Exemplo n.º 1
0
 def post(cls):
     args = cls.parser.parse_args()
     uuid_ = str(shortuuid.uuid())
     user = UserModel(uuid=uuid_, **args)
     user.password = encrypt_password(user.password)
     user.save_to_db()
     return encode_jwt_token(user.uuid, user.username)
Exemplo n.º 2
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'}
Exemplo n.º 3
0
 def delete(cls):
     uuid = get_authorized_user_uuid()
     user = UserModel.find_by_uuid(uuid)
     if user is None:
         raise NotFoundException("User does not exist")
     user.delete_from_db()
     return '', 204
Exemplo n.º 4
0
 def patch(cls):
     uuid = get_authorized_user_uuid()
     user = UserModel.find_by_uuid(uuid)
     if not user:
         raise NotFoundException("User does not exist")
     args = parse_user_update()
     user.update(**args)
     return user
Exemplo n.º 5
0
 def post(cls):
     parser = reqparse.RequestParser()
     parser.add_argument('email',
                         type=str,
                         required=True,
                         store_missing=False)
     args = parser.parse_args()
     user: UserModel = UserModel.find_by_email(args['email'])
     return {'exist': bool(user)}
Exemplo n.º 6
0
 def get(cls):
     uuid = get_authorized_user_uuid()
     user = UserModel.find_by_uuid(uuid)
     if not user:
         raise NotFoundException("User does not exist")
     output: List[SiteModel] = []
     for site in user.sites:
         output.append(SiteModel.find_by_uuid(site.site_uuid))
     return output
Exemplo n.º 7
0
 def get(cls):
     device_info: Union[DeviceInfoModel, None] = get_device_info()
     if not device_info:
         logger.error('Please add device_info on Rubix Service')
         return
     uuid = get_authorized_user_uuid()
     user = UserModel.find_by_uuid(uuid)
     output: dict = {}
     for site in user.sites:
         output[site.site_uuid] = {
             'layout_topic':
             f'{device_info.global_uuid}/{site.site_uuid}/layout',
             'alert_topic':
             f'{device_info.global_uuid}/{site.site_uuid}/alerts'
         }
     return output
Exemplo n.º 8
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)
Exemplo n.º 9
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'}
Exemplo n.º 10
0
 def get_user(cls, **kwargs) -> UserModel:
     return UserModel.find_by_username(kwargs.get('username'))
Exemplo n.º 11
0
 def get_user(cls, **kwargs) -> UserModel:
     return UserModel.find_by_uuid(kwargs.get('uuid'))
Exemplo n.º 12
0
 def get(cls):
     return UserModel.find_all()
Exemplo n.º 13
0
 def get(cls):
     uuid = get_authorized_user_uuid()
     user = UserModel.find_by_uuid(uuid)
     if not user:
         raise NotFoundException("User does not exist")
     return user