Beispiel #1
0
 def patch(self):
     args = self.parser['patch'].parse_args()
     if current_user.authorize(args['password']):
         if user_store.find_user(email=args['new_email']):
             return errors.UserAlreadyExist()
         else:
             current_user.email = args['new_email']
             db.session.commit()
             return {'email': current_user.email}
     else:
         return errors.InvalidPassword()
Beispiel #2
0
def login(email, password, remember=False):
    user = user_store.find_user(email=email)
    if user is None or not user.authorize(password):
        return errors.InvalidCredentials()
    if not user.confirmed_at:
        return errors.UserConfirmationRequired()
    # If user issues new login after deactivation, reactivate their account
    if not user.active:
        user.active = True
        db.session.commit()
    login_user(user, remember=remember)
    return {'token': user.get_auth_token()}
 def put(self):
     args = self.parser['put'].parse_args()
     user = user_store.find_user(email=args['email'])
     if not user:
         return errors.InvalidCredentials()
     if not user.confirmed_at:
         msg = send_confirmation_email(user.email, name=user.profile.name)
         if msg.status_code not in [250]:
             return errors.CouldNotSendEmail()
         else:
             return {'message': 'New confirmation link sent'}
     else:
         return errors.UserAlreadyConfirmed()
 def post(self):
     args = self.parser['post'].parse_args()
     email = Serializer.confirm_token(args['token'])
     if not email:
         return errors.InvalidToken()
     user = user_store.find_user(email=email)
     if user:
         user_store.activate_user(user)
         user.confirmed_at = datetime.utcnow()
         db.session.commit()
         return {'message': 'Account confirmed'}
     else:
         return errors.InvalidToken()
Beispiel #5
0
 def patch(self):
     args = self.parser['patch'].parse_args()
     user = user_store.find_user(email=args['email'])
     if user:
         if not user.confirmed_at:
             return errors.UserConfirmationRequired()
         msg = send_recovery_email(args['email'])
         if msg.status_code in [250]:
             return {'message': 'Recovery link sent'}
         else:
             return errors.CouldNotSendEmail()
     else:
         return errors.InvalidCredentials()
    def post(self):
        """ Create a new user account """

        args = self.parser['post'].parse_args()
        print(args)
        if user_store.find_user(email=args['email']):
            return errors.UserAlreadyExist()

        user = user_store.create_user(email=args['email'],
                                      password=args['password'])
        db.session.commit()

        token = generate_token(user)
        return {'token': token}
 def post(self):
     args = self.parser['post'].parse_args()
     email = Serializer.confirm_token(args['token'])
     if not email:
         return errors.InvalidToken()
     user = user_store.find_user(email=email)
     if user:
         if args['new_password'] == args['confirm']:
             user.password = args['new_password']
             db.session.commit()
             return {'message': 'Password reset'}
         else:
             return errors.PasswordConfirmationInvalid()
     else:
         return errors.InvalidToken()
Beispiel #8
0
def login(email: str, password: str) -> dict:
    """  Login with identity and credentials """
    app.logger.debug(f"Login user with email: {email}, password: {password}")
    user: User = user_store.find_user(email=email)
    app.logger.debug(f"Find user: {user}")

    if user is None or not user.authorize(password):
        app.logger.debug("Error: InvalidCredentials")

        return errors.InvalidCredentials()
    app.logger.debug("User in")

    token = generate_token(user)

    response: dict = {'token': token}
    app.logger.debug(f"Response: {response}")
    return response
Beispiel #9
0
    def post(self):
        args = self.parser['post'].parse_args()

        if user_store.find_user(email=args['email']):
            return errors.UserAlreadyExist()
        if args['password'] != args['confirm']:
            return errors.PasswordConfirmationInvalid()

        user = user_store.create_user(email=args['email'],
                                      password=args['password'])
        profile = Profile(user=user, name=args['name'])
        msg = send_confirmation_email(args['email'], args['name'])
        if msg.status_code not in [250]:
            return errors.CouldNotSendEmail()
        else:
            db.session.commit()
            logout_user()
            return {'user': user.email}