Workout With Friends Stay fit with a little motivation

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Properties
account.py
Go to the documentation of this file.
1 from __future__ import unicode_literals
2 from pyramid.httpexceptions import HTTPFound
3 from pyramid.view import view_config, view_defaults
4 from wowf.forms import ChangePasswordForm, ResetPasswordForm, State, UpdateProfileForm
5 from wowf.lib.auth import Auth
6 from wowf.views import BaseView
7
8
9 @view_defaults(route_name='account.profile', permission='member')
10 class UpdateProfileView(BaseView):
11
12 @view_config(renderer='account/profile.html')
13 def main(self):
14 form = UpdateProfileForm(
15 self.request.POST, obj=self.request.user, state=State(id=self.request.user.id))
16 if 'update_profile' in self.request.POST and form.validate():
17 form.update_profile(self.request.user)
18 self.request.session.flash('Profile saved successfully.', self.consts.SUCCESS)
19 return HTTPFound(location=self.request.path)
20 return dict(form=form)
21
22
23 @view_defaults(route_name='account.password', permission='member')
24 class ChangePasswordView(BaseView):
25
26 @view_config(renderer='account/password.html')
27 def main(self):
28 form = ChangePasswordForm(
29 self.request.POST, state=State(password=self.request.user.password))
30 if 'change_password' in self.request.POST and form.validate():
31 form.update_password(self.request.user)
32 self.request.session.flash('Password saved successfully.', self.consts.SUCCESS)
33 return HTTPFound(location=self.request.path)
34 return dict(form=form)
35
36
37 @view_defaults(route_name='account.password.request', permission='guest')
38 class RequestPasswordView(BaseView):
39
40 @view_config(renderer='account/request_password.html')
41 def main(self):
42 form = ResetPasswordForm(self.request.POST)
43 if 'reset_password' in self.request.POST and form.validate():
44 form.request_reset_password()
45 self.request.session.flash('Check your email for further instructions.', self.consts.NOTICE)
46 return HTTPFound(location=self.request.path)
47 return dict(form=form)
48
49
50 @view_defaults(route_name='account.password.reset', permission='guest')
51 class ResetPasswordView(BaseView):
52
53 @view_config()
54 def main(self):
55 token = self.request.matchdict['token']
56 if Auth.reset_password(token):
57 self.request.session.flash('Check your email for a temporary password.', self.consts.NOTICE)
58 return HTTPFound(location=self.request.route_url(
59 'user.login', _query={'return_to': self.request.route_url('account.password')}))
60 else:
61 self.request.session.flash('The token provided was either invalid or expired. Please try again.', self.consts.ERROR)
62 return HTTPFound(location=self.request.route_url('account.password.request'))
63