annotate pylons_app/controllers/login.py @ 195:7109d15c6813

cleared prints leftoovers, and changed current user fetching in login controller
author Marcin Kuzminski <marcin@python-works.com>
date Sat, 22 May 2010 16:07:28 +0200
parents 556473ba0399
children 3fd2af1ba5ea
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
186
556473ba0399 fixed menu in home page, and added login html with forms that validates username and password.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1 import logging
556473ba0399 fixed menu in home page, and added login html with forms that validates username and password.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2 from formencode import htmlfill
556473ba0399 fixed menu in home page, and added login html with forms that validates username and password.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
3 from pylons import request, response, session, tmpl_context as c, url
556473ba0399 fixed menu in home page, and added login html with forms that validates username and password.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
4 from pylons.controllers.util import abort, redirect
556473ba0399 fixed menu in home page, and added login html with forms that validates username and password.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
5 from pylons_app.lib.base import BaseController, render
556473ba0399 fixed menu in home page, and added login html with forms that validates username and password.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
6 import formencode
556473ba0399 fixed menu in home page, and added login html with forms that validates username and password.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
7 from pylons_app.model.forms import LoginForm
556473ba0399 fixed menu in home page, and added login html with forms that validates username and password.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
8 from pylons_app.lib.auth import AuthUser
556473ba0399 fixed menu in home page, and added login html with forms that validates username and password.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
9
556473ba0399 fixed menu in home page, and added login html with forms that validates username and password.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
10 log = logging.getLogger(__name__)
556473ba0399 fixed menu in home page, and added login html with forms that validates username and password.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
11
556473ba0399 fixed menu in home page, and added login html with forms that validates username and password.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
12 class LoginController(BaseController):
556473ba0399 fixed menu in home page, and added login html with forms that validates username and password.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
13
556473ba0399 fixed menu in home page, and added login html with forms that validates username and password.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
14 def index(self):
195
7109d15c6813 cleared prints leftoovers, and changed current user fetching in login controller
Marcin Kuzminski <marcin@python-works.com>
parents: 186
diff changeset
15 #redirect if already logged in
7109d15c6813 cleared prints leftoovers, and changed current user fetching in login controller
Marcin Kuzminski <marcin@python-works.com>
parents: 186
diff changeset
16 if c.hg_app_user.is_authenticated:
186
556473ba0399 fixed menu in home page, and added login html with forms that validates username and password.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
17 return redirect(url('hg_home'))
556473ba0399 fixed menu in home page, and added login html with forms that validates username and password.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
18
556473ba0399 fixed menu in home page, and added login html with forms that validates username and password.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
19 if request.POST:
556473ba0399 fixed menu in home page, and added login html with forms that validates username and password.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
20 #import Login Form validator class
556473ba0399 fixed menu in home page, and added login html with forms that validates username and password.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
21 login_form = LoginForm()
556473ba0399 fixed menu in home page, and added login html with forms that validates username and password.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
22 try:
556473ba0399 fixed menu in home page, and added login html with forms that validates username and password.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
23 c.form_result = login_form.to_python(dict(request.POST))
556473ba0399 fixed menu in home page, and added login html with forms that validates username and password.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
24 return redirect(url('hg_home'))
556473ba0399 fixed menu in home page, and added login html with forms that validates username and password.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
25
556473ba0399 fixed menu in home page, and added login html with forms that validates username and password.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
26 except formencode.Invalid as errors:
556473ba0399 fixed menu in home page, and added login html with forms that validates username and password.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
27 c.form_errors = errors.error_dict
556473ba0399 fixed menu in home page, and added login html with forms that validates username and password.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
28 return htmlfill.render(
556473ba0399 fixed menu in home page, and added login html with forms that validates username and password.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
29 render('/login.html'),
556473ba0399 fixed menu in home page, and added login html with forms that validates username and password.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
30 defaults=errors.value,
556473ba0399 fixed menu in home page, and added login html with forms that validates username and password.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
31 encoding="UTF-8")
556473ba0399 fixed menu in home page, and added login html with forms that validates username and password.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
32
556473ba0399 fixed menu in home page, and added login html with forms that validates username and password.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
33 return render('/login.html')
556473ba0399 fixed menu in home page, and added login html with forms that validates username and password.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
34
556473ba0399 fixed menu in home page, and added login html with forms that validates username and password.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
35 def logout(self):
556473ba0399 fixed menu in home page, and added login html with forms that validates username and password.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
36 session['hg_app_user'] = AuthUser()
556473ba0399 fixed menu in home page, and added login html with forms that validates username and password.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
37 session.save()
556473ba0399 fixed menu in home page, and added login html with forms that validates username and password.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
38 redirect(url('hg_home'))