def create_account(self, email, password): email_check = DBusers.get_user_id(email) if InputValidator.email_validator(email) and len(password) > 0 and len( email_check) == 0: user_id = DBusers.insert_user(email, password) DirHandler.check_user_dirs(str(user_id)) LoginHandler.prepare_login(DBusers.check_user(email, password), user_id, email) raise cherrypy.HTTPRedirect('/index') else: raise cherrypy.HTTPRedirect('/sign?message=Invalid Email')
def login_account(self, email, password): if InputValidator.email_validator(email): user_id = DBusers.get_user_id(email)[0] if len(user_id) > 0: user = DBusers.check_user(email, password) return LoginHandler.prepare_login(user, str(user_id['id']), email) else: return ResponseHandler.forbidden_response('Not authorized') else: return ResponseHandler.bad_request_response( 'Not a valid email address')
def request_password_reset(self, email): if InputValidator.email_validator(email): user_id = DBusers.get_user_id(email)[0]['id'] if user_id: return ResponseHandler.success_response( LoginHandler.send_reset_token(user_id, email)) else: return ResponseHandler.unauthorized_response( 'You are unauthorized') else: return ResponseHandler.bad_request_response( 'Not a valid email address')
def update_account_info(self, email, password, old_password, auth_token): user_id = InputValidator.check_session_value('user_id') if AuthHandler.check_for_auth( user_id) and AuthHandler.check_auth_token( auth_token) and InputValidator.email_validator(email): user_id = str(user_id) user_mail = InputValidator.check_session_value('user_mail') message = SettingsHandler.update_account_info( user_id, user_mail, email, password, old_password) return ResponseHandler.success_response(message) else: return ResponseHandler.unauthorized_response( 'You are unauthorized')
def password_reset(self, token, email): if InputValidator.email_validator(email): user_id = DBusers.get_user_id(email)[0]['id'] if user_id: if HashHandler.check_token(user_id, token, 2): return ResponseHandler.success_response('Correct token') else: return ResponseHandler.forbidden_response('Wrong token') else: return ResponseHandler.unauthorized_response( 'You are unauthorized') else: return ResponseHandler.bad_request_response( 'Not a valid email address')
def new_password(self, password, token, email): if InputValidator.email_validator(email): user_id = DBusers.get_user_id(email)[0]['id'] if user_id: if HashHandler.check_token(user_id, token, 2): if len(DBusers.check_user(email, password)) == 0: DBtokens.delete(user_id, 2) return ResponseHandler.success_response( DBusers.update_password(user_id, password)) else: return ResponseHandler.forbidden_response( 'Do not use your old password!') else: return ResponseHandler.forbidden_response('Wrong token') else: return ResponseHandler.unauthorized_response( 'You are unauthorized') else: return ResponseHandler.bad_request_response( 'Not a valid email address')