summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEvgeny Fadeev <evgeny.fadeev@gmail.com>2014-05-05 12:11:34 -0300
committerEvgeny Fadeev <evgeny.fadeev@gmail.com>2014-05-05 12:11:34 -0300
commitc86905cb084a77c8ace0d5f930e3d5e828c71f44 (patch)
tree17cb4d200256e880e722c074f4e4d7ceacdbf49b
parent86c649415558841e37b65ed9ace867ac53e0586a (diff)
downloadaskbot-c86905cb084a77c8ace0d5f930e3d5e828c71f44.tar.gz
askbot-c86905cb084a77c8ace0d5f930e3d5e828c71f44.tar.bz2
askbot-c86905cb084a77c8ace0d5f930e3d5e828c71f44.zip
added matching to user accounts via valid email for mozilla persona authentication
-rw-r--r--askbot/deps/django_authopenid/backends.py18
-rw-r--r--askbot/deps/django_authopenid/views.py32
2 files changed, 41 insertions, 9 deletions
diff --git a/askbot/deps/django_authopenid/backends.py b/askbot/deps/django_authopenid/backends.py
index 6d01a3a0..20533040 100644
--- a/askbot/deps/django_authopenid/backends.py
+++ b/askbot/deps/django_authopenid/backends.py
@@ -158,6 +158,24 @@ class AuthBackend(object):
except User.DoesNotExist:
return None
+ elif method == 'valid_email':
+ try:
+ user = User.objects.get(email=email)
+ except User.DoesNotExist:
+ return None
+ except User.MultipleObjectsReturned:
+ LOG.critical(
+ ('have more than one user with email %s ' +
+ 'he/she will not be able to authenticate with ' +
+ 'the email address in the place of user name') % email_address
+ )
+ return None
+
+ if user.email_isvalid == False:
+ return None
+
+ return user
+
elif method == 'oauth':
if login_providers[provider_name]['type'] in ('oauth', 'oauth2'):
try:
diff --git a/askbot/deps/django_authopenid/views.py b/askbot/deps/django_authopenid/views.py
index e303ddba..4ac42733 100644
--- a/askbot/deps/django_authopenid/views.py
+++ b/askbot/deps/django_authopenid/views.py
@@ -542,18 +542,32 @@ def signin(request, template_name='authopenid/signin.html'):
email = util.mozilla_persona_get_email_from_assertion(assertion)
if email:
user = authenticate(email=email, method='mozilla-persona')
+ if user is None:
+ user = authenticate(email=email, method='valid_email')
+ if user:
+ #create mozilla persona user association
+ #because we trust the given email address belongs
+ #to the same user
+ UserAssociation(
+ openid_url=email,
+ user=user,
+ provider_name='mozilla-persona',
+ last_used_timestamp=datetime.datetime.now()
+ ).save()
+
if user:
login(request, user)
return HttpResponseRedirect(next_url)
- else:
- #pre-fill email address with persona registration
- request.session['email'] = email
- return finalize_generic_signin(
- request,
- login_provider_name = 'mozilla-persona',
- user_identifier = email,
- redirect_url = next_url
- )
+
+ #else - create new user account
+ #pre-fill email address with persona registration
+ request.session['email'] = email
+ return finalize_generic_signin(
+ request,
+ login_provider_name = 'mozilla-persona',
+ user_identifier = email,
+ redirect_url = next_url
+ )
elif login_form.cleaned_data['login_type'] == 'openid':
#initiate communication process