init
This commit is contained in:
commit
c97e3e8d4e
21 changed files with 231 additions and 0 deletions
5
.gitignore
vendored
Normal file
5
.gitignore
vendored
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
/__pycache__
|
||||
/errorlog.txt
|
||||
/instance
|
||||
/logs.log
|
||||
/migrations
|
||||
1
README.md
Normal file
1
README.md
Normal file
|
|
@ -0,0 +1 @@
|
|||
# Pilzno
|
||||
61
app/__init__.py
Normal file
61
app/__init__.py
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
from flask import Flask, redirect, url_for
|
||||
from celery import Celery
|
||||
from app.config import Config
|
||||
from flask_sqlalchemy import SQLAlchemy
|
||||
from flask_migrate import Migrate
|
||||
from flask_login import LoginManager
|
||||
from flask_mail import Mail
|
||||
from werkzeug.middleware.proxy_fix import ProxyFix
|
||||
from logging import FileHandler, INFO
|
||||
|
||||
db = SQLAlchemy()
|
||||
migrate = Migrate()
|
||||
login_manager = LoginManager()
|
||||
mail = Mail()
|
||||
celery = Celery('app', broker=Config.CELERY_BROKER_URL, backend=Config.CELERY_RESULT_BACKEND)
|
||||
|
||||
|
||||
def create_app():
|
||||
app = Flask(__name__)
|
||||
app.config.from_object(Config)
|
||||
|
||||
celery.conf.update(app.config)
|
||||
|
||||
db.init_app(app)
|
||||
migrate.init_app(app,db)
|
||||
login_manager.init_app(app)
|
||||
mail.init_app(app)
|
||||
file_handler = FileHandler('errorlog.txt')
|
||||
file_handler.setLevel(INFO)
|
||||
app.logger.addHandler(file_handler)
|
||||
app.wsgi_app = ProxyFix(
|
||||
app.wsgi_app, x_for=1, x_proto=1
|
||||
)
|
||||
|
||||
from app.users.models import User
|
||||
@login_manager.user_loader
|
||||
def load_user(user_id):
|
||||
user = User.query.get(user_id)
|
||||
if user:
|
||||
return user
|
||||
else:
|
||||
return None
|
||||
login_manager.login_view = 'users.login'
|
||||
|
||||
from app.users import users
|
||||
from app.main import main
|
||||
# from app.reports import reports
|
||||
# from app.plan_management import plan_management
|
||||
# from app.agent_reports import agent_reports
|
||||
# from app.status_reports import status_reports
|
||||
app.register_blueprint(users)
|
||||
app.register_blueprint(main)
|
||||
# app.register_blueprint(reports)
|
||||
# app.register_blueprint(plan_management)
|
||||
# app.register_blueprint(agent_reports)
|
||||
# app.register_blueprint(status_reports)
|
||||
|
||||
@app.route('/')
|
||||
def reroute_base_url():
|
||||
return redirect(url_for('main.homepage'))
|
||||
return app, celery
|
||||
BIN
app/__pycache__/__init__.cpython-311.pyc
Normal file
BIN
app/__pycache__/__init__.cpython-311.pyc
Normal file
Binary file not shown.
BIN
app/__pycache__/config.cpython-311.pyc
Normal file
BIN
app/__pycache__/config.cpython-311.pyc
Normal file
Binary file not shown.
BIN
app/__pycache__/models.cpython-311.pyc
Normal file
BIN
app/__pycache__/models.cpython-311.pyc
Normal file
Binary file not shown.
20
app/config.py
Normal file
20
app/config.py
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
import os
|
||||
import json
|
||||
|
||||
# with open('/etc/config.json') as config_file:
|
||||
# config = json.load(config_file)
|
||||
config = {
|
||||
'SQLALCHEMY_DATABASE_URI_SQLITE': 'sqlite:///site.db'
|
||||
}
|
||||
|
||||
class Config():
|
||||
SQLALCHEMY_DATABASE_URI = config.get('SQLALCHEMY_DATABASE_URI_SQLITE')
|
||||
SECRET_KEY = config.get('SECRET_KEY')
|
||||
MAIL_PORT = 587
|
||||
MAIL_USE_TLS = True
|
||||
MAX_CONTENT_LENGTH = 500 * 1000 * 1000
|
||||
CELERY_BROKER_URL = 'redis://localhost:6379/0'
|
||||
CELERY_RESULT_BACKEND = 'redis://localhost:6379/0'
|
||||
CELERY_IMPORTS = ('app.celery_tasks', )
|
||||
SMTP_USER = config.get('SMTP_USER')
|
||||
SMTP_PASSWORD = config.get('SMTP_PASSWORD')
|
||||
9
app/main/__init__.py
Normal file
9
app/main/__init__.py
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
from flask import Blueprint
|
||||
|
||||
main = Blueprint('main',
|
||||
__name__,
|
||||
template_folder='templates',
|
||||
static_folder='static',
|
||||
url_prefix='/main')
|
||||
|
||||
from app.main import routes
|
||||
BIN
app/main/__pycache__/__init__.cpython-311.pyc
Normal file
BIN
app/main/__pycache__/__init__.cpython-311.pyc
Normal file
Binary file not shown.
BIN
app/main/__pycache__/routes.cpython-311.pyc
Normal file
BIN
app/main/__pycache__/routes.cpython-311.pyc
Normal file
Binary file not shown.
17
app/main/routes.py
Normal file
17
app/main/routes.py
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
from app import db
|
||||
from app.main import main
|
||||
from app.users.models import User
|
||||
# from forms import LoginForm, RequestResetForm, ResetPasswordForm, EditUserForm, AddUserForm
|
||||
from flask import render_template, redirect, url_for, flash, request
|
||||
from flask_login import login_required, login_user, current_user, logout_user
|
||||
from werkzeug.security import check_password_hash, generate_password_hash
|
||||
from datetime import datetime
|
||||
import os
|
||||
# import logging
|
||||
# logging.basicConfig(filename='logs.log', encoding='utf-8', level=logging.INFO)
|
||||
|
||||
|
||||
@main.route('/homepage')
|
||||
def homepage():
|
||||
|
||||
return render_template('homepage.html')
|
||||
38
app/main/templates/base.html
Normal file
38
app/main/templates/base.html
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>{% block title %}{% endblock title %}</title>
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-T3c6CoIi6uLrA9TneNEoa7RxnatzjcDSCmG1MXxSR1GAsXEV/Dwwykc2MPK8M2HN" crossorigin="anonymous">
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js" integrity="sha384-C6RzsynM9kWDrMNeT87bh95OGNyZPhcTNXj1NW7RuBCsyN/o0jlpcV8Qyq46cDfL" crossorigin="anonymous"></script>
|
||||
<link rel="stylesheet" href="{{ url_for('main.static', filename='main.css') }}">
|
||||
{% block stylesheet %}{% endblock stylesheet %}
|
||||
</head>
|
||||
<body>
|
||||
<nav class="navbar navbar-expand-lg navbar-light bg-light">
|
||||
<a href="{{url_for('main.homepage')}}" style="text-decoration: none; margin-right: 10px;"></a>
|
||||
<a href="#" style="text-decoration: none;"><span class="navbar-brand">User Page</span></a>
|
||||
<div class="collapse navbar-collapse" id="navbarNavAltMarkup">
|
||||
<div class="navbar-nav">
|
||||
<a class="nav-item nav-link active" href="#">Logout</a>
|
||||
</div>
|
||||
<!-- <div class="navbar-nav ms-auto" id="navbar-user-details">
|
||||
<p>Account Name: {{current_user.first_name}} {{current_user.last_name}}</p>
|
||||
<p>User Type: {{current_user.user_type}}</p>
|
||||
</div> -->
|
||||
</div>
|
||||
</nav>
|
||||
{% with messages = get_flashed_messages(with_categories=true) %}
|
||||
{% if messages %}
|
||||
{% for category, message in messages %}
|
||||
<div class="alert alert-{{ category }}">
|
||||
{{ message }}
|
||||
</div>
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
{% endwith %}
|
||||
{% block content %}{% endblock content %}
|
||||
</body>
|
||||
</html>
|
||||
2
app/main/templates/homepage.html
Normal file
2
app/main/templates/homepage.html
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
{% extends 'base.html' %}
|
||||
{% block title %}Customer Search{% endblock title %}
|
||||
9
app/users/__init__.py
Normal file
9
app/users/__init__.py
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
from flask import Blueprint
|
||||
|
||||
users = Blueprint('users',
|
||||
__name__,
|
||||
template_folder='templates',
|
||||
static_folder='static',
|
||||
url_prefix='/users')
|
||||
|
||||
from app.users import routes
|
||||
BIN
app/users/__pycache__/__init__.cpython-311.pyc
Normal file
BIN
app/users/__pycache__/__init__.cpython-311.pyc
Normal file
Binary file not shown.
BIN
app/users/__pycache__/models.cpython-311.pyc
Normal file
BIN
app/users/__pycache__/models.cpython-311.pyc
Normal file
Binary file not shown.
BIN
app/users/__pycache__/routes.cpython-311.pyc
Normal file
BIN
app/users/__pycache__/routes.cpython-311.pyc
Normal file
Binary file not shown.
0
app/users/forms.py
Normal file
0
app/users/forms.py
Normal file
43
app/users/models.py
Normal file
43
app/users/models.py
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
from app import db
|
||||
from flask import current_app
|
||||
from flask_login import UserMixin, current_user
|
||||
from sqlalchemy import TEXT, Column, Boolean, ForeignKey, TEXT, INTEGER, VARCHAR
|
||||
import jwt
|
||||
from datetime import datetime, timezone, timedelta
|
||||
|
||||
|
||||
class User(db.Model, UserMixin):
|
||||
__tablename__ = 'user'
|
||||
id = Column('id', INTEGER(), primary_key=True)
|
||||
first_name = Column('first_name', TEXT(), nullable=False)
|
||||
last_name = Column('last_name', TEXT(), nullable=False)
|
||||
email = Column('email', TEXT(), nullable=False, unique=True)
|
||||
password = Column('password', TEXT(), nullable=False)
|
||||
user_type = Column('user_type', TEXT(), nullable=False)
|
||||
|
||||
def get_reset_token(self, expiration=600):
|
||||
reset_token = jwt.encode(
|
||||
{
|
||||
"confirm": self.id,
|
||||
"exp": datetime.now(tz=timezone.utc)
|
||||
+ timedelta(seconds=expiration)
|
||||
},
|
||||
current_app.config['SECRET_KEY'],
|
||||
algorithm="HS256"
|
||||
)
|
||||
return reset_token
|
||||
|
||||
@staticmethod
|
||||
def verify_reset_token(token):
|
||||
try:
|
||||
data = jwt.decode(
|
||||
token,
|
||||
current_app.config['SECRET_KEY'],
|
||||
leeway=timedelta(seconds=10),
|
||||
algorithms=["HS256"]
|
||||
)
|
||||
except:
|
||||
return None
|
||||
if not User.query.get(data.get('confirm')):
|
||||
return None
|
||||
return User.query.get(data.get('confirm'))
|
||||
18
app/users/routes.py
Normal file
18
app/users/routes.py
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
from app import db
|
||||
from app.users import users
|
||||
from app.users.models import User
|
||||
# from forms import LoginForm, RequestResetForm, ResetPasswordForm, EditUserForm, AddUserForm
|
||||
from flask import render_template, redirect, url_for, flash, request
|
||||
from flask_login import login_required, login_user, current_user, logout_user
|
||||
from werkzeug.security import check_password_hash, generate_password_hash
|
||||
from datetime import datetime
|
||||
import os
|
||||
# import logging
|
||||
# logging.basicConfig(filename='logs.log', encoding='utf-8', level=logging.INFO)
|
||||
|
||||
|
||||
@users.route('/user_page/<user_id>')
|
||||
@login_required
|
||||
def user_page(user_id):
|
||||
|
||||
return render_template('user_page.html')
|
||||
8
wsgi.py
Normal file
8
wsgi.py
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
from app import create_app
|
||||
|
||||
|
||||
app, celery = create_app()
|
||||
|
||||
if __name__ == '__main__':
|
||||
with app.app_context():
|
||||
app.run(debug=True)
|
||||
Loading…
Add table
Add a link
Reference in a new issue