commit c97e3e8d4e474d3728ba46192527e65d093d7908 Author: ydb5755 Date: Wed Sep 4 20:22:49 2024 +0300 init diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..54ba69a --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +/__pycache__ +/errorlog.txt +/instance +/logs.log +/migrations \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..9f7986b --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +# Pilzno diff --git a/app/__init__.py b/app/__init__.py new file mode 100644 index 0000000..94b3f63 --- /dev/null +++ b/app/__init__.py @@ -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 \ No newline at end of file diff --git a/app/__pycache__/__init__.cpython-311.pyc b/app/__pycache__/__init__.cpython-311.pyc new file mode 100644 index 0000000..ad90979 Binary files /dev/null and b/app/__pycache__/__init__.cpython-311.pyc differ diff --git a/app/__pycache__/config.cpython-311.pyc b/app/__pycache__/config.cpython-311.pyc new file mode 100644 index 0000000..311e52c Binary files /dev/null and b/app/__pycache__/config.cpython-311.pyc differ diff --git a/app/__pycache__/models.cpython-311.pyc b/app/__pycache__/models.cpython-311.pyc new file mode 100644 index 0000000..6f92904 Binary files /dev/null and b/app/__pycache__/models.cpython-311.pyc differ diff --git a/app/config.py b/app/config.py new file mode 100644 index 0000000..a50fa7c --- /dev/null +++ b/app/config.py @@ -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') \ No newline at end of file diff --git a/app/main/__init__.py b/app/main/__init__.py new file mode 100644 index 0000000..700798b --- /dev/null +++ b/app/main/__init__.py @@ -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 \ No newline at end of file diff --git a/app/main/__pycache__/__init__.cpython-311.pyc b/app/main/__pycache__/__init__.cpython-311.pyc new file mode 100644 index 0000000..4112e73 Binary files /dev/null and b/app/main/__pycache__/__init__.cpython-311.pyc differ diff --git a/app/main/__pycache__/routes.cpython-311.pyc b/app/main/__pycache__/routes.cpython-311.pyc new file mode 100644 index 0000000..167bfcf Binary files /dev/null and b/app/main/__pycache__/routes.cpython-311.pyc differ diff --git a/app/main/routes.py b/app/main/routes.py new file mode 100644 index 0000000..01b8a13 --- /dev/null +++ b/app/main/routes.py @@ -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') \ No newline at end of file diff --git a/app/main/templates/base.html b/app/main/templates/base.html new file mode 100644 index 0000000..22262c1 --- /dev/null +++ b/app/main/templates/base.html @@ -0,0 +1,38 @@ + + + + + + + {% block title %}{% endblock title %} + + + + {% block stylesheet %}{% endblock stylesheet %} + + + + {% with messages = get_flashed_messages(with_categories=true) %} + {% if messages %} + {% for category, message in messages %} +
+ {{ message }} +
+ {% endfor %} + {% endif %} + {% endwith %} + {% block content %}{% endblock content %} + + \ No newline at end of file diff --git a/app/main/templates/homepage.html b/app/main/templates/homepage.html new file mode 100644 index 0000000..8aad2a0 --- /dev/null +++ b/app/main/templates/homepage.html @@ -0,0 +1,2 @@ +{% extends 'base.html' %} +{% block title %}Customer Search{% endblock title %} \ No newline at end of file diff --git a/app/users/__init__.py b/app/users/__init__.py new file mode 100644 index 0000000..a390092 --- /dev/null +++ b/app/users/__init__.py @@ -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 \ No newline at end of file diff --git a/app/users/__pycache__/__init__.cpython-311.pyc b/app/users/__pycache__/__init__.cpython-311.pyc new file mode 100644 index 0000000..829a5b5 Binary files /dev/null and b/app/users/__pycache__/__init__.cpython-311.pyc differ diff --git a/app/users/__pycache__/models.cpython-311.pyc b/app/users/__pycache__/models.cpython-311.pyc new file mode 100644 index 0000000..2185249 Binary files /dev/null and b/app/users/__pycache__/models.cpython-311.pyc differ diff --git a/app/users/__pycache__/routes.cpython-311.pyc b/app/users/__pycache__/routes.cpython-311.pyc new file mode 100644 index 0000000..945ef39 Binary files /dev/null and b/app/users/__pycache__/routes.cpython-311.pyc differ diff --git a/app/users/forms.py b/app/users/forms.py new file mode 100644 index 0000000..e69de29 diff --git a/app/users/models.py b/app/users/models.py new file mode 100644 index 0000000..d412b08 --- /dev/null +++ b/app/users/models.py @@ -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')) \ No newline at end of file diff --git a/app/users/routes.py b/app/users/routes.py new file mode 100644 index 0000000..80205b7 --- /dev/null +++ b/app/users/routes.py @@ -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/') +@login_required +def user_page(user_id): + + return render_template('user_page.html') \ No newline at end of file diff --git a/wsgi.py b/wsgi.py new file mode 100644 index 0000000..c4f077c --- /dev/null +++ b/wsgi.py @@ -0,0 +1,8 @@ +from app import create_app + + +app, celery = create_app() + +if __name__ == '__main__': + with app.app_context(): + app.run(debug=True) \ No newline at end of file