mirror of
https://github.com/nikdoof/test-auth.git
synced 2025-12-14 14:52:15 +00:00
Password Reset now allows for providing passwords when GENERATE_SERVICE_PASSWORD is false
This commit is contained in:
@@ -51,6 +51,13 @@ def UserServiceAccountForm(user):
|
|||||||
|
|
||||||
return ServiceAccountForm
|
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):
|
class RedditAccountForm(forms.Form):
|
||||||
""" Reddit Account Form """
|
""" Reddit Account Form """
|
||||||
|
|
||||||
|
|||||||
24
sso/views.py
24
sso/views.py
@@ -13,7 +13,7 @@ from eve_api.api_puller.accounts import import_eve_account
|
|||||||
from eve_api.models.api_player import EVEAccount, EVEPlayerCharacter
|
from eve_api.models.api_player import EVEAccount, EVEPlayerCharacter
|
||||||
|
|
||||||
from sso.models import ServiceAccount, Service, SSOUser, ExistingUser, ServiceError
|
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
|
from reddit.models import RedditAccount
|
||||||
|
|
||||||
@@ -173,7 +173,7 @@ def service_del(request, serviceid=0):
|
|||||||
return HttpResponseRedirect(reverse('sso.views.profile'))
|
return HttpResponseRedirect(reverse('sso.views.profile'))
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
def service_reset(request, serviceid=0, accept=0):
|
def service_reset(request, serviceid=0):
|
||||||
if serviceid > 0 :
|
if serviceid > 0 :
|
||||||
try:
|
try:
|
||||||
acc = ServiceAccount.objects.get(id=serviceid)
|
acc = ServiceAccount.objects.get(id=serviceid)
|
||||||
@@ -184,15 +184,23 @@ def service_reset(request, serviceid=0, accept=0):
|
|||||||
return HttpResponseRedirect(reverse('sso.views.profile'))
|
return HttpResponseRedirect(reverse('sso.views.profile'))
|
||||||
|
|
||||||
if acc.user == request.user:
|
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))
|
return render_to_response('sso/serviceaccount/reset.html', locals(), context_instance=RequestContext(request))
|
||||||
|
|
||||||
passwd = hashlib.sha1('%s%s%s' % (acc.service_uid, settings.SECRET_KEY, random.randint(0, 2147483647))).hexdigest()
|
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
|
api = acc.service.api_class
|
||||||
if not api.reset_password(acc.service_uid, passwd):
|
if not api.reset_password(acc.service_uid, passwd):
|
||||||
error = True
|
error = True
|
||||||
return render_to_response('sso/serviceaccount/resetcomplete.html', locals(), context_instance=RequestContext(request))
|
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'))
|
return HttpResponseRedirect(reverse('sso.views.profile'))
|
||||||
|
|
||||||
|
|||||||
@@ -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
|
<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>
|
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 %}
|
{% endblock %}
|
||||||
|
|||||||
Reference in New Issue
Block a user