Exemple #1
0
    def post(self):
        next = self.get_argument("next", None);
        form = RegisterForm(TornadoMultiDict(self))
        if next is None:
            del form.next

        if not form.validate():
            self.render('register.html', form=form, next=next)
            return

        # user might already exist - people _do_ forget.
        # outwardly, we don't want to reflect that an email address is
        # already registered, but we can send a different email.

        user = self.session.query(UserAccount).filter(UserAccount.email==form.email.data).first()
        if user is None:
            token = Token.create_registration(
                email=form.email.data,
                password=form.password.data,
                next=next)
            email_template = 'email/confirm_register.txt'
            email_subject = "%s - confirm your account" % settings.site_name
        else:
            token = Token.create_login(user_id=user.id, next=next)
            email_template = 'email/forgotten_password.txt'
            email_subject = "%s - forgotten password" % settings.site_name

        self.session.add(token)
        self.session.commit()

        confirmation_url = "%s/t/%s" % (settings.root_url,token.name)
        email_body = self.render_string(email_template,
            confirmation_url=confirmation_url)

        if settings.bypass_email:
            self.render('token_sent.html',
                bypass_email=settings.bypass_email,
                confirmation_url=confirmation_url,
                email_subject=email_subject,
                email_body=email_body)
            return

        # send it
        mailer.send_email(addr_from=settings.site_email,
            addr_to=form.email.data,
            subject=email_subject,
            content=email_body)
        # redirect to avoid multiple emails due to refresh clicking!
        self.redirect('/emailsent')
Exemple #2
0
    def post(self):
        next = self.get_argument("next", None)
        form = RegisterForm(TornadoMultiDict(self))
        if next is None:
            del form.next

        if not form.validate():
            self.render('register.html', form=form, next=next)
            return

        # user might already exist - people _do_ forget.
        # outwardly, we don't want to reflect that an email address is
        # already registered, but we can send a different email.

        user = self.session.query(UserAccount).filter(
            UserAccount.email == form.email.data).first()
        if user is None:
            token = Token.create_registration(email=form.email.data,
                                              password=form.password.data,
                                              next=next)
            email_template = 'email/confirm_register.txt'
            email_subject = "%s - confirm your account" % settings.site_name
        else:
            token = Token.create_login(user_id=user.id, next=next)
            email_template = 'email/forgotten_password.txt'
            email_subject = "%s - forgotten password" % settings.site_name

        self.session.add(token)
        self.session.commit()

        confirmation_url = "%s/t/%s" % (settings.root_url, token.name)
        email_body = self.render_string(email_template,
                                        confirmation_url=confirmation_url)

        if settings.bypass_email:
            self.render('token_sent.html',
                        bypass_email=settings.bypass_email,
                        confirmation_url=confirmation_url,
                        email_subject=email_subject,
                        email_body=email_body)
            return

        # send it
        mailer.send_email(addr_from=settings.site_email,
                          addr_to=form.email.data,
                          subject=email_subject,
                          content=email_body)
        # redirect to avoid multiple emails due to refresh clicking!
        self.redirect('/emailsent')
Exemple #3
0
    def post(self):
        form = ForgotForm(TornadoMultiDict(self))
        if not form.validate():
            self.render('forgot.html', form=form)
            return

        user = self.session.query(UserAccount).filter(
            UserAccount.email == form.email.data).first()
        # don't leak existence of email addresses.
        if user is not None:
            token = Token.create_login(user.id)
            email_template = 'email/forgotten_password.txt'
            email_subject = "%s - forgotten details" % settings.site_name

            self.session.add(token)
            self.session.commit()

            confirmation_url = "%s/t/%s" % (settings.root_url, token.name)
            email_body = self.render_string(email_template,
                                            confirmation_url=confirmation_url)

            if settings.bypass_email:
                self.render('token_sent.html',
                            bypass_email=settings.bypass_email,
                            confirmation_url=confirmation_url,
                            email_subject=email_subject,
                            email_body=email_body)
                return

            # send it
            mailer.send_email(addr_from=settings.site_email,
                              addr_to=form.email.data,
                              subject=email_subject,
                              content=email_body)

        # redirect to avoid multiple emails due to refresh clicking!
        self.redirect('/emailsent')
Exemple #4
0
    def post(self):
        form = ForgotForm(TornadoMultiDict(self))
        if not form.validate():
            self.render('forgot.html', form=form)
            return

        user = self.session.query(UserAccount).filter(UserAccount.email==form.email.data).first()
        # don't leak existence of email addresses.
        if user is not None:
            token = Token.create_login(user.id)
            email_template = 'email/forgotten_password.txt'
            email_subject = "%s - forgotten details" % settings.site_name

            self.session.add(token)
            self.session.commit()

            confirmation_url = "%s/t/%s" % (settings.root_url,token.name)
            email_body = self.render_string(email_template,
                confirmation_url=confirmation_url)

            if settings.bypass_email:
                self.render('token_sent.html',
                    bypass_email=settings.bypass_email,
                    confirmation_url=confirmation_url,
                    email_subject=email_subject,
                    email_body=email_body)
                return

            # send it
            mailer.send_email(addr_from=settings.site_email,
                addr_to=form.email.data,
                subject=email_subject,
                content=email_body)

        # redirect to avoid multiple emails due to refresh clicking!
        self.redirect('/emailsent')