Skip to content

Commit c6f6b5a

Browse files
committed
Added ACCOUNT_EMAIL_CONFIRMATION_AUTO_LOGIN feature
Fixes #130.
1 parent 7f38b49 commit c6f6b5a

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ version with these. Your code will need to be updated to continue working.
1414
* fixed migration with language codes to dynamically set
1515
* added password expiration
1616
* added password stripping by default
17+
* added `ACCOUNT_EMAIL_CONFIRMATION_AUTO_LOGIN` feature (default is `False`)
1718

1819
## 1.3.0
1920

account/conf.py

+1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ class AccountAppConf(AppConf):
4848
EMAIL_CONFIRMATION_REQUIRED = False
4949
EMAIL_CONFIRMATION_EMAIL = True
5050
EMAIL_CONFIRMATION_EXPIRE_DAYS = 3
51+
EMAIL_CONFIRMATION_AUTO_LOGIN = False
5152
EMAIL_CONFIRMATION_ANONYMOUS_REDIRECT_URL = "account_login"
5253
EMAIL_CONFIRMATION_AUTHENTICATED_REDIRECT_URL = None
5354
EMAIL_CONFIRMATION_URL = "account_confirm_email"

account/views.py

+10-1
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,10 @@ def post(self, *args, **kwargs):
458458
self.object = confirmation = self.get_object()
459459
confirmation.confirm()
460460
self.after_confirmation(confirmation)
461+
if settings.ACCOUNT_EMAIL_CONFIRMATION_AUTO_LOGIN:
462+
self.user = self.login_user(confirmation.email_address.user)
463+
else:
464+
self.user = self.request.user
461465
redirect_url = self.get_redirect_url()
462466
if not redirect_url:
463467
ctx = self.get_context_data()
@@ -491,7 +495,7 @@ def get_context_data(self, **kwargs):
491495
return ctx
492496

493497
def get_redirect_url(self):
494-
if self.request.user.is_authenticated():
498+
if self.user.is_authenticated():
495499
if not settings.ACCOUNT_EMAIL_CONFIRMATION_AUTHENTICATED_REDIRECT_URL:
496500
return settings.ACCOUNT_LOGIN_REDIRECT_URL
497501
return settings.ACCOUNT_EMAIL_CONFIRMATION_AUTHENTICATED_REDIRECT_URL
@@ -503,6 +507,11 @@ def after_confirmation(self, confirmation):
503507
user.is_active = True
504508
user.save()
505509

510+
def login_user(self, user):
511+
user.backend = "django.contrib.auth.backends.ModelBackend"
512+
auth.login(self.request, user)
513+
return user
514+
506515

507516
class ChangePasswordView(PasswordMixin, FormView):
508517

0 commit comments

Comments
 (0)