Show More
@@ -1,38 +1,42 b'' | |||||
1 | import logging |
|
1 | import logging | |
2 | from formencode import htmlfill |
|
2 | from formencode import htmlfill | |
3 | from pylons import request, response, session, tmpl_context as c, url |
|
3 | from pylons import request, response, session, tmpl_context as c, url | |
4 | from pylons.controllers.util import abort, redirect |
|
4 | from pylons.controllers.util import abort, redirect | |
5 | from pylons_app.lib.base import BaseController, render |
|
5 | from pylons_app.lib.base import BaseController, render | |
6 | import formencode |
|
6 | import formencode | |
7 | from pylons_app.model.forms import LoginForm |
|
7 | from pylons_app.model.forms import LoginForm | |
8 | from pylons_app.lib.auth import AuthUser |
|
8 | from pylons_app.lib.auth import AuthUser | |
9 |
|
9 | |||
10 | log = logging.getLogger(__name__) |
|
10 | log = logging.getLogger(__name__) | |
11 |
|
11 | |||
12 | class LoginController(BaseController): |
|
12 | class LoginController(BaseController): | |
13 |
|
13 | |||
|
14 | def __before__(self): | |||
|
15 | super(LoginController, self).__before__() | |||
|
16 | ||||
14 | def index(self): |
|
17 | def index(self): | |
15 | #redirect if already logged in |
|
18 | #redirect if already logged in | |
16 | if c.hg_app_user.is_authenticated: |
|
19 | if c.hg_app_user.is_authenticated: | |
17 | return redirect(url('hg_home')) |
|
20 | return redirect(url('hg_home')) | |
18 |
|
21 | |||
19 | if request.POST: |
|
22 | if request.POST: | |
20 | #import Login Form validator class |
|
23 | #import Login Form validator class | |
21 | login_form = LoginForm() |
|
24 | login_form = LoginForm() | |
22 | try: |
|
25 | try: | |
23 | c.form_result = login_form.to_python(dict(request.POST)) |
|
26 | c.form_result = login_form.to_python(dict(request.POST)) | |
24 | return redirect(url('hg_home')) |
|
27 | return redirect(url('hg_home')) | |
25 |
|
28 | |||
26 | except formencode.Invalid as errors: |
|
29 | except formencode.Invalid as errors: | |
27 | c.form_errors = errors.error_dict |
|
30 | c.form_errors = errors.error_dict | |
28 | return htmlfill.render( |
|
31 | return htmlfill.render( | |
29 | render('/login.html'), |
|
32 | render('/login.html'), | |
30 | defaults=errors.value, |
|
33 | defaults=errors.value, | |
31 | encoding="UTF-8") |
|
34 | encoding="UTF-8") | |
32 |
|
35 | |||
33 | return render('/login.html') |
|
36 | return render('/login.html') | |
34 |
|
37 | |||
35 | def logout(self): |
|
38 | def logout(self): | |
36 | session['hg_app_user'] = AuthUser() |
|
39 | session['hg_app_user'] = AuthUser() | |
37 | session.save() |
|
40 | session.save() | |
|
41 | log.info('Logging out and setting user as Empty') | |||
38 | redirect(url('hg_home')) |
|
42 | redirect(url('hg_home')) |
General Comments 0
You need to be logged in to leave comments.
Login now