def request_temp_login(request): if request.method == 'POST': form = TemporaryLoginRequestForm(request.POST) if form.is_valid(): users = form.user_cache for u in users: if u.is_suspended(): return forward_suspended_user(request, u, False) for u in users: try: hash = get_object_or_404(ValidationHash, user=u, type='templogin') if hash.expiration < datetime.datetime.now(): hash.delete() return request_temp_login(request) except: hash = ValidationHash.objects.create_new(u, 'templogin', [u.id]) send_template_email([u], "auth/temp_login_email.html", {'temp_login_code': hash}) request.user.message_set.create(message=_("An email has been sent with your temporary login key")) return HttpResponseRedirect(reverse('index')) else: form = TemporaryLoginRequestForm() return render_to_response( 'auth/temp_login_request.html', {'form': form}, context_instance=RequestContext(request))