def test_send_mail(self, DirectMailDelivery):
        from webidentity.sendmail import send_mail

        self.config.add_settings({})
        # Check that we propagate parameters correctly to the delivery system
        send_mail(u'My message', to='*****@*****.**')
        self.assertEquals(DirectMailDelivery().send.call_args_list, [
            ((u'My message', ), {'to': '*****@*****.**'})])
Exemplo n.º 2
0
    def send_confirmation_message(self):
        """Sends an email confirmation message to the user."""
        username = self.request.POST.get('username', '').strip()
        redirect_url = route_url('reset_password', self.request)
        if not username:
            self.request.session.flash(_(u'Please supply a username.'))
        else:
            user = self.session.query(User).filter(User.username == username).first()
            if user is None:
                self.request.session.flash(_(u'The given username does not match any account.'))
            else:
                # Create a password reset request that is valid for 24 hours
                reset = PasswordReset(user.id, datetime.now() + timedelta(hours=24))
                self.session.add(reset)
                message = self.create_message(user, reset)
                from_address = self.request.registry.settings['webidentity_from_address'].strip()
                send_mail(from_address, [user.email], message)
                self.request.session.flash(_(u'Password retrieval instructions have been emailed to you.'))
                redirect_url = self.request.application_url

        return HTTPFound(location=redirect_url)