def resend_confirmation(request): """Resend confirmation email.""" if request.method == 'POST': form = EmailConfirmationForm(request.POST) if form.is_valid(): email = form.cleaned_data['email'] try: reg_prof = RegistrationProfile.objects.get( user__email=email, user__is_active=False) form = try_send_email_with_form( RegistrationProfile.objects.send_confirmation_email, form, 'email', reg_prof) except RegistrationProfile.DoesNotExist: # Don't leak existence of email addresses. pass # Form may now be invalid if email failed to send. if form.is_valid(): return jingo.render(request, 'users/resend_confirmation_done.html', {'email': email}) else: form = EmailConfirmationForm() return jingo.render(request, 'users/resend_confirmation.html', {'form': form})
def resend_confirmation(request, template): """Resend confirmation email.""" if request.method == 'POST': form = EmailConfirmationForm(request.POST) if form.is_valid(): email = form.cleaned_data['email'] try: reg_prof = RegistrationProfile.objects.get( user__email=email) if not reg_prof.user.is_active: form = try_send_email_with_form( RegistrationProfile.objects.send_confirmation_email, form, 'email', reg_prof) else: form = try_send_email_with_form( RegistrationProfile.objects.send_confirmation_email, form, 'email', reg_prof, text_template='users/email/already_activated.ltxt', html_template='users/email/already_activated.html', subject=_('Account already activated')) except RegistrationProfile.DoesNotExist: # Send already active email if user exists try: user = User.objects.get(email=email, is_active=True) current_site = Site.objects.get_current() email_kwargs = {'domain': current_site.domain, 'login_url': reverse('users.login')} subject = _('Account already activated') @email_utils.safe_translation def _make_mail(locale): mail = email_utils.make_mail( subject=subject, text_template='users/email/already_activated.ltxt', html_template='users/email/already_activated.html', context_vars=email_kwargs, from_email=settings.DEFAULT_FROM_EMAIL, to_email=user.email) return mail email_utils.send_messages( [_make_mail(request.LANGUAGE_CODE)]) except User.DoesNotExist: # Don't leak existence of email addresses. pass # Form may now be invalid if email failed to send. if form.is_valid(): return render( request, template + 'resend_confirmation_done.html', {'email': email}) else: form = EmailConfirmationForm() return render(request, template + 'resend_confirmation.html', { 'form': form})
def resend_confirmation(request, template): """Resend confirmation email.""" if request.method == 'POST': form = EmailConfirmationForm(request.POST) if form.is_valid(): email = form.cleaned_data['email'] try: reg_prof = RegistrationProfile.objects.get(user__email=email) if not reg_prof.user.is_active: form = try_send_email_with_form( RegistrationProfile.objects.send_confirmation_email, form, 'email', reg_prof) else: form = try_send_email_with_form( RegistrationProfile.objects.send_confirmation_email, form, 'email', reg_prof, text_template='users/email/already_activated.ltxt', html_template='users/email/already_activated.html', subject=_('Account already activated')) except RegistrationProfile.DoesNotExist: # Send already active email if user exists try: user = User.objects.get(email=email, is_active=True) current_site = Site.objects.get_current() email_kwargs = { 'domain': current_site.domain, 'login_url': reverse('users.login') } subject = _('Account already activated') message = email_utils.render_email( 'users/email/already_activated.ltxt', email_kwargs) # TODO: Send HTML email here. form = try_send_email_with_form( mail.send_mail, form, 'email', subject, message, settings.DEFAULT_FROM_EMAIL, [user.email]) except User.DoesNotExist: # Don't leak existence of email addresses. pass # Form may now be invalid if email failed to send. if form.is_valid(): return render(request, template + 'resend_confirmation_done.html', {'email': email}) else: form = EmailConfirmationForm() return render(request, template + 'resend_confirmation.html', {'form': form})
def resend_confirmation(request): """Resend confirmation email.""" if request.method == 'POST': form = EmailConfirmationForm(request.POST) if form.is_valid(): email = form.cleaned_data['email'] try: reg_prof = RegistrationProfile.objects.get( user__email=email) if not reg_prof.user.is_active: form = try_send_email_with_form( RegistrationProfile.objects.send_confirmation_email, form, 'email', reg_prof) else: form = try_send_email_with_form( RegistrationProfile.objects.send_confirmation_email, form, 'email', reg_prof, email_template='users/email/already_activated.ltxt', email_subject=_('Account already activated')) except RegistrationProfile.DoesNotExist: # Send already active email if user exists try: user = User.objects.get(email=email, is_active=True) current_site = Site.objects.get_current() email_kwargs = {'domain': current_site.domain, 'login_url': reverse('users.login')} message = render_to_string( 'users/email/already_activated.ltxt', email_kwargs) form = try_send_email_with_form( mail.send_mail, form, 'email', _('Account already activated'), message, settings.DEFAULT_FROM_EMAIL, [user.email]) except User.DoesNotExist: # Don't leak existence of email addresses. pass # Form may now be invalid if email failed to send. if form.is_valid(): return jingo.render(request, 'users/resend_confirmation_done.html', {'email': email}) else: form = EmailConfirmationForm() return jingo.render(request, 'users/resend_confirmation.html', {'form': form})
def resend_confirmation(request): """Resend confirmation email.""" if request.method == "POST": form = EmailConfirmationForm(request.POST) if form.is_valid(): email = form.cleaned_data["email"] try: reg_prof = RegistrationProfile.objects.get(user__email=email, user__is_active=False) RegistrationProfile.objects.send_confirmation_email(reg_prof) except RegistrationProfile.DoesNotExist: # Don't leak existence of email addresses. pass return jingo.render(request, "users/resend_confirmation_done.html", {"email": email}) else: form = EmailConfirmationForm() return jingo.render(request, "users/resend_confirmation.html", {"form": form})
def change_email(request): """Change user's email. Send confirmation first.""" if request.method == 'POST': form = EmailConfirmationForm(request.POST) u = request.user if form.is_valid() and u.email != form.cleaned_data['email']: # Delete old registration profiles. EmailChange.objects.filter(user=request.user).delete() # Create a new registration profile and send a confirmation email. email_change = EmailChange.objects.create_profile( user=request.user, email=form.cleaned_data['email']) EmailChange.objects.send_confirmation_email( email_change, form.cleaned_data['email']) return jingo.render(request, 'users/change_email_done.html', {'email': form.cleaned_data['email']}) else: form = EmailConfirmationForm(initial={'email': request.user.email}) return jingo.render(request, 'users/change_email.html', {'form': form})
def test_invalid_email_address(self): form = EmailConfirmationForm( self.user, data={'email': '[email protected]'}) assert not form.is_valid()
def test_correct_email(self): form = EmailConfirmationForm( self.user, data={'email': '*****@*****.**'}) assert form.is_valid()
def test_invalid_email_address(self): form = EmailConfirmationForm(self.user, data={'email': '[email protected]'}) assert not form.is_valid()
def test_correct_email(self): form = EmailConfirmationForm(self.user, data={'email': '*****@*****.**'}) assert form.is_valid()