def on_get(self, req, resp, id): user = db.first("select id, name from gambler where id=%s", (id,)) if user: resp.body = utils.sendOk(user) else: resp.body = utils.sendMessage(False,"Usuario no existe")
def on_get(self, req, resp, id): user = db.first("select id, name from gambler where id=%s", (id, )) if user: resp.body = utils.sendOk(user) else: resp.body = utils.sendMessage(False, "Usuario no existe")
def on_get(self, req, resp, championship_id): obj = db.first( """ select id, name,is_disabled from championship where id = %s order by name asc """, (championship_id, )) datesDetail = db.query( """ select d.id, d.name from championship_date d where is_disabled = false and id_championship = %s order by id asc """, (championship_id, )) dateWithMatchForClient = [] for row in datesDetail: types = date.findTypeOfResults(row['id']) for key in types.keys(): row[key] = types[key]['points'] matchDetails = db.query( """ select m.id, id_team1, id_team2, t1.name as name_team1, t2.name as name_team2, goals_team1, goals_team2, date_start from championship_match m inner join team t1 on t1.id = m.id_team1 inner join team t2 on t2.id = m.id_team2 where m.is_disabled = false and m.id_championship_date = %s """, (row["id"], )) convertScoreInString(matchDetails) row["matchs"] = matchDetails dateWithMatchForClient.append(row) if obj is None: resp.body = utils.sendMessage(False, "Campeonato no encontrado") else: obj["dates"] = dateWithMatchForClient resp.body = utils.sendOk(obj)
def on_get(self, req, resp, championship_id): obj = db.first(""" select id, name,is_disabled from championship where id = %s order by name asc """, (championship_id,)) datesDetail = db.query(""" select d.id, d.name from championship_date d where is_disabled = false and id_championship = %s order by id asc """, (championship_id,)) dateWithMatchForClient = [] for row in datesDetail: types = date.findTypeOfResults(row['id']) for key in types.keys(): row[key] = types[key]['points'] matchDetails = db.query(""" select m.id, id_team1, id_team2, t1.name as name_team1, t2.name as name_team2, goals_team1, goals_team2, date_start from championship_match m inner join team t1 on t1.id = m.id_team1 inner join team t2 on t2.id = m.id_team2 where m.is_disabled = false and m.id_championship_date = %s """, ( row["id"] ,) ) convertScoreInString(matchDetails) row["matchs"] = matchDetails dateWithMatchForClient.append(row) if obj is None: resp.body = utils.sendMessage(False, "Campeonato no encontrado") else: obj["dates"] = dateWithMatchForClient resp.body = utils.sendOk(obj)
def on_post(self, req, resp): inUser = req.context["doc"] inUser['username'] = inUser['username'].lower() foundUser = db.first( """ select id,name,role,is_disabled from gambler where username = %(username)s --and password = %(password)s and is_disabled = false """, inUser) result = {} if foundUser == None: resp.body = utils.sendMessage( False, '''Todavía no te unes al Club de Eventos DS. Para saber cómo hacerlo, haz clic <a href="https://www.conexionbcp.com/wikis/home?lang=es#!/wiki/W22300a7f9e01_4d59_ac64_3ec295877429/page/Qué hago para pertenecer al Club de Eventos-DS" target='_blank'>aquí</a>''' ) else: try: #if not utils.isValidUserOnActiveDirectory(inUser['username'],inUser['password']): # resp.body = utils.sendMessage(False,'Matrícula o contraseña no coincide') # return #end-if token = utils.makeToken() db.execute("update gambler set token=%s where id=%s", (token, foundUser["id"])) result = { "token": token, "id": foundUser["id"], "name": foundUser["name"], "role": foundUser["role"] } resp.body = utils.sendOk(result) except: resp.body = utils.sendMessage( False, 'Error al intentar iniciar sesión')
def process_request(self, req, resp): freePaths = [ "/login-POST", ] pathWithMethod = (req.path + "-" + req.method) if pathWithMethod not in freePaths: if req.auth == '': raise falcon.HTTPPreconditionFailed( "Token Validation", "A token valid is required") else: result = db.first( """select id,role from gambler where token like %s and is_disabled = false""", (req.auth, ) ) if result == None: raise falcon.HTTPUnauthorized( 'Token Validation','This token has expired') else: req.context["userid"] = result["id"] req.context["role"] = result["role"]
def process_request(self, req, resp): freePaths = [ "/login-POST", ] pathWithMethod = (req.path + "-" + req.method) if pathWithMethod not in freePaths: if req.auth == '': raise falcon.HTTPPreconditionFailed( "Token Validation", "A token valid is required") else: result = db.first( """select id,role from gambler where token like %s and is_disabled = false""", (req.auth, )) if result == None: raise falcon.HTTPUnauthorized('Token Validation', 'This token has expired') else: req.context["userid"] = result["id"] req.context["role"] = result["role"]
def on_post(self, req, resp): inUser = req.context["doc"] inUser['username'] = inUser['username'].lower() foundUser = db.first(""" select id,name,role,is_disabled from gambler where username = %(username)s --and password = %(password)s and is_disabled = false """, inUser) result = {} if foundUser == None: resp.body = utils.sendMessage(False, '''Todavía no te unes al Club de Eventos DS. Para saber cómo hacerlo, haz clic <a href="https://www.conexionbcp.com/wikis/home?lang=es#!/wiki/W22300a7f9e01_4d59_ac64_3ec295877429/page/Qué hago para pertenecer al Club de Eventos-DS" target='_blank'>aquí</a>''') else: try: #if not utils.isValidUserOnActiveDirectory(inUser['username'],inUser['password']): # resp.body = utils.sendMessage(False,'Matrícula o contraseña no coincide') # return #end-if token = utils.makeToken() db.execute("update gambler set token=%s where id=%s", (token, foundUser["id"]) ) result = { "token": token, "id": foundUser["id"], "name": foundUser["name"], "role": foundUser["role"]} resp.body = utils.sendOk(result) except: resp.body = utils.sendMessage(False,'Error al intentar iniciar sesión')
def on_get(self, req, resp, team_id): obj = db.first("select * from team where id = %s", (team_id,)) if obj is None: resp.body = utils.sendMessage(False, "Equipo no encontrado") else: resp.body = utils.sendOk(obj)
def on_get(self, req, resp, id_user): listMatchs = db.query(""" select c.id as id_championship, d.id as id_championship_date, m.id as id_championship_match, c.name as name_championship, d.name as name_date, m.goals_team1 as score_team1, m.goals_team2 as score_team2, t1.name as name_team1, t2.name as name_team2, t1.url_logo as url_logo_team1, t2.url_logo as url_logo_team2 from championship c inner join championship_date d on d.id_championship = c.id inner join championship_match m on m.id_championship_date = d.id inner join team t1 on m.id_team1 = t1.id inner join team t2 on m.id_team2 = t2.id where c.is_disabled = false and d.is_disabled = false and m.is_disabled = false and isBeforeLimiteDateByUnixtime(m.date_start/1000) = false """) champs = {} for rowMatch in listMatchs: if rowMatch['id_championship'] in champs: dates = champs[rowMatch['id_championship']]['dates'] if not rowMatch['id_championship_date'] in dates: dates[rowMatch['id_championship_date']] = { 'name': rowMatch['name_date'], 'matchs': [] } else: objDate = {} objDate[rowMatch['id_championship_date']] = { 'name': rowMatch['name_date'], 'matchs': [] } champs[rowMatch['id_championship']] = { 'name': rowMatch['name_championship'], 'dates': objDate } #query each match for rowMatch in listMatchs: userScore = db.first( ''' select score_team1 as user_score_team1, score_team2 as user_score_team2, coalesce(gs.points,0) as points, dp.description from gambler_score gs left join championship_date_points dp on dp.id = gs.id_championship_date_points where id_gambler = %s and gs.id_championship_match = %s ''', (id_user, rowMatch['id_championship_match'])) objMatch = { 'name_team1': rowMatch['name_team1'], 'name_team2': rowMatch['name_team2'], 'url_logo_team1': rowMatch['url_logo_team1'], 'url_logo_team2': rowMatch['url_logo_team2'], 'score_team1': rowMatch['score_team1'], 'score_team2': rowMatch['score_team2'], 'user_score_team1': None, 'user_score_team2': None, 'points': 0, 'description': '-' } if userScore: objMatch['user_score_team1'] = userScore['user_score_team1'] objMatch['user_score_team2'] = userScore['user_score_team2'] objMatch['points'] = userScore['points'] if not userScore['description'] is None: objMatch['description'] = userScore['description'] idChamp = rowMatch['id_championship'] idDate = rowMatch['id_championship_date'] champs[idChamp]['dates'][idDate]['matchs'].append(objMatch) results = [] for keyChamp in champs.keys(): oneChamp = champs[keyChamp] dates = [] for keyDate in oneChamp['dates'].keys(): dates.append(oneChamp['dates'][keyDate]) results.append({'name': oneChamp['name'], 'dates': dates}) resp.body = utils.sendOk(results)
def on_get(self, req, resp, id_user): listMatchs = db.query(""" select c.id as id_championship, d.id as id_championship_date, m.id as id_championship_match, c.name as name_championship, d.name as name_date, m.goals_team1 as score_team1, m.goals_team2 as score_team2, t1.name as name_team1, t2.name as name_team2, t1.url_logo as url_logo_team1, t2.url_logo as url_logo_team2 from championship c inner join championship_date d on d.id_championship = c.id inner join championship_match m on m.id_championship_date = d.id inner join team t1 on m.id_team1 = t1.id inner join team t2 on m.id_team2 = t2.id where c.is_disabled = false and d.is_disabled = false and m.is_disabled = false and isBeforeLimiteDateByUnixtime(m.date_start/1000) = false """ ) champs = {} for rowMatch in listMatchs: if rowMatch['id_championship'] in champs: dates = champs[rowMatch['id_championship']]['dates'] if not rowMatch['id_championship_date'] in dates: dates[ rowMatch['id_championship_date'] ] = { 'name': rowMatch['name_date'], 'matchs': [] } else: objDate = {} objDate[ rowMatch['id_championship_date'] ] = { 'name': rowMatch['name_date'], 'matchs': [] } champs[ rowMatch['id_championship'] ] = { 'name': rowMatch['name_championship'], 'dates': objDate } #query each match for rowMatch in listMatchs: userScore = db.first(''' select score_team1 as user_score_team1, score_team2 as user_score_team2, coalesce(gs.points,0) as points, dp.description from gambler_score gs left join championship_date_points dp on dp.id = gs.id_championship_date_points where id_gambler = %s and gs.id_championship_match = %s ''', (id_user,rowMatch['id_championship_match'])) objMatch = { 'name_team1' : rowMatch['name_team1'] , 'name_team2' : rowMatch['name_team2'] , 'url_logo_team1' : rowMatch['url_logo_team1'] , 'url_logo_team2' : rowMatch['url_logo_team2'] , 'score_team1' : rowMatch['score_team1'] , 'score_team2' : rowMatch['score_team2'] , 'user_score_team1' : None , 'user_score_team2' : None , 'points' : 0 , 'description' : '-' } if userScore: objMatch['user_score_team1'] = userScore['user_score_team1'] objMatch['user_score_team2'] = userScore['user_score_team2'] objMatch['points'] = userScore['points'] if not userScore['description'] is None: objMatch['description'] = userScore['description'] idChamp = rowMatch['id_championship'] idDate = rowMatch['id_championship_date'] champs[idChamp]['dates'][idDate]['matchs'].append(objMatch) results = [] for keyChamp in champs.keys(): oneChamp = champs[keyChamp] dates = [] for keyDate in oneChamp['dates'].keys(): dates.append(oneChamp['dates'][keyDate]) results.append({ 'name': oneChamp['name'], 'dates': dates }) resp.body = utils.sendOk(results)