From fc7794b9e0d568fba23190a814ead1d64c1c81e2 Mon Sep 17 00:00:00 2001 From: burzuf Date: Mon, 16 Mar 2020 20:47:50 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9F=D0=B5=D1=80=D0=B5=D0=BF=D0=B8=D1=81?= =?UTF-8?q?=D0=B0=D0=BD=D1=8B=20=D1=81=D1=82=D1=80=D0=B0=D0=BD=D0=B8=D1=86?= =?UTF-8?q?=D1=8B=20=D1=81=20=D1=83=D1=87=D0=B5=D1=82=D0=BE=D0=BC=20=D0=B0?= =?UTF-8?q?=D0=B2=D1=82=D0=BE=D1=80=D0=B8=D0=B7=D0=B0=D1=86=D0=B8=D0=B8,?= =?UTF-8?q?=20=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=20=D0=BB?= =?UTF-8?q?=D0=BE=D0=B3=D0=B0=D1=83=D1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- __init__.py | 29 +++--- db_routing.py | 12 ++- templates/hero.html | 108 ---------------------- templates/index.html | 20 +++- templates/registration.html | 2 +- templates/{content.html => workshop.html} | 9 +- 6 files changed, 51 insertions(+), 129 deletions(-) delete mode 100644 templates/hero.html rename templates/{content.html => workshop.html} (96%) diff --git a/__init__.py b/__init__.py index 6837ac4..69c7a5d 100644 --- a/__init__.py +++ b/__init__.py @@ -1,6 +1,6 @@ -from flask import render_template, request, redirect +from flask import render_template, request, redirect, url_for import db_routing -from flask_login import LoginManager, current_user, login_user, login_required +from flask_login import LoginManager, login_user, login_required, logout_user from db_routing import app, db import os import hashlib @@ -10,8 +10,7 @@ login_manager = LoginManager(app) @login_manager.user_loader def load_user(user_id): - userID = db_routing.find_user(id=user_id).id - return userID + return db_routing.find_user(id=user_id) @app.route('/', methods=['GET']) @@ -26,7 +25,7 @@ def register(): userPassw = request.form['RegUserPassw'] if db_routing.add_user(userName, passw_hash(userPassw)): login_user(db_routing.find_user(username=userName)) - return redirect('content.html') + return redirect(url_for('workshop')) return render_template('registration.html') @@ -37,18 +36,24 @@ def login(): user = verify_password(userName, userPassw) if user: login_user(user) - return render_template('content.html') + return redirect(url_for('workshop')) -@app.route('/content', methods=['GET']) +@app.route('/logout') +def logout(): + logout_user() + return redirect(url_for('/')) + + +@app.route('/workshop', methods=['GET']) @login_required -def content(): - return render_template('content.html') +def workshop(): + return render_template('workshop.html') -# @app.errorhandler(404) -# def not_found(error): -# return render_template('404.html'), 404 +@app.errorhandler(404) +def not_found(error): + return render_template('error.html'), 404 def passw_hash(user_passw, salt=os.urandom(32)): diff --git a/db_routing.py b/db_routing.py index 2285fc8..8c119c2 100644 --- a/db_routing.py +++ b/db_routing.py @@ -1,6 +1,5 @@ from flask_sqlalchemy import SQLAlchemy from flask import Flask -from flask_login import UserMixin app = Flask('Jarvis', static_folder='static', template_folder='templates') app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///data.db' @@ -8,7 +7,7 @@ app.config['SECRET_KEY'] = 'Radius' db = SQLAlchemy(app) -class User(UserMixin, db.Model): +class User(db.Model): __tablename__ = 'Users' id = db.Column(db.Integer, primary_key=True) username = db.Column(db.String(80), unique=True, nullable=False) @@ -18,6 +17,15 @@ class User(UserMixin, db.Model): self.username = username self.password = password + def is_active(self): + return True + + def is_authenticated(self): + return self.is_authenticated + + def get_id(self): + return self.id + class Trigger(db.Model): __tablename__ = 'Triggers' diff --git a/templates/hero.html b/templates/hero.html deleted file mode 100644 index 1466646..0000000 --- a/templates/hero.html +++ /dev/null @@ -1,108 +0,0 @@ - - - - - - - jarvis - - - - -
- -
-
- -
-
-
-

nagbator228#264

- -
-
-
-
-
-
-
-
-
-
- -
-
-
- Jarvis -
-
-

Ваш индивидуальный помощник на каждый день

-
-
- - - -
-
-
-
-
-
- - -
-
- - - -
-
- - \ No newline at end of file diff --git a/templates/index.html b/templates/index.html index 6fa3768..f7a43d6 100644 --- a/templates/index.html +++ b/templates/index.html @@ -21,7 +21,18 @@
-
+
+ {% if current_user.is_authenticated %} +

{{ current_user.username }}

+ + {% else %}
Войти
+ {% endif %}
@@ -61,9 +73,15 @@

Ваш индивидуальный помощник на каждый день

+ {% if current_user.is_authenticated %} + + + + {% else %} + {% endif %}
diff --git a/templates/registration.html b/templates/registration.html index 66192c0..8bf8ef6 100644 --- a/templates/registration.html +++ b/templates/registration.html @@ -34,7 +34,7 @@ - + diff --git a/templates/content.html b/templates/workshop.html similarity index 96% rename from templates/content.html rename to templates/workshop.html index bb4c840..7cb64a0 100644 --- a/templates/content.html +++ b/templates/workshop.html @@ -14,7 +14,7 @@
- +

J.a.r.v.i.s

@@ -22,14 +22,13 @@
-

nagbator228#264

+

{{ current_user.username }}