def test_confirmation_invalid(self): """ Trying to confirm a new e-mail address when the ``confirmation_key`` is invalid. """ new_email = '*****@*****.**' session = orm.sessionmaker() user = session.query(User).get(1) user.signup.change_email(new_email) # Verify email with wrong SHA1 self.failIf(SignupManager.confirm_email('sha1')) # Correct SHA1, but non-existend in db. self.failIf(SignupManager.confirm_email(10 * 'a1b2'))
def email_confirm(request, confirmation_key, template_name='registration/email_confirm_fail.html', success_url=None, extra_context=None): """ Confirms an email address with a confirmation key. Confirms a new email address by running :func:`User.objects.confirm_email` method. If the method returns an :class:`User` the user will have his new e-mail address set and redirected to ``success_url``. If no ``User`` is returned the user will be represented with a fail message from ``template_name``. :param confirmation_key: String with a SHA1 representing the confirmation key used to verify a new email address. :param template_name: String containing the template name which should be rendered when confirmation fails. When confirmation is successful, no template is needed because the user will be redirected to ``success_url``. :param success_url: String containing the URL which is redirected to after a successful confirmation. Supplied argument must be able to be rendered by ``reverse`` function. :param extra_context: Dictionary of variables that are passed on to the template supplied by ``template_name``. """ user = SignupManager.confirm_email(confirmation_key) if user: messages.success(request, _('Your email address has been changed.'), fail_silently=True) if success_url: redirect_to = success_url else: redirect_to = reverse('baph_email_confirm_complete') return redirect(redirect_to) else: if not extra_context: extra_context = dict() return render_to_response(template_name, extra_context, context_instance=RequestContext(request))
def test_confirmation_valid(self): """ Confirmation of a new e-mail address with turns out to be valid. """ new_email = '*****@*****.**' session = orm.sessionmaker() user = session.query(User).get(1) user.signup.change_email(new_email) # Confirm email confirmed_user = SignupManager.confirm_email(user.signup.email_confirmation_key) self.failUnlessEqual(user, confirmed_user) # Check the new email is set. self.failUnlessEqual(confirmed_user.email, new_email) # ``email_new`` and ``email_verification_key`` should be empty self.failIf(confirmed_user.signup.email_unconfirmed) self.failIf(confirmed_user.signup.email_confirmation_key)
def test_confirmation_valid(self): """ Confirmation of a new e-mail address with turns out to be valid. """ new_email = '*****@*****.**' session = orm.sessionmaker() user = session.query(User).get(1) user.signup.change_email(new_email) # Confirm email confirmed_user = SignupManager.confirm_email( user.signup.email_confirmation_key) self.failUnlessEqual(user, confirmed_user) # Check the new email is set. self.failUnlessEqual(confirmed_user.email, new_email) # ``email_new`` and ``email_verification_key`` should be empty self.failIf(confirmed_user.signup.email_unconfirmed) self.failIf(confirmed_user.signup.email_confirmation_key)