|
|
@ -6,7 +6,7 @@ from flask import (Flask, flash, redirect, render_template, request,
|
|
|
|
from flask_login import LoginManager, login_required, login_user, logout_user
|
|
|
|
from flask_login import LoginManager, login_required, login_user, logout_user
|
|
|
|
|
|
|
|
|
|
|
|
from forms import LoginForm
|
|
|
|
from forms import LoginForm
|
|
|
|
from lotosa import LoToSa
|
|
|
|
from latosa import LaToSa
|
|
|
|
from user import User
|
|
|
|
from user import User
|
|
|
|
|
|
|
|
|
|
|
|
app = Flask(__name__)
|
|
|
|
app = Flask(__name__)
|
|
|
@ -19,12 +19,12 @@ app.config.update(
|
|
|
|
login_manager = LoginManager()
|
|
|
|
login_manager = LoginManager()
|
|
|
|
login_manager.init_app(app)
|
|
|
|
login_manager.init_app(app)
|
|
|
|
|
|
|
|
|
|
|
|
lotosa = LoToSa(app)
|
|
|
|
latosa = LaToSa(app)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@login_manager.user_loader
|
|
|
|
@login_manager.user_loader
|
|
|
|
def load_user(user_id) -> Union[User, None]:
|
|
|
|
def load_user(user_id) -> Union[User, None]:
|
|
|
|
for user in lotosa.get_users():
|
|
|
|
for user in latosa.get_users():
|
|
|
|
if user.uid == user_id:
|
|
|
|
if user.uid == user_id:
|
|
|
|
return user
|
|
|
|
return user
|
|
|
|
return None
|
|
|
|
return None
|
|
|
@ -32,24 +32,24 @@ def load_user(user_id) -> Union[User, None]:
|
|
|
|
|
|
|
|
|
|
|
|
@app.route('/', methods=['GET', 'POST'])
|
|
|
|
@app.route('/', methods=['GET', 'POST'])
|
|
|
|
def index():
|
|
|
|
def index():
|
|
|
|
i18n = lotosa.get_i18n(request)
|
|
|
|
i18n = latosa.get_i18n(request)
|
|
|
|
form = LoginForm()
|
|
|
|
form = LoginForm()
|
|
|
|
if request.method == 'POST':
|
|
|
|
if request.method == 'POST':
|
|
|
|
username = form.username.data
|
|
|
|
username = form.username.data
|
|
|
|
password = form.password.data
|
|
|
|
password = form.password.data
|
|
|
|
user = lotosa.login_user(username, password)
|
|
|
|
user = latosa.login_user(username, password)
|
|
|
|
if user:
|
|
|
|
if user:
|
|
|
|
login_user(user)
|
|
|
|
login_user(user)
|
|
|
|
flash('Logged in successfully.')
|
|
|
|
flash(i18n['login']['success'])
|
|
|
|
return redirect(url_for('admin'))
|
|
|
|
return redirect(url_for('admin'))
|
|
|
|
flash('Logged in faled, please try again.')
|
|
|
|
flash(i18n['login']['failed'])
|
|
|
|
return render_template('index.html', i18n=i18n, form=form)
|
|
|
|
return render_template('index.html', i18n=i18n, form=form)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@app.route('/admin', methods=['GET'])
|
|
|
|
@app.route('/admin', methods=['GET'])
|
|
|
|
@login_required
|
|
|
|
@login_required
|
|
|
|
def admin():
|
|
|
|
def admin():
|
|
|
|
i18n = lotosa.get_i18n(request)
|
|
|
|
i18n = latosa.get_i18n(request)
|
|
|
|
return render_template('admin.html', i18n=i18n)
|
|
|
|
return render_template('admin.html', i18n=i18n)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|