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
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"
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})
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()
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()
def ad_dashboard(): claims = get_jwt_claims() if claims: if claims['role'] == 'admin': return send_from_directory("templates", "admin/dashboard.html") return uc.login()
def my_expired_token_callback(response=None): if 'access_token_cookie' in request.cookies: return logout() else: return uc.login()
def users_count(): return uc.users_count()
def account(): if request.method == 'GET': return send_from_directory("templates", "admin/account_form.html") else: return uc.account(request)
def deletebook(id): claims = get_jwt_claims() if claims: if claims['role'] == 'admin': return bc.deletebook(id) return uc.login()
def library(): claims = get_jwt_claims() if claims: if claims['role'] == 'user': return render_template('my_library.html') return uc.login()
def admin_books(): claims = get_jwt_claims() if claims: if claims['role'] == 'admin': return send_from_directory("templates", "admin/booklist.html") return uc.login()
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()
def bg(id): claims = get_jwt_claims() if claims: if claims['role'] == 'admin': return gc.bg_query(id) return uc.login()
def users(): claims = get_jwt_claims() if claims: if claims['role'] == 'admin': return uc.users() return uc.login()
def users_list(): # identity = get_jwt_identity() # if identity == 'admin': return uc.users_list()
def deletegenre(id): claims = get_jwt_claims() if claims: if claims['role'] == 'admin': return gc.deletegenre(id) return uc.login()
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()