Пример #1
0
 def wrapper(*args, **kwargs):
     if request.authorization:
         ucontr = UserController()
         try:
             user = ucontr.get(nickname=request.authorization.username)
         except NotFound:
             raise Forbidden("Couldn't authenticate your user")
         if not ucontr.check_password(user, request.authorization.password):
             raise Forbidden("Couldn't authenticate your user")
         if not user.is_active:
             raise Forbidden("User is deactivated")
         login_user_bundle(user)
     if current_user.is_authenticated:
         return func(*args, **kwargs)
     raise Unauthorized()
Пример #2
0
 def validate(self):
     validated = super().validate()
     ucontr = UserController()
     try:
         user = ucontr.get(nickname=self.nickmane.data)
     except NotFound:
         self.nickmane.errors.append("Wrong nickname")
         validated = False
     else:
         if not user.is_active:
             self.nickmane.errors.append("Account not active")
             validated = False
         if not ucontr.check_password(user, self.password.data):
             self.password.errors.append("Wrong password")
             validated = False
         self.user = user
     return validated