Esempio n. 1
0
    def patch(username):
        """Patch the user profile associated with the provided username.

        User only for patching the password.
        """
        try:

            request_json = request.get_json()
            valid_format, errors = schema_utils.validate(
                request_json, 'anonymous_user')
            if not valid_format:
                return {
                    'message': schema_utils.serialize(errors)
                }, http_status.HTTP_400_BAD_REQUEST
            user = UserService.find_by_username(username)

            if user is None:
                response, status = {'message': 'User {} does not exist.'.format(username)}, \
                                   http_status.HTTP_404_NOT_FOUND
            elif user.as_dict().get('type', None) != Role.ANONYMOUS_USER.name:
                response, status = {
                    'Normal users cant be patched',
                    http_status.HTTP_501_NOT_IMPLEMENTED
                }
            else:
                UserService.reset_password_for_anon_user(
                    request_json, username, token_info=g.jwt_oidc_token_info)
                response, status = '', http_status.HTTP_204_NO_CONTENT
        except BusinessException as exception:
            response, status = {
                'code': exception.code,
                'message': exception.message
            }, exception.status_code
        return response, status
Esempio n. 2
0
 def delete(username):
     """Delete/Reset the OTP of user profile associated with the provided username."""
     try:
         user = UserService.find_by_username(username)
         if user is None:
             response, status = {'message': 'User {} does not exist.'.format(username)}, \
                                http_status.HTTP_404_NOT_FOUND
         elif user.as_dict().get('login_source',
                                 None) != LoginSource.BCEID.value:
             response, status = {
                 'Only BCEID users has OTP',
                 http_status.HTTP_400_BAD_REQUEST
             }
         else:
             origin_url = request.environ.get('HTTP_ORIGIN', 'localhost')
             UserService.delete_otp_for_user(
                 username,
                 token_info=g.jwt_oidc_token_info,
                 origin_url=origin_url)
             response, status = '', http_status.HTTP_204_NO_CONTENT
     except BusinessException as exception:
         response, status = {
             'code': exception.code,
             'message': exception.message
         }, exception.status_code
     return response, status
Esempio n. 3
0
 def get(username):
     """Return the user profile associated with the provided username."""
     user = UserService.find_by_username(username)
     if user is None:
         response, status = {'message': 'User {} does not exist.'.format(username)}, http_status.HTTP_404_NOT_FOUND
     else:
         response, status = user.as_dict(), http_status.HTTP_200_OK
     return response, status
Esempio n. 4
0
 def delete(username):
     """Delete the user profile associated with the provided username."""
     try:
         user = UserService.find_by_username(username)
         if user is None:
             response, status = {'message': 'User {} does not exist.'.format(username)}, \
                 http_status.HTTP_404_NOT_FOUND
         elif user.as_dict().get('type', None) != AccessType.ANONYMOUS.value:
             response, status = {'Normal users cant be deleted', http_status.HTTP_501_NOT_IMPLEMENTED}
         else:
             UserService.delete_anonymous_user(username, token_info=g.jwt_oidc_token_info)
             response, status = '', http_status.HTTP_204_NO_CONTENT
     except BusinessException as exception:
         response, status = {'code': exception.code, 'message': exception.message}, exception.status_code
     return response, status