Exemple #1
0
 def post(cls):
     parser = reqparse.RequestParser()
     parser.add_argument('username',
                         type=str,
                         required=True,
                         store_missing=False)
     parser.add_argument('password',
                         type=str,
                         required=True,
                         store_missing=False)
     parser.add_argument('new_password',
                         type=str,
                         required=True,
                         store_missing=False)
     args = parser.parse_args()
     username = get_authorized_username()
     user: UserModel = UserModel.find_by_username(username)
     if user is None:
         raise NotFoundException("User does not exist")
     if not (args['username'] == username
             and check_password_hash(user.password, args['password'])):
         raise UnauthorizedException("Invalid username or password")
     user.password = encrypt_password(args['new_password'])
     user.commit()
     return {'message': 'Your password has been changed successfully'}
Exemple #2
0
 def post(cls):
     parser = reqparse.RequestParser()
     parser.add_argument('username',
                         type=str,
                         required=True,
                         store_missing=False)
     args = parser.parse_args()
     user: UserModel = UserModel.find_by_username(args['username'])
     return {'exist': bool(user)}
Exemple #3
0
 def post(cls):
     parser = reqparse.RequestParser()
     parser.add_argument('username',
                         type=str,
                         required=True,
                         store_missing=False)
     parser.add_argument('password',
                         type=str,
                         required=True,
                         store_missing=False)
     args = parser.parse_args()
     user = UserModel.find_by_username(args['username'])
     if user is None:
         raise NotFoundException('User does not exist')
     if not check_password_hash(user.password, args['password']):
         raise BadDataException(
             'username and password combination is incorrect')
     return encode_jwt_token(user.uuid, user.username)
Exemple #4
0
 def post(cls):
     parser = reqparse.RequestParser()
     parser.add_argument('username',
                         type=str,
                         required=True,
                         store_missing=False)
     args = parser.parse_args()
     user: UserModel = UserModel.find_by_username(args['username'])
     if user is None:
         raise NotFoundException("User does not exist")
     user.state = StateType.VERIFIED
     user.commit()
     data = {
         "to": "",
         "data": {
             "title": "NubeIO User Status",
             "body": "User is verified by Admin!",
             "type": FcmDataType.USER_VERIFICATION.name
         }
     }
     DeviceModel.send_notification_by_user_uuid(user.uuid,
                                                FcmServerModel.get_key(),
                                                data)
     return {'message': 'User has been verified successfully'}
Exemple #5
0
 def get_user(cls, **kwargs) -> UserModel:
     return UserModel.find_by_username(kwargs.get('username'))