def get_response_data(cls, conn, response_id): scientist_id = response_id[:response_id.find(u':')] project_id = response_id[response_id.find(u':')+1:response_id.rfind(u':')] vacancy_id = response_id[response_id.rfind(u':')+1:] response_data = dict( scientist_id=scientist_id, vacancy_id=vacancy_id ) # get message and status columns = [u'message', u'status'] where_list = [ dict( column=u'scientist_id', value=scientist_id ), dict( column=u'project_id', value=project_id ), dict( column=u'vacancy_id', value=vacancy_id ) ] sql_query = get_select_query(globals.TABLE_RESPONSES, columns=columns, where=where_list) cursor = yield momoko.Op(conn.execute, sql_query) data = cursor.fetchone() response_data.update(dict(zip(columns, data))) # get vacancy name v_col = [u'vacancy_name'] sql_query = get_select_query(globals.TABLE_VACANCIES, columns=v_col, where=dict(column=u'id', value=vacancy_id)) cursor = yield momoko.Op(conn.execute, sql_query) data = cursor.fetchone() response_data.update(dict(zip(v_col, data))) # get scientist name scientist = yield Scientist.get_by_id(scientist_id) scientist_name = u' '.join(map(lambda x: x.decode('utf8'), [scientist.last_name, scientist.first_name, scientist.middle_name])) response_data.update(dict( scientist_name=scientist_name, )) raise gen.Return(response_data)
def check_login(cls, conn, email, pwd): sql_query = get_select_query(globals.TABLE_ROLES, columns=['id', 'pwd'], where=dict(column='email', value=email)) cursor = yield momoko.Op(conn.execute, sql_query) data = cursor.fetchone() if not data: raise Exception(u'Incorrect pwd') _id, enc_pwd = data exists = check_password(pwd, enc_pwd) if exists: raise gen.Return(_id) raise Exception(u'Incorrect pwd')
def validate_credentials(cls, conn, data): """ Check if user can save email/pwd :param conn: :param data: :raise gen.Return: """ email = data.get(u'email') pwd = data.get(u'pwd') both_fields = email and pwd if not both_fields: raise RequiredFields([u'Email', u'Password']) sql_query = get_select_query(globals.TABLE_ROLES, functions="count(*)", where=dict(column=u'email', value=email)) cursor = yield momoko.Op(conn.execute, sql_query) count = cursor.fetchone() if int(count[0]) > 0: raise UserExistException(email)