diff options
author | Weitian LI <liweitianux@gmail.com> | 2014-04-27 19:31:18 +0800 |
---|---|---|
committer | Weitian LI <liweitianux@gmail.com> | 2014-04-27 19:31:18 +0800 |
commit | ce1c277ee1904fb30df82f75a024822bd3411892 (patch) | |
tree | 30cafb886ea2da1e94a30082994251399d3f6df8 | |
parent | b784a30dd8c92f8e7f49a15e564c8ff422e85f94 (diff) | |
download | django-skaschool-ce1c277ee1904fb30df82f75a024822bd3411892.tar.bz2 |
* implemented function to auto login user after activation
o added 'login_on_activation' and connected to 'user_activated' signal
o updated 'activation_complete.html' template
-rw-r--r-- | account/models.py | 18 | ||||
-rw-r--r-- | templates/registration/activation_complete.html | 4 |
2 files changed, 19 insertions, 3 deletions
diff --git a/account/models.py b/account/models.py index 9886f6c..b42a8d1 100644 --- a/account/models.py +++ b/account/models.py @@ -5,13 +5,14 @@ # from django.db import models +from django.conf import settings from django.contrib.auth.models import User +from django.contrib.auth import login from django.db.models.fields.files import FieldFile -from django.conf import settings from django.utils.translation import ugettext_lazy as _ from django.db.models.signals import pre_delete -from registration.signals import user_registered +from registration.signals import user_registered, user_activated from account.extra import ContentTypeRestrictedFileField, OverwriteStorage @@ -235,9 +236,20 @@ def user_registered_callback(sender, user, request, **kwargs): profile.identify = request.POST['identify'] profile.save() -### connect 'user_registered_callback' to signal +### connect 'user_registered_callback' to signal user_registered user_registered.connect(user_registered_callback) +### login user after activated +def login_on_activation(sender, user, request, **kwargs): + """ + Logs in the user after activation + """ + user.backend = 'django.contrib.auth.backends.ModelBackend' + login(request, user) + +# connect 'login_on_activation' to signal user_activated +user_activated.connect(login_on_activation) + ### delete files associated with model FileField # Pre-delete signal function for deleting files a model diff --git a/templates/registration/activation_complete.html b/templates/registration/activation_complete.html index d27622a..fb03a7e 100644 --- a/templates/registration/activation_complete.html +++ b/templates/registration/activation_complete.html @@ -15,7 +15,11 @@ <p class="lead">您已成功激活账户。</p> <br> + {% if user.is_authenticated %} + <p><a href="{% url 'profile' %}" class="btn btn-primary">进入个人主页</a></p> + {% else %} <p><a href="{% url 'login' %}" class="btn btn-primary">登录</a></p> + {% endif %} </div> {% endblock %} |