-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5ba1b13
commit 4b11836
Showing
78 changed files
with
167,332 additions
and
42 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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
.git | ||
__pycache__ | ||
*.pyc | ||
*.pyo | ||
*.pyd |
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,10 @@ | ||
# True for development, False for production | ||
DEBUG=True | ||
|
||
# Flask ENV | ||
FLASK_APP=run.py | ||
FLASK_ENV=development | ||
|
||
# Used for CDN (in production) | ||
# No Slash at the end | ||
ASSETS_ROOT=/static/assets |
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,33 @@ | ||
# byte-compiled / optimized / DLL files | ||
__pycache__/ | ||
*.py[cod] | ||
|
||
# tests and coverage | ||
*.pytest_cache | ||
.coverage | ||
|
||
# database & logs | ||
*.db | ||
*.sqlite3 | ||
*.log | ||
|
||
# venv | ||
env | ||
venv | ||
|
||
# other | ||
.DS_Store | ||
|
||
# sphinx docs | ||
_build | ||
_static | ||
_templates | ||
|
||
# javascript | ||
package-lock.json | ||
.vscode/symbols.json | ||
|
||
apps/static/assets/node_modules | ||
apps/static/assets/yarn.lock | ||
apps/static/assets/.temp | ||
|
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,16 @@ | ||
FROM python:3.9 | ||
|
||
# set environment variables | ||
ENV PYTHONDONTWRITEBYTECODE 1 | ||
ENV PYTHONUNBUFFERED 1 | ||
|
||
COPY requirements.txt . | ||
|
||
# install python dependencies | ||
RUN pip install --upgrade pip | ||
RUN pip install --no-cache-dir -r requirements.txt | ||
|
||
COPY . . | ||
|
||
# gunicorn | ||
CMD ["gunicorn", "--config", "gunicorn-cfg.py", "run:app"] |
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 @@ | ||
web: gunicorn run:app --log-file=- |
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,44 @@ | ||
# -*- encoding: utf-8 -*- | ||
""" | ||
Copyright (c) 2019 - present AppSeed.us | ||
""" | ||
|
||
from flask import Flask | ||
from flask_login import LoginManager | ||
from flask_sqlalchemy import SQLAlchemy | ||
from importlib import import_module | ||
|
||
|
||
db = SQLAlchemy() | ||
login_manager = LoginManager() | ||
|
||
|
||
def register_extensions(app): | ||
db.init_app(app) | ||
login_manager.init_app(app) | ||
|
||
|
||
def register_blueprints(app): | ||
for module_name in ('authentication', 'home'): | ||
module = import_module('apps.{}.routes'.format(module_name)) | ||
app.register_blueprint(module.blueprint) | ||
|
||
|
||
def configure_database(app): | ||
|
||
@app.before_first_request | ||
def initialize_database(): | ||
db.create_all() | ||
|
||
@app.teardown_request | ||
def shutdown_session(exception=None): | ||
db.session.remove() | ||
|
||
|
||
def create_app(config): | ||
app = Flask(__name__) | ||
app.config.from_object(config) | ||
register_extensions(app) | ||
register_blueprints(app) | ||
configure_database(app) | ||
return app |
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,12 @@ | ||
# -*- encoding: utf-8 -*- | ||
""" | ||
Copyright (c) 2019 - present AppSeed.us | ||
""" | ||
|
||
from flask import Blueprint | ||
|
||
blueprint = Blueprint( | ||
'authentication_blueprint', | ||
__name__, | ||
url_prefix='' | ||
) |
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,31 @@ | ||
# -*- encoding: utf-8 -*- | ||
""" | ||
Copyright (c) 2019 - present AppSeed.us | ||
""" | ||
|
||
from flask_wtf import FlaskForm | ||
from wtforms import StringField, PasswordField | ||
from wtforms.validators import Email, DataRequired | ||
|
||
# login and registration | ||
|
||
|
||
class LoginForm(FlaskForm): | ||
username = StringField('Username', | ||
id='username_login', | ||
validators=[DataRequired()]) | ||
password = PasswordField('Password', | ||
id='pwd_login', | ||
validators=[DataRequired()]) | ||
|
||
|
||
class CreateAccountForm(FlaskForm): | ||
username = StringField('Username', | ||
id='username_create', | ||
validators=[DataRequired()]) | ||
email = StringField('Email', | ||
id='email_create', | ||
validators=[DataRequired(), Email()]) | ||
password = PasswordField('Password', | ||
id='pwd_create', | ||
validators=[DataRequired()]) |
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,48 @@ | ||
# -*- encoding: utf-8 -*- | ||
""" | ||
Copyright (c) 2019 - present AppSeed.us | ||
""" | ||
|
||
from flask_login import UserMixin | ||
|
||
from apps import db, login_manager | ||
|
||
from apps.authentication.util import hash_pass | ||
|
||
class Users(db.Model, UserMixin): | ||
|
||
__tablename__ = 'Users' | ||
|
||
id = db.Column(db.Integer, primary_key=True) | ||
username = db.Column(db.String(64), unique=True) | ||
email = db.Column(db.String(64), unique=True) | ||
password = db.Column(db.LargeBinary) | ||
|
||
def __init__(self, **kwargs): | ||
for property, value in kwargs.items(): | ||
# depending on whether value is an iterable or not, we must | ||
# unpack it's value (when **kwargs is request.form, some values | ||
# will be a 1-element list) | ||
if hasattr(value, '__iter__') and not isinstance(value, str): | ||
# the ,= unpack of a singleton fails PEP8 (travis flake8 test) | ||
value = value[0] | ||
|
||
if property == 'password': | ||
value = hash_pass(value) # we need bytes here (not plain str) | ||
|
||
setattr(self, property, value) | ||
|
||
def __repr__(self): | ||
return str(self.username) | ||
|
||
|
||
@login_manager.user_loader | ||
def user_loader(id): | ||
return Users.query.filter_by(id=id).first() | ||
|
||
|
||
@login_manager.request_loader | ||
def request_loader(request): | ||
username = request.form.get('username') | ||
user = Users.query.filter_by(username=username).first() | ||
return user if user else None |
Oops, something went wrong.