def register_new_user(self, request):
        register_form = request.json if request.is_json else request.form
        register_dict = dict(register_form)
        form_register_fields = ["firstName", 'lastName', 'email', 'password', 'sectorId']
        form_valid_res = form_is_full(register_dict, form_register_fields)

        if form_valid_res.isSuccess:
            firstName = register_dict["firstName"]
            lastName = register_dict['lastName']
            email = register_dict['email']
            password = register_dict['password']
            sectorId = register_dict['sectorId']

            user = User(firstName=firstName, lastName=lastName, email=email, password=password, sectorId=sectorId)

            if user_is_valid(user).isSuccess:
                if password_is_valid(user.password).isSuccess:
                    if sector_id_is_valid(user.sectorId).isSuccess:
                        password_encrypt = PasswordEncryption.hash_salt(password=password, salt=None)
                        user.password = password_encrypt
                        if DAL.save_new_user_to_db(user) and DAL.save_user_password_history_to_db(user):
                            return AuthorizationResult(isSuccess=True, Message="User created successfully. ")
                    else:
                        return sector_id_is_valid(user.sectorId)
                else:
                    return password_is_valid(user.password)
            else:
                return AuthorizationResult(isSuccess=False, Message="User created failed. ")
        else:
            return form_valid_res
 def login(self, request):
     login_form = request.json if request.is_json else request.form
     login_dict = dict(login_form)
     login_fields = ['email', 'password']
     login_res = form_is_full(login_dict, login_fields)
     if login_res.isSuccess:
         return start_login_process(login_dict['email'],
                                    login_dict['password'])
     else:
         return None, login_res
 def change_password(self, request, user_id):
     change_password_form = request.json if request.is_json else request.form
     change_password_form_fields = ['password']
     change_password_dict = dict(change_password_form)
     change_password_form_res = form_is_full(change_password_dict,
                                             change_password_form_fields)
     if change_password_form_res.isSuccess:
         return start_change_password(user_id, change_password_dict)
     else:
         return change_password_form_res
 def create_packages(self, request):
     package_form = request.json if request.is_json else request.form
     package_dict = dict(package_form)
     package_fields = ['name']
     package_res = form_is_full(package_dict, package_fields)
     if package_res.isSuccess:
         package = Packages(name=package_dict['name'])
         if DAL.save_new_package_to_db(package):
             return True
     return package_res.isSuccess
 def verify_password_and_token(self, request):
     verify_password_recovery_form = request.json if request.is_json else request.form
     verify_password_recovery_form_fields = ["email", 'token']
     verify_password_recovery_dict = dict(verify_password_recovery_form)
     verify_form_res = form_is_full(verify_password_recovery_dict,
                                    verify_password_recovery_form_fields)
     if verify_form_res.isSuccess:
         return start_verify_password_and_token(
             verify_password_recovery_dict)
     else:
         return None, verify_form_res
 def password_recovery(self, request):
     forget_password_form = request.json if request.is_json else request.form
     forget_password_dict = dict(forget_password_form)
     forget_password_form_fields = ["email"]
     forget_password_form_res = form_is_full(forget_password_dict,
                                             forget_password_form_fields)
     if forget_password_form_res.isSuccess:
         return start_password_recovery_process(
             forget_password_dict.get("email"))
     else:
         return forget_password_form_res
 def create_sector(self, request):
     sector_form = request.json if request.is_json else request.form
     sector_dict = dict(sector_form)
     sector_fields = ['name', 'description']
     sector_res = form_is_full(sector_dict, sector_fields)
     if sector_res.isSuccess:
         sector = Sectors(name=sector_dict['name'],
                          description=sector_dict['description'])
         DAL.save_new_sector_to_db(sector)
         return True
     else:
         sector_res.isSuccess
Ejemplo n.º 8
0
 def create_packages_sector(self, request):
     packages_sector_form = request.json if request.is_json else request.form
     packages_sector_dict = dict(packages_sector_form)
     packages_sector_fields = ['packageId', 'sectorId', 'price', 'name']
     packages_sector_res = form_is_full(packages_sector_dict,
                                        packages_sector_fields)
     if packages_sector_res.isSuccess:
         packagesSector = PackagesSectors(
             packageId=packages_sector_dict['packageId'],
             sectorId=packages_sector_dict['sectorId'],
             price=packages_sector_dict['price'],
             name=packages_sector_dict['name'])
         if DAL.save_new_packages_sectors_to_db(packagesSector):
             return True
     return False