def sendpw(request): """ send a new password to the user. It return a mail with a new pasword and a confirm link in. To activate the new password, the user should click on confirm link. url : /sendpw/ templates : authopenid/sendpw_email.txt, authopenid/sendpw.html """ logging.debug('') if settings.USE_EXTERNAL_LEGACY_LOGIN == True: logging.debug('delegating to view dealing with external password recovery') return HttpResponseRedirect(reverse('user_external_legacy_login_issues')) msg = request.GET.get('msg','') logging.debug('request method is %s' % request.method) if request.method == 'POST': form = EmailPasswordForm(request.POST) if form.is_valid(): logging.debug('EmailPasswordForm is valid') new_pw = User.objects.make_random_password() confirm_key = UserPasswordQueue.objects.get_new_confirm_key() try: uqueue = UserPasswordQueue.objects.get( user=form.user_cache ) except: uqueue = UserPasswordQueue( user=form.user_cache ) uqueue.new_password = new_pw uqueue.confirm_key = confirm_key uqueue.save() # send email subject = _("Request for new password") message_template = loader.get_template( 'authopenid/sendpw_email.txt') key_link = settings.APP_URL + reverse('user_confirmchangepw') + '?key=' + confirm_key logging.debug('emailing new password for %s' % form.user_cache.username) message_context = Context({ 'site_url': settings.APP_URL + reverse('index'), 'key_link': key_link, 'username': form.user_cache.username, 'password': new_pw, }) message = message_template.render(message_context) send_mail(subject, message, settings.DEFAULT_FROM_EMAIL, [form.user_cache.email]) msg = _("A new password and the activation link were sent to your email address.") else: form = EmailPasswordForm() logging.debug('showing reset password form') return render_to_response('authopenid/sendpw.html', { 'form': form, 'msg': msg }, context_instance=RequestContext(request))
def sendpw(request): """ send a new password to the user. It return a mail with a new pasword and a confirm link in. To activate the new password, the user should click on confirm link. url : /sendpw/ templates : authopenid/sendpw_email.txt, authopenid/sendpw.html """ msg = request.GET.get('msg', '') if request.POST: form = EmailPasswordForm(request.POST) if form.is_valid(): new_pw = User.objects.make_random_password() confirm_key = UserPasswordQueue.objects.get_new_confirm_key() try: uqueue = UserPasswordQueue.objects.get(user=form.user_cache) except: uqueue = UserPasswordQueue(user=form.user_cache) uqueue.new_password = new_pw uqueue.confirm_key = confirm_key uqueue.save() # send email current_domain = Site.objects.get_current().domain subject = _("Request for new password") message_template = loader.get_template( 'authopenid/sendpw_email.txt') message_context = Context({ 'site_url': 'http://%s' % current_domain, 'confirm_key': confirm_key, 'username': form.user_cache.username, 'password': new_pw, 'url_confirm': reverse('user_confirmchangepw'), }) message = message_template.render(message_context) send_mail(subject, message, settings.DEFAULT_FROM_EMAIL, [form.user_cache.email]) msg = _("A new password has been sent to your email address.") else: form = EmailPasswordForm() return render('authopenid/sendpw.html', { 'form': form, 'msg': msg }, context_instance=RequestContext(request))
def sendpw(request): """ send a new password to the user. It return a mail with a new pasword and a confirm link in. To activate the new password, the user should click on confirm link. url : /sendpw/ templates : authopenid/sendpw_email.txt, authopenid/sendpw.html """ msg = request.GET.get('msg','') if request.POST: form = EmailPasswordForm(request.POST) if form.is_valid(): new_pw = User.objects.make_random_password() confirm_key = UserPasswordQueue.objects.get_new_confirm_key() try: uqueue = UserPasswordQueue.objects.get( user=form.user_cache ) except: uqueue = UserPasswordQueue( user=form.user_cache ) uqueue.new_password = new_pw uqueue.confirm_key = confirm_key uqueue.save() # send email current_domain = Site.objects.get_current().domain subject = _("Request for new password") message_template = loader.get_template( 'authopenid/sendpw_email.txt') message_context = Context({ 'site_url': 'http://%s' % current_domain, 'confirm_key': confirm_key, 'username': form.user_cache.username, 'password': new_pw, 'url_confirm': reverse('user_confirmchangepw'), }) message = message_template.render(message_context) send_mail(subject, message, settings.DEFAULT_FROM_EMAIL, [form.user_cache.email]) msg = _("A new password has been sent to your email address.") else: form = EmailPasswordForm() return render('authopenid/sendpw.html', { 'form': form, 'msg': msg }, context_instance=RequestContext(request))