Beispiel #1
0
 def post(self):
     body = RequestParser().get_body_users_args()
     user = UserModel.find_user_by_login(body['login'])
     if user:
         return {'message': 'User %s already exists' % body['login']}, 422
     new_user = UserModel(**body)
     try:
         new_user.save_user()
     except:
         return {'message': 'cannot save user, internal server error'}, 500
     return new_user.json(), 201
Beispiel #2
0
 def post(self):
     body = RequestParser().get_body_users_args()
     user = UserModel.find_user_by_login(body['login'])
     if user and safe_str_cmp(user.password, body['password']):
         access_token = create_access_token(identity=user.id)
         refresh_token = create_refresh_token(identity=user.id)
         token = {
             'access token': access_token,
             'refresh_token': refresh_token
         }
         return token, 200
     return {'message': 'the username or password is incorrect'}, 401