Added login persistence.
This commit is contained in:
parent
441623a947
commit
eba6c19f6e
@ -3,7 +3,8 @@ import re
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
import flask
|
||||
from flask.ext.login import LoginManager, login_user, login_required, current_user, logout_user, login_fresh
|
||||
from flask.ext.login import LoginManager, login_user, login_required, current_user, logout_user, login_fresh, \
|
||||
confirm_login
|
||||
from flask.ext.sqlalchemy import SQLAlchemy
|
||||
from flask.ext.wtf import Form
|
||||
import requests
|
||||
@ -161,12 +162,12 @@ def show_home():
|
||||
if form.validate_on_submit():
|
||||
user = User.query.get(str(form.api_key.data))
|
||||
if user:
|
||||
login_user(user)
|
||||
login_user(user, remember=True)
|
||||
return flask.redirect(flask.url_for('show_quiz'))
|
||||
else:
|
||||
try:
|
||||
new_user = User(str(form.api_key.data))
|
||||
login_user(new_user)
|
||||
login_user(new_user, remember=True)
|
||||
return flask.redirect(flask.url_for('show_quiz'))
|
||||
except ValueError as err:
|
||||
flask.flash(err)
|
||||
@ -179,6 +180,7 @@ def show_home():
|
||||
def show_quiz():
|
||||
if not login_fresh():
|
||||
if User.query.get(current_user.api_key):
|
||||
confirm_login()
|
||||
return flask.render_template("quiz.html")
|
||||
else:
|
||||
logout_user()
|
||||
|
Loading…
Reference in New Issue
Block a user