Beispiel #1
0
def login_user():
    if request.method == "GET":
        if 'access_token_cookie' in request.cookies:
            token = decode_token(request.cookies['access_token_cookie'])
            if 'identity' in token:
                return redirect('/')
        return uc.login()
    else:
        form = LoginForm()
        # try:
        # fetch the user data
        json_user = {
            'username': form.username.data,
            'password': form.password.data
        }

        resp = requests.post('http://localhost:9500/users/login', json=json_user)

        response_info = resp.json()
        response = make_response(redirect('/'))
        if 'token' in response_info:
            set_access_cookies(response, response_info['token'])
        else:
            flash('Invalid username/password supplied')
            return uc.login()
        return response
Beispiel #2
0
def register():
    if 'access_token_cookie' in request.cookies:
        token = decode_token(request.cookies['access_token_cookie'])
        if 'identity' in token:
            return redirect('/')
    if request.method == "GET":
        return uc.register_form()
    elif request.method == "POST":
        return uc.redirect_login(requests)
    else:
        return "error"
Beispiel #3
0
def validate():
    if request.is_json:
        username_in_json = request.get_json()
        if 'username' in username_in_json:
            return uc.validate(username_in_json['username'])
    else:
        return jsonify({'message': False})
Beispiel #4
0
def edit_gen():
    claims = get_jwt_claims()
    if claims:
        if claims['role'] == 'admin':
            gc.edit_genre(request)
            return send_from_directory("templates", "admin/view_genre_form.html")
    return uc.login()
Beispiel #5
0
def addgenre():
    claims = get_jwt_claims()
    if claims:
        if claims['role'] == 'admin':
            if request.method == 'GET':
                return send_from_directory("templates", "admin/add_genre_form.html")
    return uc.login()
Beispiel #6
0
def ad_dashboard():
    claims = get_jwt_claims()
    if claims:
        if claims['role'] == 'admin':
            return send_from_directory("templates", "admin/dashboard.html")
    return uc.login()
Beispiel #7
0
def my_expired_token_callback(response=None):
    if 'access_token_cookie' in request.cookies:
        return logout()
    else:
        return uc.login()
Beispiel #8
0
def users_count():
    return uc.users_count()
Beispiel #9
0
def account():
    if request.method == 'GET':
        return send_from_directory("templates", "admin/account_form.html")
    else:
        return uc.account(request)
Beispiel #10
0
def deletebook(id):
    claims = get_jwt_claims()
    if claims:
        if claims['role'] == 'admin':
            return bc.deletebook(id)
    return uc.login()
Beispiel #11
0
def library():
    claims = get_jwt_claims()
    if claims:
        if claims['role'] == 'user':
            return render_template('my_library.html')
    return uc.login()
Beispiel #12
0
def admin_books():
    claims = get_jwt_claims()
    if claims:
        if claims['role'] == 'admin':
            return send_from_directory("templates", "admin/booklist.html")
    return uc.login()
Beispiel #13
0
def show_gen_form():
    claims = get_jwt_claims()
    if claims:
        if claims['role'] == 'admin':
            return send_from_directory("templates", "admin/edit_genre_form.html")
    return uc.login()
Beispiel #14
0
def bg(id):
    claims = get_jwt_claims()
    if claims:
        if claims['role'] == 'admin':
            return gc.bg_query(id)
    return uc.login()
Beispiel #15
0
def users():
    claims = get_jwt_claims()
    if claims:
        if claims['role'] == 'admin':
            return uc.users()
    return uc.login()
Beispiel #16
0
def users_list():
    # identity = get_jwt_identity()
    # if identity == 'admin':
    return uc.users_list()
Beispiel #17
0
def deletegenre(id):
    claims = get_jwt_claims()
    if claims:
        if claims['role'] == 'admin':
            return gc.deletegenre(id)
    return uc.login()
Beispiel #18
0
def books_view():
    claims = get_jwt_claims()
    if claims:
        if claims['role'] == 'admin':
            return send_from_directory("templates", "admin/add_book_form.html")
    return uc.login()