Password Reset now allows for providing passwords when GENERATE_SERVICE_PASSWORD is false

This commit is contained in:
2010-04-03 21:19:39 +01:00
parent 45e303fb4e
commit 96de3cc5eb
3 changed files with 29 additions and 9 deletions

View File

@@ -51,6 +51,13 @@ def UserServiceAccountForm(user):
return ServiceAccountForm
class ServiceAccountResetForm(forms.Form):
def __init__(self, *args, **kwargs):
super(ServiceAccountResetForm, self).__init__(*args, **kwargs)
if not settings.GENERATE_SERVICE_PASSWORD:
self.password = forms.CharField(widget=forms.PasswordInput, label="Password" )
self.fields['password'] = self.password
class RedditAccountForm(forms.Form):
""" Reddit Account Form """

View File

@@ -13,7 +13,7 @@ from eve_api.api_puller.accounts import import_eve_account
from eve_api.models.api_player import EVEAccount, EVEPlayerCharacter
from sso.models import ServiceAccount, Service, SSOUser, ExistingUser, ServiceError
from sso.forms import EveAPIForm, UserServiceAccountForm, RedditAccountForm, UserLookupForm
from sso.forms import EveAPIForm, UserServiceAccountForm, ServiceAccountResetForm, RedditAccountForm, UserLookupForm
from reddit.models import RedditAccount
@@ -173,7 +173,7 @@ def service_del(request, serviceid=0):
return HttpResponseRedirect(reverse('sso.views.profile'))
@login_required
def service_reset(request, serviceid=0, accept=0):
def service_reset(request, serviceid=0):
if serviceid > 0 :
try:
acc = ServiceAccount.objects.get(id=serviceid)
@@ -184,15 +184,23 @@ def service_reset(request, serviceid=0, accept=0):
return HttpResponseRedirect(reverse('sso.views.profile'))
if acc.user == request.user:
if not accept:
if not request.method == 'POST':
form = ServiceAccountResetForm()
return render_to_response('sso/serviceaccount/reset.html', locals(), context_instance=RequestContext(request))
form = ServiceAccountResetForm(request.POST)
if form.is_valid():
if settings.GENERATE_SERVICE_PASSWORD:
passwd = hashlib.sha1('%s%s%s' % (acc.service_uid, settings.SECRET_KEY, random.randint(0, 2147483647))).hexdigest()
else:
passwd = form.cleaned_data['password']
api = acc.service.api_class
if not api.reset_password(acc.service_uid, passwd):
error = True
return render_to_response('sso/serviceaccount/resetcomplete.html', locals(), context_instance=RequestContext(request))
else:
return render_to_response('sso/serviceaccount/reset.html', locals(), context_instance=RequestContext(request))
return HttpResponseRedirect(reverse('sso.views.profile'))

View File

@@ -7,6 +7,11 @@
<p>This service will reset your password for account {{ acc.service_uid }} on {{ acc.service }}. If you wish to continue please click the link
below.</p>
<p><a href="/profile/reset/service/{{ serviceid }}/1">Reset my Password</a></p>
<form action="/profile/reset/service/{{ serviceid }}/" method="post">
<table>
{{ form.as_table }}
</table>
<input type="submit" value="Reset Account" />
</form>
{% endblock %}