def add_session(form): if not assert_keys_in_form_exist(form, ['email', 'password']): return msg.error_msg("Please check the inputs.") sessions = SessionModel() users = UserModel() (email, password) = (form['email'], form['password']) users_founded = users.get_user(email=email, password=encrypt(password), enable=True) if users_founded == None: return msg.error_msg("Failed to validate user information.") if len(users_founded) == 0: return msg.error_msg("Invalid email address or password.") uid = users_founded[0]['user_id'] new_session_id = sessions.create_session_id() start_time = datetime.utcnow() res = sessions.start_session(new_session_id, uid, start_time) if res == None: return msg.error_msg("Failed to start a new session.") return msg.success_msg({ "sessionID": new_session_id, "uid": uid, "startTime": str(start_time), "userName": users_founded[0]['name'] })
def add_session(form): if not assert_keys_in_form_exist(form, ['email', 'password']): return msg.error_msg("Invalid request.") (email, password) = (form['email'], form['password']) users_founded = User.get_user(email=email, password=encrypt(password), enable=True) if users_founded is None: return msg.error_msg("Failed to validate user information.") if len(users_founded) == 0: return msg.error_msg("Invalid email address or password.") uid = users_founded[0]['user_id'] new_session_id = Session.create_session_id() start_time = datetime.utcnow() res = Session.start_session(new_session_id, uid, start_time) if res is None: return msg.error_msg("Failed to start a new session.") return msg.success_msg({"sessionID": new_session_id, "uid": uid, "startTime": str(start_time)})