예제 #1
0
 def process_request(self, req):
     if 'email_verification_token' not in req.session:
         chrome.add_notice(req, 'Your email is already verified')
     elif req.method != 'POST':
         pass
     elif 'resend' in req.args:
         mgr = AccountManager(self.env)
         mgr._notify(
             'email_verification_requested', 
             req.authname, 
             req.session['email_verification_token']
         )
         chrome.add_notice(req,
                 'A notification email has been resent to %s.',
                 req.session.get('email'))
     elif 'verify' in req.args:
         if req.args['token'] == req.session['email_verification_token']:
             del req.session['email_verification_token']
             chrome.add_notice(req, 'Thank you for verifying your email address')
         else:
             chrome.add_warning(req, 'Invalid verification token')
     data = {}
     if 'token' in req.args:
         data['token'] = req.args['token']
     return 'verify_email.html', data, None
예제 #2
0
    def _do_reset_password(self, req):
        if req.authname and req.authname != 'anonymous':
            return {'logged_in': True}
        if req.method != 'POST':
            return {}
        username = req.args.get('username')
        email = req.args.get('email')
        if not username:
            return {'error': 'Username is required'}
        if not email:
            return {'error': 'Email is required'}

        new_password = self._random_password()
        mgr = AccountManager(self.env)
        try:
            mgr._notify('password_reset', username, email, new_password)
        except Exception, e:
            return {'error': ','.join(e.args)}
예제 #3
0
    def post_process_request(self, req, template, data, content_type):
        if not req.session.authenticated:
            # Anonymous users should register and perms should be tweaked so
            # that anonymous users can't edit wiki pages and change or create
            # tickets. As such, this email verifying code won't be used on them
            return template, data, content_type

        email = req.session.get('email')
        # Only send verification if the user actually entered en email address.
        if email and email != req.session.get('email_verification_sent_to'):
            req.session['email_verification_token'] = self._gen_token()
            req.session['email_verification_sent_to'] = email
            mgr = AccountManager(self.env)
            mgr._notify(
                'email_verification_requested', 
                req.authname, 
                req.session['email_verification_token']
            )
            chrome.add_notice(req, Markup(tag.span(
                    'An email has been sent to ', email,
                    ' with a token to ',
                    tag.a(href=req.href.verify_email())(
                        'verify your new email address'))))
        return template, data, content_type