-
Notifications
You must be signed in to change notification settings - Fork 199
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
updated dependencies migrates all auth to flask jwt extended
- Loading branch information
Showing
11 changed files
with
145 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,12 @@ | ||
FROM gitpod/workspace-full | ||
|
||
USER root | ||
RUN sudo apt-get update | ||
RUN sudo apt-get install -y libgbm-dev gconf-service libxext6 libxfixes3 libxi6 libxrandr2 libxrender1 libcairo2 libcups2 libdbus-1-3 libexpat1 libfontconfig1 libgcc1 libgconf-2-4 libgdk-pixbuf2.0-0 libglib2.0-0 libgtk-3-0 libnspr4 libpango-1.0-0 libpangocairo-1.0-0 libstdc++6 libx11-6 libx11-xcb1 libxcb1 libxcomposite1 libxcursor1 libxdamage1 libxss1 libxtst6 libappindicator1 libnss3 libasound2 libatk1.0-0 libc6 ca-certificates fonts-liberation lsb-release xdg-utils wget | ||
|
||
USER gitpod | ||
|
||
# Copy the .python-version file into the Docker image to use it during the build | ||
COPY .python-version /home/gitpod/.python-version | ||
|
||
# Install the specific Python version from .python-version and upgrade pip | ||
RUN pyenv install $(cat /home/gitpod/.python-version) && \ | ||
pyenv global $(cat /home/gitpod/.python-version) && \ | ||
eval "$(pyenv init -)" && \ | ||
pip install --upgrade pip |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,42 @@ | ||
from flask_login import login_user, login_manager, logout_user, LoginManager | ||
from flask_jwt_extended import create_access_token, jwt_required, JWTManager | ||
from flask_jwt_extended import create_access_token, jwt_required, JWTManager, get_jwt_identity, verify_jwt_in_request | ||
|
||
from App.models import User | ||
|
||
def jwt_authenticate(username, password): | ||
def login(username, password): | ||
user = User.query.filter_by(username=username).first() | ||
if user and user.check_password(password): | ||
return create_access_token(identity=username) | ||
return None | ||
|
||
def login(username, password): | ||
user = User.query.filter_by(username=username).first() | ||
if user and user.check_password(password): | ||
return user | ||
return None | ||
|
||
def setup_flask_login(app): | ||
login_manager = LoginManager() | ||
login_manager.init_app(app) | ||
|
||
@login_manager.user_loader | ||
def load_user(user_id): | ||
return User.query.get(user_id) | ||
|
||
return login_manager | ||
|
||
def setup_jwt(app): | ||
jwt = JWTManager(app) | ||
|
||
@jwt.user_identity_loader | ||
def user_identity_lookup(identity): | ||
user = User.query.filter_by(username=identity).one_or_none() | ||
if user: | ||
return user.id | ||
return None | ||
|
||
@jwt.user_lookup_loader | ||
def user_lookup_callback(_jwt_header, jwt_data): | ||
identity = jwt_data["sub"] | ||
return User.query.get(identity) | ||
jwt = JWTManager(app) | ||
|
||
# configure's flask jwt to resolve get_current_identity() to the corresponding user's ID | ||
@jwt.user_identity_loader | ||
def user_identity_lookup(identity): | ||
user = User.query.filter_by(username=identity).one_or_none() | ||
if user: | ||
return user.id | ||
return None | ||
|
||
return jwt | ||
@jwt.user_lookup_loader | ||
def user_lookup_callback(_jwt_header, jwt_data): | ||
identity = jwt_data["sub"] | ||
return User.query.get(identity) | ||
return jwt | ||
|
||
# Context processor to make 'is_authenticated' available to all templates | ||
def add_auth_context(app): | ||
@app.context_processor | ||
def inject_user(): | ||
try: | ||
verify_jwt_in_request() | ||
user_id = get_jwt_identity() | ||
current_user = User.query.get(user_id) | ||
is_authenticated = True | ||
except Exception as e: | ||
print(e) | ||
is_authenticated = False | ||
current_user = None | ||
return dict(is_authenticated=is_authenticated, current_user=current_user) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{% extends "layout.html" %} | ||
{% block title %}{{title}}{% endblock %} | ||
{% block page %}{{title}}{% endblock %} | ||
|
||
{{ super() }} | ||
|
||
{% block content %} | ||
<div class="row"> | ||
<div class="container"> | ||
{{message}} | ||
</div> | ||
</div> | ||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters