コード例 #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
コード例 #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"
コード例 #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})
コード例 #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()
コード例 #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()
コード例 #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()
コード例 #7
0
def my_expired_token_callback(response=None):
    if 'access_token_cookie' in request.cookies:
        return logout()
    else:
        return uc.login()
コード例 #8
0
def users_count():
    return uc.users_count()
コード例 #9
0
def account():
    if request.method == 'GET':
        return send_from_directory("templates", "admin/account_form.html")
    else:
        return uc.account(request)
コード例 #10
0
def deletebook(id):
    claims = get_jwt_claims()
    if claims:
        if claims['role'] == 'admin':
            return bc.deletebook(id)
    return uc.login()
コード例 #11
0
def library():
    claims = get_jwt_claims()
    if claims:
        if claims['role'] == 'user':
            return render_template('my_library.html')
    return uc.login()
コード例 #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()
コード例 #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()
コード例 #14
0
def bg(id):
    claims = get_jwt_claims()
    if claims:
        if claims['role'] == 'admin':
            return gc.bg_query(id)
    return uc.login()
コード例 #15
0
def users():
    claims = get_jwt_claims()
    if claims:
        if claims['role'] == 'admin':
            return uc.users()
    return uc.login()
コード例 #16
0
def users_list():
    # identity = get_jwt_identity()
    # if identity == 'admin':
    return uc.users_list()
コード例 #17
0
def deletegenre(id):
    claims = get_jwt_claims()
    if claims:
        if claims['role'] == 'admin':
            return gc.deletegenre(id)
    return uc.login()
コード例 #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()