Exemple #1
0
 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')
Exemple #2
0
 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')
Exemple #3
0
 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')
Exemple #4
0
 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')
Exemple #5
0
 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')