token auth methods

This commit is contained in:
Matt Wright
2012-06-11 18:06:47 -04:00
parent c4ada0d998
commit 90d52c6561
+10 -4
View File
@@ -3,7 +3,7 @@ from datetime import datetime
from flask import current_app
from flask.ext.security.exceptions import BadCredentialsError, \
UserNotFoundError
UserNotFoundError, AuthenticationError
from flask.ext.security.utils import generate_token
from werkzeug.local import LocalProxy
@@ -36,9 +36,15 @@ def generate_authentication_token(user):
return user
def login_by_token(token):
pass
def authenticate_by_token(token):
try:
return find_user_by_authentication_token(token)
except UserNotFoundError:
raise BadCredentialsError('Invalid authentication token')
except Exception, e:
raise AuthenticationError(str(e))
def reset_authentication_token(user):
security.datastore._save_model(generate_authentication_token(user))
user = generate_authentication_token(user)
security.datastore._save_model(user)