aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--account/forms.py87
-rw-r--r--account/models.py17
-rw-r--r--account/static/js/account_email_resend.js19
-rw-r--r--account/templates/account/email_resend.html29
-rw-r--r--account/templates/account/email_resend_done.html24
-rw-r--r--account/urls.py10
-rw-r--r--account/views.py19
-rw-r--r--static/js/account_email_resend.js19
-rw-r--r--templates/registration/registration_complete.html1
9 files changed, 204 insertions, 21 deletions
diff --git a/account/forms.py b/account/forms.py
index ca54711..f5f515f 100644
--- a/account/forms.py
+++ b/account/forms.py
@@ -5,6 +5,8 @@ account/forms.py for skaschool
"""
from django import forms
+from django.contrib.auth.models import User
+from django.contrib.sites.models import Site, RequestSite
from registration.forms import RegistrationFormUniqueEmail
from django.utils.translation import ugettext_lazy as _
@@ -17,27 +19,76 @@ class UserRegForm(RegistrationFormUniqueEmail):
add fields 'realname', 'gender', 'institute' and 'captcha'
"""
# XXX: keep consistent with GENDERS in 'models.UserProfile'
- GENDERS = (
- ('M', _("Male")),
- ('F', _("Female")),
- ('X', _("Secret")),
- )
+ GENDERS = UserProfile.GENDERS
+ IDENTIFIES = UserProfile.IDENTIFIES
realname = forms.CharField(max_length=30, label=_("Name"))
gender = forms.ChoiceField(choices=GENDERS, label=_("Gender"))
institute = forms.CharField(max_length=100, label=_("Institute"))
+ identify = forms.ChoiceField(choices=IDENTIFIES, label=_("Identify"))
- def __init__(self, *args, **kw):
- super(UserRegForm, self).__init__(*args, **kw)
- # order form fields
- self.fields.keyOrder = [
- 'username',
- 'email',
- 'password1',
- 'password2',
- 'realname',
- 'gender',
- 'institute',
- ]
+ #def __init__(self, *args, **kw):
+ # super(UserRegForm, self).__init__(*args, **kw)
+ # # order form fields
+ # self.fields.keyOrder = [
+ # 'username',
+ # 'email',
+ # 'password1',
+ # 'password2',
+ # 'realname',
+ # 'gender',
+ # 'institute',
+ # 'identify',
+ # ]
+
+
+class ResendEmailForm(forms.Form):
+ """
+ form used in ResendEmailView
+ """
+ username = forms.RegexField(regex=r'^[\w.@+-]+$',
+ max_length=30,
+ label=_("Username"),
+ error_messages={'invalid': _("This value may contain only letters, numbers and @/./+/-/_ characters.")})
+ is_update_email = forms.BooleanField(label=_("Is update email"),
+ required=False, initial=False)
+ email = forms.EmailField(label=_("E-mail"), required=False)
+
+ def clean_username(self):
+ username = self.cleaned_data.get('username', '')
+ user = User.objects.filter(username=username)
+ if not user:
+ raise forms.ValidationError(_("Username not exists"), code='invalid')
+ return username
+
+ def clean(self):
+ # if 'is_update_email' True, then email field is required
+ is_update_email = self.cleaned_data.get('is_update_email', False)
+ email = self.cleaned_data.get('email', '')
+ if (is_update_email and (not email)):
+ raise forms.ValidationError(_("Email is required"), code='required')
+ return self.cleaned_data
+
+ def update_email(self):
+ # update User email if user provided a different email
+ username = self.cleaned_data.get('username', '')
+ email = self.cleaned_data.get('email', '')
+ user = User.objects.get(username=username)
+ if email:
+ user.email = email
+ user.save()
+
+ def resend_email(self):
+ # resend activation email
+ if Site._meta.installed:
+ site = Site.objects.get_current()
+ else:
+ site = RequestSite(self.request)
+
+ username = self.cleaned_data.get('username', '')
+ user = User.objects.get(username=username)
+ regprofile = user.registrationprofile_set.get(user=user)
+ if not regprofile.activation_key_expired():
+ regprofile.send_activation_email(site)
class UpdateProfileForm(forms.ModelForm):
@@ -49,6 +100,6 @@ class UpdateProfileForm(forms.ModelForm):
class Meta:
model = UserProfile
- fields = ('realname', 'gender', 'institute')
+ fields = ('realname', 'gender', 'institute', 'identify')
diff --git a/account/models.py b/account/models.py
index 684f2d8..9f2fff7 100644
--- a/account/models.py
+++ b/account/models.py
@@ -36,12 +36,29 @@ class UserProfile(models.Model):
('N', _("No")),
('C', _("Checking")),
)
+ # choices for identify
+ IDENTIFIES = (
+ ('OT', _("Other")),
+ ('UG', _("Undergraudate")),
+ ('MG', _("Master graudate")),
+ ('PG', _("PhD graudate")),
+ ('PD', _("Post-doctoral")),
+ ('SR', _("Assistant researcher")),
+ ('AR', _("Associate researcher")),
+ ('DR', _("Distinguished researcher")),
+ ('RE', _("Researcher")),
+ ('IN', _("Instructor")),
+ ('SP', _("Assistant professor")),
+ ('AP', _("Associate professor")),
+ ('PR', _("Professor")),
+ )
# model fields
# FK default backward manager name 'userprofile_set'
user = models.ForeignKey(User, unique=True, verbose_name=_("Username"))
realname = models.CharField(_("Name"), max_length=30)
gender = models.CharField(_("Gender"), max_length=1, choices=GENDERS)
institute = models.CharField(_("Institute"), max_length=100)
+ identify = models.CharField(_("Identify"), max_length=2, choices=IDENTIFIES)
# store the infomation about approval and sponsorship
is_approved = models.CharField(_("Is approved"), max_length=1,
choices=APPROVED_STATUS, default='C')
diff --git a/account/static/js/account_email_resend.js b/account/static/js/account_email_resend.js
new file mode 100644
index 0000000..e8d2411
--- /dev/null
+++ b/account/static/js/account_email_resend.js
@@ -0,0 +1,19 @@
+/*
+ * email_resend.js for 'account/email_resend.html'
+ */
+
+$(document).ready(function() {
+ // disable email field by default
+ $("input#id_email").prop("disabled", true);
+
+ // update email field when 'is_update_email' checkbox changed
+ $("input#id_is_update_email").change(function(e) {
+ if ($(this).prop("checked")) {
+ $("input#id_email").prop("disabled", false);
+ }
+ else {
+ $("input#id_email").prop("disabled", true);
+ }
+ });
+});
+
diff --git a/account/templates/account/email_resend.html b/account/templates/account/email_resend.html
new file mode 100644
index 0000000..bdb2f30
--- /dev/null
+++ b/account/templates/account/email_resend.html
@@ -0,0 +1,29 @@
+{% extends 'base.html' %}
+{% load staticfiles %}
+{% load url from future %}
+{% load bootstrap3 %}
+
+{# resend activation email done #}
+
+{% block title %}
+重新发送激活邮件 | 2014 SKA Summer School
+{% endblock %}
+
+{% block content %}
+ <div class="container">
+ <h2>重新发送激活邮件</h2>
+ <br>
+
+ <form role="form" class="form-horizontal" method="post">
+ {% csrf_token %}
+ {% bootstrap_form form layout='horizontal' %}
+ {% buttons submit='提交' reset='重置' layout='horizontal' %}{% endbuttons %}
+ </form>
+ </div>
+{% endblock %}
+
+{% block js_extra %}
+ <script src="{% static 'js/account_email_resend.js' %}" type="text/javascript"></script>
+{% endblock %}
+
+{# vim: set ts=8 sw=2 tw=0 fenc=utf-8 ft=htmldjango.html: #}
diff --git a/account/templates/account/email_resend_done.html b/account/templates/account/email_resend_done.html
new file mode 100644
index 0000000..ff7ad6b
--- /dev/null
+++ b/account/templates/account/email_resend_done.html
@@ -0,0 +1,24 @@
+{% extends 'base.html' %}
+{% load staticfiles %}
+{% load url from future %}
+{% load bootstrap3 %}
+
+{# resend activation email done #}
+
+{% block title %}
+已重新发送激活邮件 | 2014 SKA Summer School
+{% endblock %}
+
+{% block content %}
+ <div class="container">
+ <h2>已重新发送激活邮件</h2>
+ <p class="lead">
+ 我们已向您注册使用的邮箱重新发送了激活邮件,请留意查收,并使用其中的链接激活账户。
+ </p>
+
+ <br>
+ <p>如果您还未收到激活邮件,或者激活链接已过期,请直接联系我们以激活账户:<a href="mailto:skaschool2014@163.com"><code>skaschool2014@163.com</code></a></p>
+ </div>
+{% endblock %}
+
+{# vim: set ts=8 sw=2 tw=0 fenc=utf-8 ft=htmldjango.html: #}
diff --git a/account/urls.py b/account/urls.py
index e193772..b17abd5 100644
--- a/account/urls.py
+++ b/account/urls.py
@@ -12,7 +12,7 @@ from django.contrib.auth.decorators import login_required
from registration.backends.default.views import ActivationView
from registration.backends.default.views import RegistrationView
-from account.views import ProfileView, UpdateProfileView, ListApprovedView
+from account.views import ResendEmailView, ProfileView, UpdateProfileView, ListApprovedView
from account.forms import UserRegForm
@@ -38,6 +38,14 @@ urlpatterns = patterns('',
url(r'^logout/$', 'django.contrib.auth.views.logout',
{'template_name': 'account/logout.html'},
name='logout'),
+ # resend activate email
+ url(r'^email/resend/$',
+ ResendEmailView.as_view(),
+ name='email_resend'),
+ # resend activate email done
+ url(r'^email/resend/done/$',
+ TemplateView.as_view(template_name='account/email_resend_done.html'),
+ name='email_resend_done'),
# change password
# If 'post_change_redirect' not provided,
# then redirect to url 'password_change_done'.
diff --git a/account/views.py b/account/views.py
index 3186abb..a4c3337 100644
--- a/account/views.py
+++ b/account/views.py
@@ -6,16 +6,31 @@ views.py of app 'account'
from django.shortcuts import render
from django.views.generic.base import TemplateView
-from django.views.generic.edit import UpdateView
+from django.views.generic.edit import FormView, UpdateView
from django.views.generic.list import ListView
from django.core.urlresolvers import reverse_lazy
from django.http import HttpResponseRedirect
from account.models import UserProfile
-from account.forms import UpdateProfileForm
+from account.forms import ResendEmailForm, UpdateProfileForm
###### Class-based views ######
+class ResendEmailView(FormView):
+ """
+ class-based view used to resend activation email
+ if user provided different email, then update email to User instance
+ """
+ form_class = ResendEmailForm
+ template_name = 'account/email_resend.html'
+ success_url = reverse_lazy('email_resend_done')
+
+ def form_valid(self, form):
+ form.update_email()
+ form.resend_email()
+ return super(ResendEmailView, self).form_valid(form)
+
+
class ProfileView(TemplateView):
"""
class view to show profile page
diff --git a/static/js/account_email_resend.js b/static/js/account_email_resend.js
new file mode 100644
index 0000000..e8d2411
--- /dev/null
+++ b/static/js/account_email_resend.js
@@ -0,0 +1,19 @@
+/*
+ * email_resend.js for 'account/email_resend.html'
+ */
+
+$(document).ready(function() {
+ // disable email field by default
+ $("input#id_email").prop("disabled", true);
+
+ // update email field when 'is_update_email' checkbox changed
+ $("input#id_is_update_email").change(function(e) {
+ if ($(this).prop("checked")) {
+ $("input#id_email").prop("disabled", false);
+ }
+ else {
+ $("input#id_email").prop("disabled", true);
+ }
+ });
+});
+
diff --git a/templates/registration/registration_complete.html b/templates/registration/registration_complete.html
index 553a154..49ea090 100644
--- a/templates/registration/registration_complete.html
+++ b/templates/registration/registration_complete.html
@@ -21,6 +21,7 @@
还未收到激活邮件?
<a href="#" class="btn btn-default">重新发送激活邮件</a>
</p>
+ <p>如果您的激活链接已过期,请直接联系我们以激活账户:<a href="mailto:skaschool2014@163.com"><code>skaschool2014@163.com</code></a></p>
</div>
{% endblock %}