def email_reset(request): if request.method == "POST": form = EmailResetForm(request.POST, user = request.user) if form.is_valid(): # save new email info to DB (temporal) try: rer = ResetEmailRequest.objects.get(user=request.user) rer.email = form.cleaned_data['email'] except ResetEmailRequest.DoesNotExist: rer = ResetEmailRequest(user=request.user, email=form.cleaned_data['email']) rer.save() # send email to the new address user = request.user email = form.cleaned_data["email"] current_site = get_current_site(request) site_name = current_site.name domain = current_site.domain c = { 'email': email, 'domain': domain, 'site_name': site_name, 'uid': int_to_base36(user.id), 'user': user, 'token': default_token_generator.make_token(user), 'protocol': 'http', } subject = loader.render_to_string('accounts/email_reset_subject.txt', c) subject = ''.join(subject.splitlines()) email_body = loader.render_to_string('accounts/email_reset_email.html', c) send_mail(subject=subject, email_body=email_body, email_to=[email]) return HttpResponseRedirect(reverse('accounts.views.email_reset_done')) else: form = EmailResetForm(user = request.user) return render_to_response('accounts/email_reset_form.html',locals(),context_instance=RequestContext(request))
def email_reset(request): if request.method == "POST": form = EmailResetForm(request.POST, user=request.user) if form.is_valid(): # Save new email info to DB (temporal) try: rer = ResetEmailRequest.objects.get(user=request.user) rer.email = form.cleaned_data['email'] except ResetEmailRequest.DoesNotExist: rer = ResetEmailRequest(user=request.user, email=form.cleaned_data['email']) rer.save() # Send email to the new address user = request.user email = form.cleaned_data["email"] current_site = get_current_site(request) site_name = current_site.name domain = current_site.domain c = { 'email': email, 'domain': domain, 'site_name': site_name, 'uid': int_to_base36(user.id), 'user': user, 'token': default_token_generator.make_token(user), 'protocol': 'http', } subject = loader.render_to_string( 'accounts/email_reset_subject.txt', c) subject = ''.join(subject.splitlines()) email_body = loader.render_to_string( 'accounts/email_reset_email.html', c) send_mail(subject=subject, email_body=email_body, email_to=[email]) return HttpResponseRedirect( reverse('accounts.views.email_reset_done')) else: form = EmailResetForm(user=request.user) tvars = {'form': form} return render(request, 'accounts/email_reset_form.html', tvars)
def email_reset(request): if request.method == "POST": form = EmailResetForm(request.POST, user=request.user) if form.is_valid(): # Save new email info to DB (temporal) try: rer = ResetEmailRequest.objects.get(user=request.user) rer.email = form.cleaned_data["email"] except ResetEmailRequest.DoesNotExist: rer = ResetEmailRequest(user=request.user, email=form.cleaned_data["email"]) rer.save() # Send email to the new address user = request.user email = form.cleaned_data["email"] current_site = get_current_site(request) site_name = current_site.name domain = current_site.domain c = { "email": email, "domain": domain, "site_name": site_name, "uid": int_to_base36(user.id), "user": user, "token": default_token_generator.make_token(user), "protocol": "http", } subject = loader.render_to_string("accounts/email_reset_subject.txt", c) subject = "".join(subject.splitlines()) email_body = loader.render_to_string("accounts/email_reset_email.html", c) send_mail(subject=subject, email_body=email_body, email_to=[email]) return HttpResponseRedirect(reverse("accounts.views.email_reset_done")) else: form = EmailResetForm(user=request.user) tvars = {"form": form} return render(request, "accounts/email_reset_form.html", tvars)