예제 #1
0
def login():
    current_user = get_jwt_identity()

    if current_user is None:
        data = request.json
        if not validate_params(data, 'login', 'password'):
            return rest('error', Errors.request_params_error)

        user = db.User.login(data['login'], data['password'])

        if user is None:
            return rest('error', Errors.auth_error)

        return rest(
            'success', {
                "access_token": create_access_token(identity=user['email']),
                'refresh_token': create_refresh_token(identity=user['email']),
                'user': user
            })
    else:
        user = db.User.get(email=current_user, PUBLIC=False)[0]
        return rest(
            'success', {
                'user': user,
                "access_token": create_access_token(identity=user['email']),
                'refresh_token': create_refresh_token(identity=user['email'])
            })
예제 #2
0
def get_user():
    data = request.json

    if not validate_params(data, 'token'):
        return rest('error', Errors.request_params_error)

    for user in db.User.users.values():
        if user['token'] == data['token']:
            return rest('success', user)

    return rest('error', Errors.auth_error)
예제 #3
0
def login():
    data = request.json

    if not validate_params(data, 'login', 'password'):
        return rest('error', Errors.request_params_error)

    token = db.User.login(data['login'], data['password'])

    if not token:
        return rest('error', Errors.auth_error)

    # set token to user
    db.User.users[data['login']]['token'] = token

    return rest('success', {'token': token})
예제 #4
0
def signup():
    data = request.json

    if not validate_params(data, 'email', 'password', 'username'):
        return rest('error', Errors.request_params_error)

    success = db.User.create_account(data['username'], data['email'],
                                     data['password'])

    if success:
        return rest(
            'success', {
                "access_token": create_access_token(identity=data['email']),
                'refresh_token': create_refresh_token(identity=data['email']),
                'user': db.User.get(email=data['email'], PUBLIC=True)[0]
            })

    return rest('error', Errors.auth_error)
예제 #5
0
def get_user():
    current_user = get_jwt_identity()
    user = db.User.get(email=current_user, PUBLIC=False)
    return rest('success', user)
예제 #6
0
def refresh():
    current_user = get_jwt_identity()
    return rest('success',
                {"access_token": create_access_token(identity=current_user)})