]> asedeno.scripts.mit.edu Git - bluechips.git/blob - bluechips/controllers/user.py
added XSRF protection to all forms and associated tests
[bluechips.git] / bluechips / controllers / user.py
1 """
2 Calculate the current state of the books
3 """
4
5 import logging
6
7 from bluechips.lib.base import *
8
9 import sqlalchemy
10 from sqlalchemy import orm
11
12 from pylons import request
13 from pylons.decorators import validate
14 from pylons.decorators.secure import authenticate_form
15
16 from formencode import validators, Schema
17
18 log = logging.getLogger(__name__)
19
20
21 class EmailSchema(Schema):
22     "Validate email updates."
23     allow_extra_fields = False
24     new_email = validators.Email()
25
26
27 class UserController(BaseController):
28     def index(self):
29         c.title = 'User Settings'
30         return render('/user/index.mako')
31
32     @authenticate_form
33     @validate(schema=EmailSchema(), form='index')
34     def update(self):
35         new_email = self.form_result['new_email']
36         request.environ['user'].email = new_email
37         meta.Session.commit()
38         if new_email is None:
39             h.flash("Removed email address.")
40         else:
41             h.flash("Updated email address to '%s'." % new_email)
42         return h.redirect_to('/')