Fix login_user method to actually return a True or False value as mentioned in mattupstate/flask-social-example#8

This commit is contained in:
Matt Wright
2012-12-11 15:10:26 -05:00
parent 1092ffc9ea
commit ee4c8f2a3f
2 changed files with 27 additions and 9 deletions
+16
View File
@@ -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
+11 -9
View File
@@ -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():