Exemplo n.º 1
0
    def update(cls, mysql, user_id):
        service = UserService(mysql)

        try:
            user = service.update(user_id)
        except ResourceNotFoundException as error:
            return jsonify({
                'message': str(error),
                'code': error.get_code()
            }), 404
        except MissingFieldException as error:
            return jsonify({
                'message': str(error),
                'code': error.get_code()
            }), 400
        except ResourceAlreadyExistsException as error:
            return jsonify({
                'message': str(error),
                'code': error.get_code()
            }), 400

        repo = UserRepository(mysql)
        user = repo.update(user)

        return cls.get_by_filter(mysql, 'id', user.get_id())
Exemplo n.º 2
0
    def test_get_user_data(self):
        mock_dao = Mock()
        email = '*****@*****.**'
        name = 'some name'

        mock_dao.get_all.return_value = User(email, name)

        service = UserService(mock_dao)

        user = service.get_user(email)

        self.assertEqual(user.get_email(), email)
        self.assertEqual(user.get_name(), name)
Exemplo n.º 3
0
    def create(cls, mysql):
        service = UserService(mysql)

        try:
            user = service.validate_payload_for_creation_and_hydrate()
        except MissingFieldException as error:
            return jsonify({
                'message': str(error),
                'code': error.get_code()
            }), 400
        except ResourceAlreadyExistsException as error:
            return jsonify({
                'message': str(error),
                'code': error.get_code()
            }), 400

        user = service.create(user)

        return cls.get_by_filter(mysql, 'id', user.get_id())
Exemplo n.º 4
0
    def authenticate(cls, mysql):
        user_service = UserService(mysql)

        try:
            user = user_service.authenticate()
        except MissingFieldException as error:
            return jsonify({
                'message': str(error),
                'code': error.get_code()
            }), 400
        except InvalidInput as error:
            return jsonify({
                'message': str(error),
                'code': error.get_code()
            }), 400
        except MissingHeaderException as error:
            return jsonify({
                'message': str(error),
                'code': error.get_code()
            }), 400
        except ResourceNotFoundException as error:
            return jsonify({
                'message': str(error),
                'code': error.get_code()
            }), 403
        except InvalidCredentialsException as error:
            return jsonify({
                'message': str(error),
                'code': error.get_code()
            }), 403
        except InactiveUserException as error:
            return jsonify({
                'message': str(error),
                'code': error.get_code()
            }), 403

        return jsonify({
            'id': user.get_id(),
            'email': user.get_email(),
            'username': user.get_user_name(),
            'active': user.get_is_active(),
            'token': user.get_token()
        }), 200
Exemplo n.º 5
0
    def get_by_filter(cls, mysql, filter, filter_value):
        user_service = UserService(mysql)

        try:
            user = user_service.get_by_filter(filter, filter_value)
        except UnsupportedFilterException as error:
            return jsonify({
                'message': str(error),
                'code': error.get_code()
            }), 400
        except ResourceNotFoundException as error:
            return jsonify({
                'message': str(error),
                'code': error.get_code()
            }), 404

        return jsonify({
            'id': user.get_id(),
            'email': user.get_email(),
            'username': user.get_user_name(),
            'active': user.get_is_active()
        }), 200
SESSION_ID = "my-session-id"
ACCESS_TOKEN = "access-token"
ACCESS_TOKEN_COOKIE = "access_token_cookie"
TOKEN_EXPIRES_IN_SECONDS = 300

app.config['JWT_SECRET_KEY'] = os.environ.get(SECRET_KEY)
app.secret_key = os.environ.get(SECRET_KEY)

app.config['JWT_ACCESS_TOKEN_EXPIRES'] = TOKEN_EXPIRES_IN_SECONDS
app.config['JWT_TOKEN_LOCATION'] = ('headers', 'cookies')
app.config['JWT_COOKIE_SECURE'] = True
app.config['JWT_COOKIE_CSRF_PROTECT'] = False

jwt = JWTManager(app)

user_service = UserService()
note_service = NoteService()
validator = Validator()


@jwt.unauthorized_loader
def my_unauthorized_loader_function(callback):
    return render_template("errors/403.html"), 403


@app.route('/')
def index():
    return render_template('index.html')


# ==================================== LOGIN ======================================
Exemplo n.º 7
0
    def renew_token(cls, mysql, current_user):
        user_service = UserService(mysql)
        user_service.renew_token(current_user)

        return cls.get_by_filter(mysql, 'id', current_user.get_id())
Exemplo n.º 8
0
from flask import Blueprint, request
from flask_cors import cross_origin, CORS

from src.API.utils import objects_to_json
from src.service.user_service import UserService

user_api = Blueprint('user_api', __name__)
CORS(user_api, suppport_credentials=True)

service = UserService()


@user_api.route('/userData', methods=['GET'])
@cross_origin(support_credentials=True)
def user_data():
    email = request.args.get('userEmail')

    return {'user': objects_to_json(service.get_user(email))}
Exemplo n.º 9
0
 def __init__(self):
     self.user_service = UserService()
     self.permission_service = Permission()
Exemplo n.º 10
0
 def __init__(self, user_service=UserService()):
     self.dao = ConsortiumDAO()
     self.user_service = user_service
     self.email_service = EmailService()