Beispiel #1
0
    def update(self, admin=None, employee_number= None, username=None, password=None, email=None):
        try:
            if email:
                email_is_valid(email)
            if username:
                username_is_valid(username)
            if password:
                password_is_valid(password)
            if employee_number:
                employee_number_is_valid(employee_number)
        except UserErrors.InvalidEmail as e:
            return e
        except UserErrors.InvalidUsername as e:
            return e
        except UserErrors.InvalidPassword as e:
            return e
        except UserErrors.InvalidEmployeeNumber as e:
            return e

        self.username = self.username if username is None else username
        self.password = self.password if password is None else password
        self.email = self.email if email is None else email
        self.employee_number = self.employee_number if employee_number is None else employee_number
        self.admin = self.admin if admin is None else admin

        db.session.commit()
Beispiel #2
0
    def register(self):
        if not email_is_valid(self.email):
            raise UserErrors.InvalidEmail("Wrong email format.")

        if User.query.filter_by(email=self.email).first() is not None:
            raise UserErrors.EmailExists("Email already exists")

        if User.query.filter_by(employee_number=self.employee_number).first() is not None:
            raise UserErrors.EmployeeNumberExists("User number:{} is already used.".format(self.employee_number))

        self.save_to_database()