-
Notifications
You must be signed in to change notification settings - Fork 24
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
App Generator
committed
Feb 4, 2021
1 parent
0cce84c
commit fb16156
Showing
104 changed files
with
15,380 additions
and
0 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,8 @@ | ||
DEBUG=True | ||
SECRET_KEY=S3cr3t_K#Key | ||
DB_ENGINE=postgresql | ||
DB_NAME=appseed-flask | ||
DB_HOST=localhost | ||
DB_PORT=5432 | ||
DB_USERNAME=appseed | ||
DB_PASS=pass |
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,28 @@ | ||
# 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 |
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,11 @@ | ||
FROM python:3.6 | ||
|
||
ENV FLASK_APP run.py | ||
|
||
COPY run.py gunicorn-cfg.py requirements.txt config.py .env ./ | ||
COPY app app | ||
|
||
RUN pip install -r requirements.txt | ||
|
||
EXPOSE 5005 | ||
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,32 @@ | ||
# MIT License | ||
|
||
Copyright (c) 2019 - present [AppSeed](http://appseed.us/) | ||
|
||
<br /> | ||
|
||
## Licensing Information | ||
|
||
<br /> | ||
|
||
| Item | - | | ||
| ---------------------------------- | --- | | ||
| License Type | MIT | | ||
| Use for print | **YES** | | ||
| Create single personal website/app | **YES** | | ||
| Create single website/app for client | **YES** | | ||
| Create multiple website/apps for clients | **YES** | | ||
| Create multiple SaaS applications | **YES** | | ||
| End-product paying users | **YES** | | ||
| Product sale | **YES** | | ||
| Remove footer credits | **YES** | | ||
| --- | --- | | ||
| Remove copyright mentions from source code | NO | | ||
| Production deployment assistance | NO | | ||
| Create HTML/CSS template for sale | NO | | ||
| Create Theme/Template for CMS for sale | NO | | ||
| Separate sale of our UI Elements | NO | | ||
|
||
<br /> | ||
|
||
--- | ||
For more information regarding licensing, please contact the AppSeed Service < *[email protected]* > |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# -*- encoding: utf-8 -*- | ||
""" | ||
Copyright (c) 2019 - present AppSeed.us | ||
""" | ||
|
||
from flask import Flask, url_for | ||
from flask_login import LoginManager | ||
from flask_sqlalchemy import SQLAlchemy | ||
from importlib import import_module | ||
from logging import basicConfig, DEBUG, getLogger, StreamHandler | ||
from os import path | ||
|
||
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 ('base', 'home'): | ||
module = import_module('app.{}.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__, static_folder='base/static') | ||
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,14 @@ | ||
# -*- encoding: utf-8 -*- | ||
""" | ||
Copyright (c) 2019 - present AppSeed.us | ||
""" | ||
|
||
from flask import Blueprint | ||
|
||
blueprint = Blueprint( | ||
'base_blueprint', | ||
__name__, | ||
url_prefix='', | ||
template_folder='templates', | ||
static_folder='static' | ||
) |
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,19 @@ | ||
# -*- encoding: utf-8 -*- | ||
""" | ||
Copyright (c) 2019 - present AppSeed.us | ||
""" | ||
|
||
from flask_wtf import FlaskForm | ||
from wtforms import TextField, PasswordField | ||
from wtforms.validators import InputRequired, Email, DataRequired | ||
|
||
## login and registration | ||
|
||
class LoginForm(FlaskForm): | ||
username = TextField ('Username', id='username_login' , validators=[DataRequired()]) | ||
password = PasswordField('Password', id='pwd_login' , validators=[DataRequired()]) | ||
|
||
class CreateAccountForm(FlaskForm): | ||
username = TextField('Username' , id='username_create' , validators=[DataRequired()]) | ||
email = TextField('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 sqlalchemy import Binary, Column, Integer, String | ||
|
||
from app import db, login_manager | ||
|
||
from app.base.util import hash_pass | ||
|
||
class User(db.Model, UserMixin): | ||
|
||
__tablename__ = 'User' | ||
|
||
id = Column(Integer, primary_key=True) | ||
username = Column(String, unique=True) | ||
email = Column(String, unique=True) | ||
password = Column(Binary) | ||
|
||
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 User.query.filter_by(id=id).first() | ||
|
||
@login_manager.request_loader | ||
def request_loader(request): | ||
username = request.form.get('username') | ||
user = User.query.filter_by(username=username).first() | ||
return user if user else None |
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,112 @@ | ||
# -*- encoding: utf-8 -*- | ||
""" | ||
Copyright (c) 2019 - present AppSeed.us | ||
""" | ||
|
||
from flask import jsonify, render_template, redirect, request, url_for | ||
from flask_login import ( | ||
current_user, | ||
login_required, | ||
login_user, | ||
logout_user | ||
) | ||
|
||
from app import db, login_manager | ||
from app.base import blueprint | ||
from app.base.forms import LoginForm, CreateAccountForm | ||
from app.base.models import User | ||
|
||
from app.base.util import verify_pass | ||
|
||
@blueprint.route('/') | ||
def route_default(): | ||
return redirect(url_for('base_blueprint.login')) | ||
|
||
## Login & Registration | ||
|
||
@blueprint.route('/login', methods=['GET', 'POST']) | ||
def login(): | ||
login_form = LoginForm(request.form) | ||
if 'login' in request.form: | ||
|
||
# read form data | ||
username = request.form['username'] | ||
password = request.form['password'] | ||
|
||
# Locate user | ||
user = User.query.filter_by(username=username).first() | ||
|
||
# Check the password | ||
if user and verify_pass( password, user.password): | ||
|
||
login_user(user) | ||
return redirect(url_for('base_blueprint.route_default')) | ||
|
||
# Something (user or pass) is not ok | ||
return render_template( 'accounts/login.html', msg='Wrong user or password', form=login_form) | ||
|
||
if not current_user.is_authenticated: | ||
return render_template( 'accounts/login.html', | ||
form=login_form) | ||
return redirect(url_for('home_blueprint.index')) | ||
|
||
@blueprint.route('/register', methods=['GET', 'POST']) | ||
def register(): | ||
login_form = LoginForm(request.form) | ||
create_account_form = CreateAccountForm(request.form) | ||
if 'register' in request.form: | ||
|
||
username = request.form['username'] | ||
email = request.form['email' ] | ||
|
||
# Check usename exists | ||
user = User.query.filter_by(username=username).first() | ||
if user: | ||
return render_template( 'accounts/register.html', | ||
msg='Username already registered', | ||
success=False, | ||
form=create_account_form) | ||
|
||
# Check email exists | ||
user = User.query.filter_by(email=email).first() | ||
if user: | ||
return render_template( 'accounts/register.html', | ||
msg='Email already registered', | ||
success=False, | ||
form=create_account_form) | ||
|
||
# else we can create the user | ||
user = User(**request.form) | ||
db.session.add(user) | ||
db.session.commit() | ||
|
||
return render_template( 'accounts/register.html', | ||
msg='User created please <a href="/login">login</a>', | ||
success=True, | ||
form=create_account_form) | ||
|
||
else: | ||
return render_template( 'accounts/register.html', form=create_account_form) | ||
|
||
@blueprint.route('/logout') | ||
def logout(): | ||
logout_user() | ||
return redirect(url_for('base_blueprint.login')) | ||
|
||
## Errors | ||
|
||
@login_manager.unauthorized_handler | ||
def unauthorized_handler(): | ||
return render_template('page-403.html'), 403 | ||
|
||
@blueprint.errorhandler(403) | ||
def access_forbidden(error): | ||
return render_template('page-403.html'), 403 | ||
|
||
@blueprint.errorhandler(404) | ||
def not_found_error(error): | ||
return render_template('page-404.html'), 404 | ||
|
||
@blueprint.errorhandler(500) | ||
def internal_error(error): | ||
return render_template('page-500.html'), 500 |
Large diffs are not rendered by default.
Oops, something went wrong.
Oops, something went wrong.