init
This commit is contained in:
commit
c97e3e8d4e
21 changed files with 231 additions and 0 deletions
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')
|
||||
Loading…
Add table
Add a link
Reference in a new issue