def change_password(http_request, nonce, user): """ Change password after email verification. """ form = PasswordForm(http_request.POST or None) if not form.is_valid(): form_title = _("choose a new password") form_action = '/accounts/verify/%s/' % nonce.hashkey form_submit = _("change password") form_javascript = "document.getElementById('id_password').focus()" return render_to_response('form.html', locals(), context_instance=RequestContext(http_request)) user.set_password(form.cleaned_data['password']) user.save() nonce.delete() return success_page(http_request, _("Password changed"), _("Your new password has been saved."), _("Click the link in the top right corner to log in."))
def register(http_request, nonce): """ Register a new user after email verification. """ form = RegistrationForm(http_request.POST or None) user = None if form.is_valid(): user = form.create_user(nonce.email) if user is None: form_title = _("create a new account") form_action = '/accounts/verify/%s/' % nonce.hashkey form_submit = _("create account") form_javascript = "document.getElementById('id_username').focus()" return render_to_response('form.html', locals(), context_instance=RequestContext(http_request)) user.first_name = form.cleaned_data['first_name'] user.last_name = form.cleaned_data['last_name'] user.save() nonce.delete() return success_page(http_request, _("Account created"), _("A new user account was created."), _("Click the link in the top right corner to log in."))
Nonce.objects.create(email=address, hashkey=hashkey, ip=ip) domain = Site.objects.get_current().domain message = email_message(domain, hashkey, user) try: send_mail("Browsershots email verification", message, settings.DEFAULT_FROM_EMAIL, [address], fail_silently=False) except smtplib.SMTPException, e: return error_page(http_request, _("email error"), _("Could not send email."), str(e)) hide_hashkey(hashkey) return success_page( http_request, _("email sent"), _("A verification email was sent to %(address)s.") % locals(), _("Check your email inbox and follow the instructions in the message." ), _("If your email provider uses graylisting, it may take a few minutes." )) def hide_hashkey(hashkey): """ Remove hashkey from debug output. """ from django.db import connection for index, query in enumerate(connection.queries): if hashkey in query['sql']: query['sql'] = query['sql'].replace(hashkey, '[hidden]')
if len(users): user = users[0] hashkey = crypto.random_md5() Nonce.objects.create(email=address, hashkey=hashkey, ip=ip) domain = Site.objects.get_current().domain message = email_message(domain, hashkey, user) try: send_mail("Browsershots email verification", message, settings.DEFAULT_FROM_EMAIL, [address], fail_silently=False) except smtplib.SMTPException, e: return error_page(http_request, _("email error"), _("Could not send email."), str(e)) hide_hashkey(hashkey) return success_page(http_request, _("email sent"), _("A verification email was sent to %(address)s.") % locals(), _("Check your email inbox and follow the instructions in the message."), _("If your email provider uses graylisting, it may take a few minutes.")) def hide_hashkey(hashkey): """ Remove hashkey from debug output. """ from django.db import connection for index, query in enumerate(connection.queries): if hashkey in query['sql']: query['sql'] = query['sql'].replace(hashkey, '[hidden]') class UserForm(forms.Form): """