Beispiel #1
0
 def index(self):
     user_id = InputValidator.check_session_value('user_id')
     if AuthHandler.check_for_auth(
             user_id) and AuthHandler.check_auth_token_db(user_id):
         return ResponseHandler.prepare_index(user_id)
     else:
         ResponseHandler.unauthorized_response('You are unauthorized')
         raise cherrypy.HTTPRedirect('/sign')
Beispiel #2
0
 def hash_message(self, hash_function, message, auth_token):
     user_id = InputValidator.check_session_value('user_id')
     if AuthHandler.check_for_auth(
             user_id) and AuthHandler.check_auth_token(auth_token):
         return ResponseHandler.success_response(
             HashHandler.choose_hash_function(hash_function, message))
     else:
         return ResponseHandler.unauthorized_response(
             'You are unauthorized')
Beispiel #3
0
 def caesar_cipher_crack(self, message, auth_token):
     user_id = InputValidator.check_session_value('user_id')
     if AuthHandler.check_for_auth(
             user_id) and AuthHandler.check_auth_token(auth_token):
         return ResponseHandler.success_response(
             CaesarCipher(0).crack_cipher(message))
     else:
         return ResponseHandler.unauthorized_response(
             'You are unauthorized')
Beispiel #4
0
 def get_user_settings(self, auth_token):
     user_id = InputValidator.check_session_value('user_id')
     if AuthHandler.check_for_auth(
             user_id) and AuthHandler.check_auth_token(auth_token):
         user_id = str(user_id)
         return DBusers.get_user_settings(user_id)
     else:
         return ResponseHandler.unauthorized_response(
             'You are unauthorized')
Beispiel #5
0
 def vigenere_cipher_crack(self, message, auth_token):
     user_id = InputValidator.check_session_value('user_id')
     if AuthHandler.check_for_auth(
             user_id) and AuthHandler.check_auth_token(auth_token):
         clean_message = CipherHelper.remove_special_chars(message)
         return ResponseHandler.success_response(
             VigenereCipher().crack_cipher(clean_message))
     else:
         return ResponseHandler.unauthorized_response(
             'You are unauthorized')
Beispiel #6
0
 def get_user_devices(self, auth_token):
     user_id = InputValidator.check_session_value('user_id')
     if AuthHandler.check_for_auth(
             user_id) and AuthHandler.check_auth_token(auth_token):
         user_id = str(user_id)
         devices = DBdevices.get_by_user_id(user_id)
         return devices
     else:
         return ResponseHandler.unauthorized_response(
             'You are unauthorized')
Beispiel #7
0
 def file_decrypt(self, file_id, auth_token):
     user_id = InputValidator.check_session_value('user_id')
     if AuthHandler.check_for_auth(
             user_id) and AuthHandler.check_auth_token(auth_token):
         user_id = str(user_id)
         return ResponseHandler.success_response(
             FileEncryptor.decrypt(user_id, file_id))
     else:
         return ResponseHandler.unauthorized_response(
             'You are unauthorized')
Beispiel #8
0
 def activate_user_device(self, device_id, auth_token):
     user_id = InputValidator.check_session_value('user_id')
     if AuthHandler.check_for_auth(
             user_id) and AuthHandler.check_auth_token(auth_token):
         user_id = str(user_id)
         DBdevices.deactivate_all(user_id)
         return ResponseHandler.success_response(
             SecondFactorHandler.activate_device(user_id, device_id))
     else:
         return ResponseHandler.unauthorized_response(
             'You are unauthorized')
Beispiel #9
0
 def delete_user_device(self, device_id, auth_token):
     user_id = InputValidator.check_session_value('user_id')
     if AuthHandler.check_for_auth(
             user_id) and AuthHandler.check_auth_token(auth_token):
         user_id = str(user_id)
         DBdevices.delete(device_id, user_id)
         deleted_message = f'Device was deleted. \n {SecondFactorHandler.check_for_active_device(user_id)}'
         return ResponseHandler.success_response(deleted_message)
     else:
         return ResponseHandler.unauthorized_response(
             'You are unauthorized')
Beispiel #10
0
 def file_update(self, file_id, file_description, file_name, auth_token):
     user_id = InputValidator.check_session_value('user_id')
     if AuthHandler.check_for_auth(
             user_id) and AuthHandler.check_auth_token(auth_token):
         user_id = str(user_id)
         message = FileHandler.change_file_name(user_id, file_id, file_name,
                                                file_description)
         return ResponseHandler.success_response(message)
     else:
         return ResponseHandler.unauthorized_response(
             'You are unauthorized')
Beispiel #11
0
 def update_settings_sec_fa(self, sec_fa, sec_fa_email, sec_fa_app,
                            auth_token):
     user_id = InputValidator.check_session_value('user_id')
     if AuthHandler.check_for_auth(
             user_id) and AuthHandler.check_auth_token(auth_token):
         user_id = str(user_id)
         message = SettingsHandler.check_second_factor_options(
             sec_fa, sec_fa_email, sec_fa_app, user_id)
         return ResponseHandler.success_response(message)
     else:
         return ResponseHandler.unauthorized_response(
             'You are unauthorized')
Beispiel #12
0
 def caesar_cipher(self, message, shift, option, auth_token):
     user_id = InputValidator.check_session_value('user_id')
     if not InputValidator.int_validator(int(shift)):
         return ResponseHandler.bad_request_response(
             'Your Shift value has to be an int')
     if AuthHandler.check_for_auth(
             user_id) and AuthHandler.check_auth_token(auth_token):
         return ResponseHandler.success_response(
             CaesarCipher(int(shift)).cipher(message, option))
     else:
         return ResponseHandler.unauthorized_response(
             'You are unauthorized')
Beispiel #13
0
 def file_delete(self, file_id, is_encrypted, auth_token):
     user_id = InputValidator.check_session_value('user_id')
     if AuthHandler.check_for_auth(
             user_id) and AuthHandler.check_auth_token(auth_token):
         user_id = str(user_id)
         message = FileHandler.delete_file(
             user_id, file_id, DBfiles.get_file_path(user_id, file_id),
             is_encrypted)
         return ResponseHandler.success_response(message)
     else:
         return ResponseHandler.unauthorized_response(
             'You are unauthorized')
Beispiel #14
0
 def request_qr(self, auth_token):
     user_id = InputValidator.check_session_value('user_id')
     if AuthHandler.check_for_auth(
             user_id) and AuthHandler.check_auth_token(auth_token):
         user_id = str(user_id)
         otp = OtpHandler.create_otp(user_id)
         DBotp.insert(user_id, otp)
         img_string = QRHandler.create_qr_image(user_id, otp)
         cherrypy.response.headers['Content-Type'] = "image/png"
         return base64.b64encode(img_string)
     else:
         return ResponseHandler.unauthorized_response(
             'You are unauthorized')
Beispiel #15
0
 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')
Beispiel #16
0
 def file_upload(self, file, file_description, auth_token):
     user_id = InputValidator.check_session_value('user_id')
     if not InputValidator.file_validator(file):
         ResponseHandler.bad_request_response(
             'You didnt submit a valid file')
         return cherrypy.HTTPRedirect('/')
     if AuthHandler.check_for_auth(
             user_id) and AuthHandler.check_auth_token(auth_token):
         user_id = str(user_id)
         FileHandler.write_file(user_id, file, file_description)
         raise cherrypy.HTTPRedirect('/')
     else:
         ResponseHandler.unauthorized_response('You are unauthorized')
         raise cherrypy.HTTPRedirect('/sign')
Beispiel #17
0
 def deactivate_user_device(self, device_id, auth_token):
     user_id = InputValidator.check_session_value('user_id')
     if AuthHandler.check_for_auth(
             user_id) and AuthHandler.check_auth_token(auth_token):
         user_id = str(user_id)
         deactivate_message = SecondFactorHandler.deactivate_device(
             user_id, device_id)
         deactivate_addition = SecondFactorHandler.check_for_active_device(
             user_id)
         return ResponseHandler.success_response(
             f'{deactivate_message} {deactivate_addition}')
     else:
         return ResponseHandler.unauthorized_response(
             'You are unauthorized')
Beispiel #18
0
 def file_download(self, file_id, auth_token):
     user_id = InputValidator.check_session_value('user_id')
     if AuthHandler.check_for_auth(
             user_id) and AuthHandler.check_auth_token(auth_token):
         user_id = str(user_id)
         user_path = f'../storage/users/{user_id}'
         absolute_file_path = os.path.abspath(
             f'{user_path}{DBfiles.get_file_path(user_id, file_id)}')
         file_name = DBfiles.get_file_name(file_id, user_id)
         return serve_file(absolute_file_path,
                           disposition="attachment",
                           name=file_name)
     else:
         ResponseHandler.unauthorized_response('You are unauthorized')
         raise cherrypy.HTTPRedirect('/sign')
Beispiel #19
0
 def verify_otp(self, otp, auth_token):
     user_id = InputValidator.check_session_value('user_id')
     if user_id and AuthHandler.check_auth_token(auth_token):
         user_id = str(user_id)
         return LoginHandler.prepare_otp_login(user_id, otp)
     else:
         return ResponseHandler.unauthorized_response(
             'You are unauthorized')
Beispiel #20
0
 def check_otp_verified(self):
     user_id = InputValidator.check_session_value('user_id')
     if user_id and AuthHandler.check_auth_token_db(user_id):
         check_value = DBotp.check_verification(user_id)
         if check_value:
             LoginHandler.verify_login(user_id)
         return ResponseHandler.success_response(str(check_value))
     else:
         return ResponseHandler.unauthorized_response(
             'You are unauthorized')
Beispiel #21
0
 def request_new_otp(self):
     user_id = InputValidator.check_session_value('user_id')
     if user_id and AuthHandler.check_auth_token_db(user_id):
         user_id = str(user_id)
         user_mail = InputValidator.check_session_value('user_mail')
         otp_option = InputValidator.check_session_value('otp_option')
         return ResponseHandler.success_response(
             OtpHandler.prepare_otp_send(user_id, otp_option, user_mail))
     else:
         ResponseHandler.unauthorized_response('You are unauthorized')
Beispiel #22
0
 def insert_user_device(self, device_id, device_name, user_id):
     if not user_id:
         user_id = InputValidator.check_session_value('user_id')
         if AuthHandler.check_for_auth(user_id):
             user_id = str(user_id)
         else:
             return ResponseHandler.unauthorized_response(
                 'You are unauthorized')
     device = DBdevices.get_by_device_id(device_id)
     if len(device) > 0:
         if device[0]['device_is_active']:
             return 'Device already active'
         else:
             return 'Device already registered'
     db_connection_state = DBdevices.insert(user_id, device_id, device_name)
     if db_connection_state == 'success':
         return 'Successfully inserted device'
     elif db_connection_state == 'failed':
         return 'Failed to insert device'