~ubuntu-branches/ubuntu/vivid/trac-accountmanager/vivid

« back to all changes in this revision

Viewing changes to acct_mgr/web_ui.py

  • Committer: Bazaar Package Importer
  • Author(s): Leo Costela
  • Date: 2009-12-22 21:31:06 UTC
  • Revision ID: james.westby@ubuntu.com-20091222213106-o0ke99dpjn664na7
Tags: 0.2.1+r7163-1
* new upstream checkout
* convert to "3.0 (quilt)"
* debian/{control,rules}: migrate to python-support (closes: #555487)
* debian/{compat,control}: bump to dh 7
* debian/rules: replace dh_clean with dh_prep on build
* debian/patches: adapt to new upstream
* debian/watch: fix download mangle

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
from trac.web.main import IRequestHandler, IRequestFilter
25
25
from trac.web import chrome
26
26
from trac.web.chrome import INavigationContributor, ITemplateProvider
 
27
from genshi.core import Markup
27
28
from genshi.builder import tag
28
29
 
29
30
from api import AccountManager
205
206
        if req.authname and req.authname != 'anonymous':
206
207
            if req.session.get('force_change_passwd', False):
207
208
                redirect_url = req.href.prefs('account')
208
 
                if req.path_info != redirect_url:
 
209
                if req.href(req.path_info) != redirect_url:                
209
210
                    req.redirect(redirect_url)
210
211
        return (template, data, content_type)
211
212
 
239
240
                if force_change_password:
240
241
                    del(req.session['force_change_passwd'])
241
242
                    req.session.save()
242
 
                    chrome.add_notice(req, MessageWrapper(tag(
 
243
                    chrome.add_notice(req, Markup(tag(
243
244
                        "Thank you for taking the time to update your password."
244
245
                    )))
245
246
                    force_change_password = False
248
249
            else:
249
250
                data.update({'error': 'Invalid action'})
250
251
        if force_change_password:
251
 
            chrome.add_warning(req, MessageWrapper(tag(
 
252
            chrome.add_warning(req, Markup(tag(
252
253
                "You are required to change password because of a recent "
253
254
                "password change request. ",
254
255
                tag.b("Please change your password now."))))
507
508
        return [resource_filename(__name__, 'templates')]
508
509
 
509
510
 
510
 
class MessageWrapper(object):
511
 
    """Wrapper for add_warning and add_notice to work around the requirement
512
 
    for a % operator."""
513
 
    def __init__(self, body):
514
 
        self.body = body
515
 
 
516
 
    def __mod__(self, rhs):
517
 
        return self.body
518
 
 
519
 
 
520
511
class EmailVerificationNotification(SingleUserNofification):
521
512
    template_name = 'verify_email.txt'
522
513
 
549
540
            # tickets. As such, this email verifying code won't be used on them
550
541
            return handler
551
542
        if handler is not self and 'email_verification_token' in req.session:
552
 
            chrome.add_warning(req, MessageWrapper(tag.span(
 
543
            chrome.add_warning(req, Markup(tag.span(
553
544
                    'Your permissions have been limited until you ',
554
545
                    tag.a(href=req.href.verify_email())(
555
546
                          'verify your email address'))))
562
553
            # that anonymous users can't edit wiki pages and change or create
563
554
            # tickets. As such, this email verifying code won't be used on them
564
555
            return template, data, content_type
565
 
        if req.session.get('email') != req.session.get('email_verification_sent_to'):
 
556
 
 
557
        email = req.session.get('email')
 
558
        # Only send verification if the user actually entered en email address.
 
559
        if email and email != req.session.get('email_verification_sent_to'):
566
560
            req.session['email_verification_token'] = self._gen_token()
567
 
            req.session['email_verification_sent_to'] = req.session.get('email')
 
561
            req.session['email_verification_sent_to'] = email
568
562
            self._send_email(req)
569
 
            chrome.add_notice(req, MessageWrapper(tag.span(
570
 
                    'An email has been sent to ', req.session['email'],
 
563
            chrome.add_notice(req, Markup(tag.span(
 
564
                    'An email has been sent to ', email,
571
565
                    ' with a token to ',
572
566
                    tag.a(href=req.href.verify_email())(
573
567
                        'verify your new email address'))))