From eba6c19f6e731398809e2b1558a838b7636c4822 Mon Sep 17 00:00:00 2001 From: Nathan Cannon Date: Thu, 24 Dec 2015 17:03:54 +0000 Subject: [PATCH] Added login persistence. --- wanikaniburned.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/wanikaniburned.py b/wanikaniburned.py index 24e3bb2..9faf65e 100644 --- a/wanikaniburned.py +++ b/wanikaniburned.py @@ -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()