Added the ability to change email addresses

This commit is contained in:
2011-05-16 14:00:46 +01:00
parent 46b4b9a041
commit 2e22a9663c
5 changed files with 54 additions and 2 deletions

View File

@@ -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

View File

@@ -16,6 +16,7 @@ urlpatterns = patterns('',
(r'^profile/refresh/', views.refresh_access),
(r'^profile/refresh/(?P<userid>\d+)/', views.refresh_access),
(r'^profile/change/password/$', password_change),
(r'^profile/change/email/$', views.email_change),
(r'^users/(?P<username>.*)/$', views.user_view),
(r'^users/$', views.user_lookup),
)

View File

@@ -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))

View File

@@ -0,0 +1,16 @@
{% extends "base.html" %}
{% block title %}Change your E-mail address{% endblock %}
{% block content %}
<form action="" method="post">
<table>
{{ form.as_table }}
</table>
<br />
{% csrf_token %}
<input type="submit" value="Change Email" />
</form>
{% endblock %}

View File

@@ -49,7 +49,8 @@ function refresh_apikey(key) {
<p>
<div class="skill_controls">
<a href="{% url sso.views.refresh_access %}">Update Access</a>
<a href="{% url django.contrib.auth.views.password_change %}">Change Your Password</a><br/>
<a href="{% url django.contrib.auth.views.password_change %}">Change Your Password</a>
<a href="{% url sso.views.email_change %}">Change Your E-mail</a
</div>
</p>