From 2e22a9663c743f49bc21787cb3566e6a0bb90381 Mon Sep 17 00:00:00 2001 From: Andrew Williams Date: Mon, 16 May 2011 14:00:46 +0100 Subject: [PATCH] Added the ability to change email addresses --- app/sso/forms.py | 16 ++++++++++++++++ app/sso/urls.py | 1 + app/sso/views.py | 20 +++++++++++++++++++- app/templates/sso/emailchange.html | 16 ++++++++++++++++ app/templates/sso/profile.html | 3 ++- 5 files changed, 54 insertions(+), 2 deletions(-) create mode 100644 app/templates/sso/emailchange.html diff --git a/app/sso/forms.py b/app/sso/forms.py index 1e7105c..920d4b7 100644 --- a/app/sso/forms.py +++ b/app/sso/forms.py @@ -108,3 +108,19 @@ class APIPasswordForm(forms.Form): """ API Password reset form """ password = forms.CharField(widget=forms.PasswordInput, label="Password") + + +class EmailChangeForm(forms.Form): + """ Email Change Form """ + + email1 = forms.EmailField(label=u'New E-mail Address', max_length=75) + email2 = forms.EmailField(label=u'Confirm New E-mail Address', max_length=75) + + def clean_email2(self): + email1 = self.cleaned_data.get('email1') + email2 = self.cleaned_data.get('email2') + if email1 and email2: + if email1 != email2: + raise forms.ValidationError("The two e-mail fields didn't match.") + return email2 + diff --git a/app/sso/urls.py b/app/sso/urls.py index c6fc005..2dad1a0 100644 --- a/app/sso/urls.py +++ b/app/sso/urls.py @@ -16,6 +16,7 @@ urlpatterns = patterns('', (r'^profile/refresh/', views.refresh_access), (r'^profile/refresh/(?P\d+)/', views.refresh_access), (r'^profile/change/password/$', password_change), + (r'^profile/change/email/$', views.email_change), (r'^users/(?P.*)/$', views.user_view), (r'^users/$', views.user_lookup), ) diff --git a/app/sso/views.py b/app/sso/views.py index 31c3a0d..9620855 100644 --- a/app/sso/views.py +++ b/app/sso/views.py @@ -22,7 +22,7 @@ from eve_api.tasks import import_apikey, import_apikey_result, update_user_acces from eve_proxy.models import ApiAccessLog from sso.models import ServiceAccount, Service, SSOUser, ExistingUser, ServiceError -from sso.forms import UserServiceAccountForm, ServiceAccountResetForm, UserLookupForm, APIPasswordForm +from sso.forms import UserServiceAccountForm, ServiceAccountResetForm, UserLookupForm, APIPasswordForm, EmailChangeForm @login_required def profile(request): @@ -253,3 +253,21 @@ def refresh_access(request, userid=0): update_user_access(request.user.id) messages.add_message(request, messages.INFO, "User access updated.") return redirect('sso.views.profile') + + +@login_required +def email_change(request): + """ Change the user's email address """ + + if request.method == 'POST': + form = EmailChangeForm(request.POST) + if form.is_valid(): + request.user.email = form.cleaned_data['email2'] + request.user.save() + messages.add_message(request, messages.INFO, "E-mail address changed to %s." % form.cleaned_data['email2']) + return redirect('sso.views.profile') # Redirect after POST + else: + form = EmailChangeForm() # An unbound form + + return render_to_response('sso/emailchange.html', locals(), context_instance=RequestContext(request)) + diff --git a/app/templates/sso/emailchange.html b/app/templates/sso/emailchange.html new file mode 100644 index 0000000..91b0188 --- /dev/null +++ b/app/templates/sso/emailchange.html @@ -0,0 +1,16 @@ +{% extends "base.html" %} + +{% block title %}Change your E-mail address{% endblock %} + +{% block content %} + +
+ +{{ form.as_table }} +
+
+{% csrf_token %} + +
+ +{% endblock %} diff --git a/app/templates/sso/profile.html b/app/templates/sso/profile.html index 7b786a5..cff293e 100644 --- a/app/templates/sso/profile.html +++ b/app/templates/sso/profile.html @@ -49,7 +49,8 @@ function refresh_apikey(key) {