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)
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'}
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
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
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)}
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
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
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)
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'}
def get_user(cls, **kwargs) -> UserModel: return UserModel.find_by_username(kwargs.get('username'))
def get_user(cls, **kwargs) -> UserModel: return UserModel.find_by_uuid(kwargs.get('uuid'))
def get(cls): return UserModel.find_all()
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