-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: defined secret_key generator, create more templates
A secret_key generator function was created to help in the security, modification were made on the simple flask template, the robust flask template was created in full and tested, will the moderate flask template was init
- Loading branch information
Showing
102 changed files
with
1,627 additions
and
11 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
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,21 @@ | ||
# secret_key_generator.py | ||
|
||
""" | ||
This module generates secret keys to used in the frameworks templates | ||
""" | ||
|
||
|
||
import secrets | ||
import string | ||
|
||
|
||
class GenerateSecretKey: | ||
""" This class is use to generate secret key to be used for security | ||
purposes """ | ||
|
||
def generate_secret_key(length=32): | ||
""" The function generates a 32 character secret key """ | ||
|
||
alphabet = string.ascii_letters + string.digits | ||
secret_key = ''.join(secrets.choice(alphabet) for _ in range(length)) | ||
return secret_key |
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,160 @@ | ||
# Byte-compiled / optimized / DLL files | ||
__pycache__/ | ||
*.py[cod] | ||
*$py.class | ||
|
||
# C extensions | ||
*.so | ||
|
||
# Distribution / packaging | ||
.Python | ||
build/ | ||
develop-eggs/ | ||
dist/ | ||
downloads/ | ||
eggs/ | ||
.eggs/ | ||
lib/ | ||
lib64/ | ||
parts/ | ||
sdist/ | ||
var/ | ||
wheels/ | ||
share/python-wheels/ | ||
*.egg-info/ | ||
.installed.cfg | ||
*.egg | ||
MANIFEST | ||
|
||
# PyInstaller | ||
# Usually these files are written by a python script from a template | ||
# before PyInstaller builds the exe, so as to inject date/other infos into it. | ||
*.manifest | ||
*.spec | ||
|
||
# Installer logs | ||
pip-log.txt | ||
pip-delete-this-directory.txt | ||
|
||
# Unit test / coverage reports | ||
htmlcov/ | ||
.tox/ | ||
.nox/ | ||
.coverage | ||
.coverage.* | ||
.cache | ||
nosetests.xml | ||
coverage.xml | ||
*.cover | ||
*.py,cover | ||
.hypothesis/ | ||
.pytest_cache/ | ||
cover/ | ||
|
||
# Translations | ||
*.mo | ||
*.pot | ||
|
||
# Django stuff: | ||
*.log | ||
local_settings.py | ||
db.sqlite3 | ||
db.sqlite3-journal | ||
|
||
# Flask stuff: | ||
instance/ | ||
.webassets-cache | ||
|
||
# Scrapy stuff: | ||
.scrapy | ||
|
||
# Sphinx documentation | ||
docs/_build/ | ||
|
||
# PyBuilder | ||
.pybuilder/ | ||
target/ | ||
|
||
# Jupyter Notebook | ||
.ipynb_checkpoints | ||
|
||
# IPython | ||
profile_default/ | ||
ipython_config.py | ||
|
||
# pyenv | ||
# For a library or package, you might want to ignore these files since the code is | ||
# intended to run in multiple environments; otherwise, check them in: | ||
# .python-version | ||
|
||
# pipenv | ||
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. | ||
# However, in case of collaboration, if having platform-specific dependencies or dependencies | ||
# having no cross-platform support, pipenv may install dependencies that don't work, or not | ||
# install all needed dependencies. | ||
#Pipfile.lock | ||
|
||
# poetry | ||
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. | ||
# This is especially recommended for binary packages to ensure reproducibility, and is more | ||
# commonly ignored for libraries. | ||
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control | ||
#poetry.lock | ||
|
||
# pdm | ||
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control. | ||
#pdm.lock | ||
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it | ||
# in version control. | ||
# https://pdm.fming.dev/#use-with-ide | ||
.pdm.toml | ||
|
||
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm | ||
__pypackages__/ | ||
|
||
# Celery stuff | ||
celerybeat-schedule | ||
celerybeat.pid | ||
|
||
# SageMath parsed files | ||
*.sage.py | ||
|
||
# Environments | ||
.env | ||
.venv | ||
env/ | ||
venv/ | ||
ENV/ | ||
env.bak/ | ||
venv.bak/ | ||
|
||
# Spyder project settings | ||
.spyderproject | ||
.spyproject | ||
|
||
# Rope project settings | ||
.ropeproject | ||
|
||
# mkdocs documentation | ||
/site | ||
|
||
# mypy | ||
.mypy_cache/ | ||
.dmypy.json | ||
dmypy.json | ||
|
||
# Pyre type checker | ||
.pyre/ | ||
|
||
# pytype static type analyzer | ||
.pytype/ | ||
|
||
# Cython debug symbols | ||
cython_debug/ | ||
|
||
# PyCharm | ||
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can | ||
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore | ||
# and can be added to the global gitignore or merged into this file. For a more nuclear | ||
# option (not recommended) you can uncomment the following to ignore the entire idea folder. | ||
#.idea/ |
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,7 @@ | ||
# myte_moderate_flask_template | ||
|
||
## Features | ||
|
||
## Contribution | ||
|
||
## Contact |
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 @@ | ||
# database | ||
DATABASE_HOST = '' | ||
DATABASE_PORT = 5432 | ||
DATABASE_USERNAME = '' | ||
DATABASE_PASSWORD = '' | ||
DATABASE_NAME = '' | ||
|
||
# application | ||
APPHOST = '0.0.0.0' | ||
APPPOST = 3000 | ||
|
||
# environment | ||
ENVIRONMENT = 'dev' | ||
|
||
# security | ||
SECRETKEY = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' |
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 @@ | ||
# app.py | ||
|
||
""" | ||
This module defines... | ||
""" | ||
|
||
# imports | ||
|
||
from flask import Flask, render_template | ||
from flask_migrate import Migrate | ||
|
||
import config | ||
from models import db | ||
|
||
# configurations | ||
|
||
app = Flask(__name__) | ||
|
||
app.debug = config.DEBUG | ||
app.config['SQLALCHEMY_DATABASE_URI'] = config.SQLALCHEMY_DATABASE_URI | ||
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = config.SQLALCHEMY_TRACK_MODIFICATIONS # noqa | ||
app.config['SECRET_KEY'] = config.SECRET_KEY | ||
|
||
db.init_app(app) | ||
db.app = app | ||
migrate = Migrate(app, db) | ||
|
||
# application | ||
|
||
|
||
@app.route('/', methods=['GET']) | ||
def index(): | ||
""" This function defines... """ | ||
|
||
# write your logic here | ||
|
||
return render_template('pages/index.html'), 200 | ||
|
||
# entrypoint | ||
|
||
|
||
if __name__ == "__main__": | ||
app.debug = config.DEBUG | ||
app.run() |
Empty 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,44 @@ | ||
# config.py | ||
|
||
""" | ||
This module defines... | ||
""" | ||
|
||
# imports | ||
|
||
import os | ||
|
||
from dotenv import load_dotenv | ||
|
||
# configurations | ||
|
||
load_dotenv() | ||
|
||
DATABASE_USERNAME = os.getenv('DATABASE_USERNAME') | ||
DATABASE_PASSWORD = os.getenv('DATABASE_PASSWORD') | ||
DATABASE_HOST = os.getenv('DATABASE_HOST') | ||
DATABASE_PORT = os.getenv('DATABASE_PORT') | ||
DATABASE_NAME = os.getenv('DATABASE_NAME') | ||
|
||
DEBUG = True | ||
|
||
# databases | ||
# delete any database you don't want to use | ||
|
||
# postgreSQL - default (pip install psycopg2 (windows users) or psycopg2-binary (linux and mac users)) # noqa | ||
|
||
SQLALCHEMY_DATABASE_URI = f'postgresql://{DATABASE_USERNAME}:{DATABASE_PASSWORD}@{DATABASE_HOST}:{DATABASE_PORT}/{DATABASE_NAME}' # noqa | ||
|
||
# # mySQL (pip install mysql-connector-python) | ||
# uncomment line 35 to use MySQL DB and comment line 30 | ||
|
||
# SQLALCHEMY_DATABASE_URI = f'mysql://{DATABASE_USERNAME}:{DATABASE_PASSWORD}@{DATABASE_HOST}:{DATABASE_PORT}/{DATABASE_NAME}' # noqa | ||
|
||
# # SQLite (goto https://www.sqlite.org/download.html, download and install, if you've not) # noqa | ||
# uncomment line 40 to use SQLite DB and comment line 30 | ||
|
||
# SQLALCHEMY_DATABASE_URI = f'sqlite:///{DATABASE_NAME}.db' | ||
|
||
SQLALCHEMY_TRACK_MODIFICATIONS = False | ||
|
||
SECRET_KEY = os.getenv('SECRETKEY') |
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,36 @@ | ||
""" | ||
This module defines all forms needed by the users | ||
""" | ||
# imports | ||
|
||
from flask_wtf import FlaskForm | ||
from flask_wtf.file import FileAllowed, FileField | ||
from wtforms import IntegerField, SelectField, StringField, SubmitField | ||
from wtforms.validators import DataRequired, Email | ||
|
||
|
||
# forms | ||
|
||
|
||
class CreateUserForm(FlaskForm): | ||
|
||
""" This class is use to create new users """ | ||
|
||
name = StringField('Name', validators=[DataRequired()]) | ||
email_address = StringField('Email Address', validators=[Email()]) | ||
phone_number = IntegerField('Phone Number') | ||
street_name = StringField('Street Name', validators=[DataRequired()]) | ||
city = StringField('City', validators=[DataRequired()]) | ||
state = StringField('State', validators=[DataRequired()]) | ||
country = SelectField('Country', validators=[DataRequired()], choices=[]) | ||
zipcode = StringField('Zipcode', validators=[DataRequired()]) | ||
user_photo = FileField('Logo', validators=[FileAllowed( | ||
['jpg', 'png'], 'JPG & PNG Formats Only!')]) | ||
create_user = SubmitField('Add user') | ||
|
||
|
||
class DeleteUserForm(FlaskForm): | ||
|
||
""" This class is use to create new users """ | ||
|
||
delete_user = SubmitField('Yes') |
Oops, something went wrong.