mirror of
https://github.com/nikdoof/test-auth.git
synced 2025-12-14 06:42:16 +00:00
Added the ability to change email addresses
This commit is contained in:
@@ -108,3 +108,19 @@ class APIPasswordForm(forms.Form):
|
|||||||
""" API Password reset form """
|
""" API Password reset form """
|
||||||
|
|
||||||
password = forms.CharField(widget=forms.PasswordInput, label="Password")
|
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
|
||||||
|
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ urlpatterns = patterns('',
|
|||||||
(r'^profile/refresh/', views.refresh_access),
|
(r'^profile/refresh/', views.refresh_access),
|
||||||
(r'^profile/refresh/(?P<userid>\d+)/', views.refresh_access),
|
(r'^profile/refresh/(?P<userid>\d+)/', views.refresh_access),
|
||||||
(r'^profile/change/password/$', password_change),
|
(r'^profile/change/password/$', password_change),
|
||||||
|
(r'^profile/change/email/$', views.email_change),
|
||||||
(r'^users/(?P<username>.*)/$', views.user_view),
|
(r'^users/(?P<username>.*)/$', views.user_view),
|
||||||
(r'^users/$', views.user_lookup),
|
(r'^users/$', views.user_lookup),
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ from eve_api.tasks import import_apikey, import_apikey_result, update_user_acces
|
|||||||
from eve_proxy.models import ApiAccessLog
|
from eve_proxy.models import ApiAccessLog
|
||||||
|
|
||||||
from sso.models import ServiceAccount, Service, SSOUser, ExistingUser, ServiceError
|
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
|
@login_required
|
||||||
def profile(request):
|
def profile(request):
|
||||||
@@ -253,3 +253,21 @@ def refresh_access(request, userid=0):
|
|||||||
update_user_access(request.user.id)
|
update_user_access(request.user.id)
|
||||||
messages.add_message(request, messages.INFO, "User access updated.")
|
messages.add_message(request, messages.INFO, "User access updated.")
|
||||||
return redirect('sso.views.profile')
|
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))
|
||||||
|
|
||||||
|
|||||||
16
app/templates/sso/emailchange.html
Normal file
16
app/templates/sso/emailchange.html
Normal 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 %}
|
||||||
@@ -49,7 +49,8 @@ function refresh_apikey(key) {
|
|||||||
<p>
|
<p>
|
||||||
<div class="skill_controls">
|
<div class="skill_controls">
|
||||||
<a href="{% url sso.views.refresh_access %}">Update Access</a>
|
<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>
|
</div>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user