def delete(cls, user_id: int):
        user = UserModel.find_by_id(user_id)
        if not user:
            return NotFoundError("user not found").to_json()
        user.delete_from_db()

        return {"message": "deleted"}, 200
Beispiel #2
0
 def default(self, *args, **kwargs):
     resource = '/'.join(args)
     raise NotFoundError({
         'error_msg': 'Requested resource not found.',
         'resource': resource,
         'params': kwargs
     })
Beispiel #3
0
    def get(cls):
        try:
            users = UserModel.get_all()

            return {"users": [user.json() for user in users]}, 200

        except:
            return NotFoundError("users not found").json()
Beispiel #4
0
 def validate_user(username_or_email, password):
     user = UserRepository.find_user(username_or_email)
     if not user:
         raise NotFoundError({
             'error_msg':
             'User with provided username or email has not been found.'
         })
     return UserControl._verify_password(user.hashed_password,
                                         password), user
Beispiel #5
0
 def GET():
     if not len(args):
         search_query = QueryHelper.get_string('search', kwargs)
         in_maintenance = QueryHelper.get_int('in_maintenance', kwargs)
         if search_query:
             return UnitsControl.search_units(search_query,
                                              in_maintenance)
         with_names = QueryHelper.get_bool('names', kwargs)
         return UnitsControl.get_units(with_names, in_maintenance)
     raise NotFoundError({'error_msg': 'Resource not found'})
    def post(cls):
        try:
            data = user_schema.load(request.get_json())

            user = UserModel.find_by_username(data["username"])
            # user does not exist
            if not user:
                return NotFoundError("user not found").to_json()

            if user.password == data["password"]:
                if not user.activated:
                    return {"message": "user not activated"}, 400
                access_token = create_access_token(identity=user.id,
                                                   fresh=True)
                refresh_token = create_refresh_token(user.id)
                return {
                    "access_token": access_token,
                    "refresh_token": refresh_token
                }, 200

            return NotFoundError("password does not match").to_json()
        except ValidationError as err:
            return err.messages, 400
Beispiel #7
0
    def post(cls):
        data = cls.parser.parse_args()
        existingUser = UserModel.find_by_username(data['username'])
        if not existingUser:
            return NotFoundError("{} not found".format(
                data["username"])).json()

        if existingUser.password == data["password"]:
            access_token = create_access_token(identity=existingUser.id,
                                               fresh=True)
            refresh_token = create_refresh_token(existingUser.id)
            return {
                "access_token": access_token,
                "refresh_token": refresh_token
            }

        else:
            return InternalError("password does not match").json()
Beispiel #8
0
 def POST():
     if not len(args):
         try:
             with BodyReader() as body:
                 name = body['name']
                 own_name = body['own_name']
         except MultiKeyError as ex:
             paths = ex.get_error_paths()
             keys = {'paths': paths, 'count': len(paths)}
             raise BadRequestError({
                 'error_msg': 'Request body is not full',
                 'keys': keys
             })
         if not len(name) or not len(own_name):
             raise BadRequestError({
                 'error_msg': 'Cannot create language with empty name',
                 'name': name,
                 'own_name': own_name
             })
         return LanguageControl.create(name, own_name)
     raise NotFoundError({'error_msg': 'Resource not found'})
Beispiel #9
0
 def POST():
     if not len(args):
         return UnitsControl.create_unit()
     if len(args) == 2 and args[1] == 'name':
         id = args[0]
         try:
             with BodyReader() as body:
                 lang = body['lang']
                 short_name = body['short_name']
                 full_name = body['full_name']
                 desc = body['description']
         except MultiKeyError as ex:
             paths = ex.get_error_paths()
             keys = {'paths': paths, 'count': len(paths)}
             raise BadRequestError({
                 'error_msg': 'Request body is not full',
                 'keys': keys
             })
         try:
             return UnitsControl.add_name(id, lang, short_name,
                                          full_name, desc)
         except ValueError as ex:
             raise BadRequestError({'error_msg': 'Bad request'})
     raise NotFoundError({'error_msg': 'Resource not found'})
Beispiel #10
0
 def DELETE():
     if len(args) == 1:
         AuthControl.revoke_token(args[0])
         return
     raise NotFoundError({'error_msg': 'Resource not found'})
Beispiel #11
0
 def GET():
     if len(args) == 1:
         token_info = get_token_info(args[0])
         if token_info:
             return token_info
     raise NotFoundError({'error_msg': 'Resource not found'})
Beispiel #12
0
 def GET():
     if not len(args):
         return LanguageControl.get_all()
     raise NotFoundError({'error_msg': 'Resource not found'})
    def get(self, name):
        existingStore = StoreModel.find_by_name(name)
        if not existingStore:
            return NotFoundError("store not found").json()

        return {"store": existingStore.json()}, 200
Beispiel #14
0
 def revoke_token(token_id):
     if not Token.revoke(token_id):
         raise NotFoundError({'error_msg': 'Token not found'})
 def get(cls, user_id: int):
     user = UserModel.find_by_id(user_id)
     if not user:
         return NotFoundError("user not found").to_json()
     return user_schema.dump(user), 200