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
|
||||
@ -118,7 +119,7 @@ def get_items_with_level_restriction(level_range, item_state, item_types):
|
||||
loads = json.loads
|
||||
if 'radical' in item_types:
|
||||
items.extend({'item_type': 'radical', 'answer': item['meaning'], 'question': item['image']
|
||||
if item['image'] else item['character']} for item in loads(current_user.radicals)
|
||||
if item['image'] else item['character']} for item in loads(current_user.radicals)
|
||||
if item['user_specific'] and item['user_specific']['srs'] in item_state
|
||||
and item['level'] in level_range)
|
||||
radical_count = len(items)
|
||||
@ -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