Permalink
Browse files

Added ACCOUNT_EMAIL_CONFIRMATION_AUTO_LOGIN feature

Fixes #130.
  • Loading branch information...
brosner committed Oct 18, 2016
1 parent 7f38b49 commit c6f6b5adcc09cf06ff81f110b17839f11c52b189
Showing with 12 additions and 1 deletion.
  1. +1 −0 CHANGELOG.md
  2. +1 −0 account/conf.py
  3. +10 −1 account/views.py
View
@@ -14,6 +14,7 @@ version with these. Your code will need to be updated to continue working.
* fixed migration with language codes to dynamically set
* added password expiration
* added password stripping by default
+ * added `ACCOUNT_EMAIL_CONFIRMATION_AUTO_LOGIN` feature (default is `False`)
## 1.3.0
View
@@ -48,6 +48,7 @@ class AccountAppConf(AppConf):
EMAIL_CONFIRMATION_REQUIRED = False
EMAIL_CONFIRMATION_EMAIL = True
EMAIL_CONFIRMATION_EXPIRE_DAYS = 3
+ EMAIL_CONFIRMATION_AUTO_LOGIN = False
EMAIL_CONFIRMATION_ANONYMOUS_REDIRECT_URL = "account_login"
EMAIL_CONFIRMATION_AUTHENTICATED_REDIRECT_URL = None
EMAIL_CONFIRMATION_URL = "account_confirm_email"
View
@@ -458,6 +458,10 @@ def post(self, *args, **kwargs):
self.object = confirmation = self.get_object()
confirmation.confirm()
self.after_confirmation(confirmation)
+ if settings.ACCOUNT_EMAIL_CONFIRMATION_AUTO_LOGIN:
+ self.user = self.login_user(confirmation.email_address.user)
+ else:
+ self.user = self.request.user
redirect_url = self.get_redirect_url()
if not redirect_url:
ctx = self.get_context_data()
@@ -491,7 +495,7 @@ def get_context_data(self, **kwargs):
return ctx
def get_redirect_url(self):
- if self.request.user.is_authenticated():
+ if self.user.is_authenticated():
if not settings.ACCOUNT_EMAIL_CONFIRMATION_AUTHENTICATED_REDIRECT_URL:
return settings.ACCOUNT_LOGIN_REDIRECT_URL
return settings.ACCOUNT_EMAIL_CONFIRMATION_AUTHENTICATED_REDIRECT_URL
@@ -503,6 +507,11 @@ def after_confirmation(self, confirmation):
user.is_active = True
user.save()
+ def login_user(self, user):
+ user.backend = "django.contrib.auth.backends.ModelBackend"
+ auth.login(self.request, user)
+ return user
+
class ChangePasswordView(PasswordMixin, FormView):

0 comments on commit c6f6b5a

Please sign in to comment.