From ee4c8f2a3fa753a8685849f6c713fc4b7e5f89a7 Mon Sep 17 00:00:00 2001 From: Matt Wright Date: Tue, 11 Dec 2012 15:10:26 -0500 Subject: [PATCH] Fix `login_user` method to actually return a True or False value as mentioned in mattupstate/flask-social-example#8 --- flask_security/babel.py | 16 ++++++++++++++++ flask_security/utils.py | 20 +++++++++++--------- 2 files changed, 27 insertions(+), 9 deletions(-) create mode 100644 flask_security/babel.py diff --git a/flask_security/babel.py b/flask_security/babel.py new file mode 100644 index 0000000..7e8f734 --- /dev/null +++ b/flask_security/babel.py @@ -0,0 +1,16 @@ + +try: + from flask.ext.babel import gettext, ngettext, lazy_gettext + babel_installed = True +except ImportError: + babel_installed = False + def gettext(string, **variables): + return string % variables + + def ngettext(singular, plural, num, **variables): + return (singular if num == 1 else plural) % variables + + def lazy_gettext(string, **variables): + return gettext(string, **variables) + +_ = gettext diff --git a/flask_security/utils.py b/flask_security/utils.py index 9b44408..7bc1902 100644 --- a/flask_security/utils.py +++ b/flask_security/utils.py @@ -38,23 +38,25 @@ _pwd_context = LocalProxy(lambda: _security.pwd_context) def login_user(user, remember=True): """Performs the login and sends the appropriate signal.""" - _login_user(user, remember) + if not _login_user(user, remember): + return False if _security.trackable: - old_current, new_current = user.current_login_at, datetime.utcnow() - user.last_login_at = old_current or new_current - user.current_login_at = new_current - + old_current_login, new_current_login = user.current_login_at, datetime.utcnow() remote_addr = request.remote_addr or 'untrackable' - old_current, new_current = user.current_login_ip, remote_addr - user.last_login_ip = old_current or new_current - user.current_login_ip = new_current + old_current_ip, new_current_ip = user.current_login_ip, remote_addr + user.last_login_at = old_current_login or new_current_login + user.current_login_at = new_current_login + user.last_login_ip = old_current_ip or new_current_ip + user.current_login_ip = new_current_ip user.login_count = user.login_count + 1 if user.login_count else 1 - _datastore.put(user) + _datastore.put(user) + identity_changed.send(current_app._get_current_object(), identity=Identity(user.id)) + return True def logout_user():