Example #1
0
    def get(self):
        claims = get_jwt_claims()
        if not claims['is_admin']:
            return {'message': 'Admin privilege required.'}, 401

        users = [users.json() for users in UserModel.find_all()]
        return {'usersList': users}, 200
Example #2
0
    def post(self):
        data = _user_parser.parse_args()
        notAdmin = 0
        now = datetime.now()
        date_time = now.strftime("%m/%d/%Y, %H:%M:%S")

        if UserModel.find_by_email(data['email']):
            return {"message": "A user with that email already exists"}, 400

        user = UserModel(data['email'], data['password'], data['lastname'],
                         data['firstname'], data['othernames'], data['phone'],
                         data['country'], data['orgnaisionationame'],
                         date_time, notAdmin)
        user.save_to_db()

        return {"message": "User created successfully."}, 201
Example #3
0
    def get(cls, email):
        user = UserModel.find_by_email(email)
        if not user:
            return {'message': 'User Not Found'}, 404

        claims = get_jwt_claims()
        if not claims['is_admin']:
            return {'message': 'Admin privilege required.'}, 401

        return user.json(), 200
Example #4
0
    def delete(cls, email):
        user = UserModel.find_by_email(email)
        if not user:
            return {'message': 'User Not Found'}, 404

        claims = get_jwt_claims()
        if not claims['is_admin']:
            return {'message': 'Admin privilege required.'}, 401

        user.delete_from_db()
        return {'message': 'User deleted successfully.'}, 200
Example #5
0
    def post(self, email):
        user = UserModel.find_by_email(email)

        claims = get_jwt_claims()
        if not claims['is_admin']:
            return {'message': 'Admin privilege required.'}, 401

        if not user:
            return {'message': 'User Not Found'}, 404

        user.isAdmin = 0

        user.save_to_db()

        return {'message': 'User right Admin removed'}, 200
Example #6
0
    def post(self):
        data = _user_login_parser.parse_args()

        user = UserModel.find_by_email(data['email'])

        if user and safe_str_cmp(user.password, data['password']):
            access_token = create_access_token(
                identity=user.userid,
                fresh=True,
                expires_delta=timedelta(seconds=86400))
            refresh_token = create_refresh_token(user.userid)
            return {
                'access_token': access_token,
                'refresh_token': refresh_token
            }, 200

        return {"message": "Invalid Credentials!"}, 401
Example #7
0
    def put(self, email):
        data = _user_parser.parse_args()
        user = UserModel.find_by_email(email)

        claims = get_jwt_claims()
        if not claims['is_admin']:
            return {'message': 'Admin privilege required.'}, 401

        if not user:
            return {'message': 'User Not Found'}, 404

        user.password = data['password']
        user.lastname = data['lastname']
        user.firstname = data['firstname']
        user.othernames = data['othernames']
        user.phone = data['phone']
        user.country = data['country']
        user.orgnaisionationame = data['orgnaisionationame']
        user.save_to_db()

        return user.json()
Example #8
0
def add_claims_to_jwt(identity):
    user = UserModel.check_if_admin(identity)
    if user:
        return {'is_admin': True}
    return {'is_admin': False}