Mercurial > kallithea
annotate rhodecode/controllers/login.py @ 4147:1c8f818787b3 rhodecode-2.2.5-gpl
old style: show the full link box on summary page - no overlap or truncation
author | Mads Kiilerich <madski@unity3d.com> |
---|---|
date | Wed, 02 Jul 2014 19:03:23 -0400 |
parents | ffd45b185016 |
children | 7e5f8c12a3fc |
rev | line source |
---|---|
861
fd2ea6ceadc8
updated docs on every controller
Marcin Kuzminski <marcin@python-works.com>
parents:
761
diff
changeset
|
1 # -*- coding: utf-8 -*- |
1206
a671db5bdd58
fixed license issue #149
Marcin Kuzminski <marcin@python-works.com>
parents:
1203
diff
changeset
|
2 # This program is free software: you can redistribute it and/or modify |
a671db5bdd58
fixed license issue #149
Marcin Kuzminski <marcin@python-works.com>
parents:
1203
diff
changeset
|
3 # it under the terms of the GNU General Public License as published by |
a671db5bdd58
fixed license issue #149
Marcin Kuzminski <marcin@python-works.com>
parents:
1203
diff
changeset
|
4 # the Free Software Foundation, either version 3 of the License, or |
a671db5bdd58
fixed license issue #149
Marcin Kuzminski <marcin@python-works.com>
parents:
1203
diff
changeset
|
5 # (at your option) any later version. |
1203
6832ef664673
source code cleanup: remove trailing white space, normalize file endings
Marcin Kuzminski <marcin@python-works.com>
parents:
1121
diff
changeset
|
6 # |
252
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
202
diff
changeset
|
7 # This program is distributed in the hope that it will be useful, |
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
202
diff
changeset
|
8 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
202
diff
changeset
|
9 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
202
diff
changeset
|
10 # GNU General Public License for more details. |
1203
6832ef664673
source code cleanup: remove trailing white space, normalize file endings
Marcin Kuzminski <marcin@python-works.com>
parents:
1121
diff
changeset
|
11 # |
252
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
202
diff
changeset
|
12 # You should have received a copy of the GNU General Public License |
1206
a671db5bdd58
fixed license issue #149
Marcin Kuzminski <marcin@python-works.com>
parents:
1203
diff
changeset
|
13 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4095
diff
changeset
|
14 """ |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4095
diff
changeset
|
15 rhodecode.controllers.login |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4095
diff
changeset
|
16 ~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4095
diff
changeset
|
17 |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4095
diff
changeset
|
18 Login controller for rhodeocode |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4095
diff
changeset
|
19 |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4095
diff
changeset
|
20 :created_on: Apr 22, 2010 |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4095
diff
changeset
|
21 :author: marcink |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4095
diff
changeset
|
22 :copyright: (c) 2013 RhodeCode GmbH. |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4095
diff
changeset
|
23 :license: GPLv3, see LICENSE for more details. |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4095
diff
changeset
|
24 """ |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4095
diff
changeset
|
25 |
417
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
363
diff
changeset
|
26 |
861
fd2ea6ceadc8
updated docs on every controller
Marcin Kuzminski <marcin@python-works.com>
parents:
761
diff
changeset
|
27 import logging |
fd2ea6ceadc8
updated docs on every controller
Marcin Kuzminski <marcin@python-works.com>
parents:
761
diff
changeset
|
28 import formencode |
2623
44678a64cfae
Use HttpFound response in login.
Marcin Kuzminski <marcin@python-works.com>
parents:
2045
diff
changeset
|
29 import datetime |
2678
04d2bcfbe7a6
security fix, inspired by django security
Marcin Kuzminski <marcin@python-works.com>
parents:
2623
diff
changeset
|
30 import urlparse |
861
fd2ea6ceadc8
updated docs on every controller
Marcin Kuzminski <marcin@python-works.com>
parents:
761
diff
changeset
|
31 |
363
98abf8953b87
Added user registration, changed login url schema, moved it into _admin/ for safety
Marcin Kuzminski <marcin@python-works.com>
parents:
360
diff
changeset
|
32 from formencode import htmlfill |
2623
44678a64cfae
Use HttpFound response in login.
Marcin Kuzminski <marcin@python-works.com>
parents:
2045
diff
changeset
|
33 from webob.exc import HTTPFound |
861
fd2ea6ceadc8
updated docs on every controller
Marcin Kuzminski <marcin@python-works.com>
parents:
761
diff
changeset
|
34 from pylons.i18n.translation import _ |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4095
diff
changeset
|
35 from pylons.controllers.util import redirect |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4095
diff
changeset
|
36 from pylons import request, session, tmpl_context as c, url |
861
fd2ea6ceadc8
updated docs on every controller
Marcin Kuzminski <marcin@python-works.com>
parents:
761
diff
changeset
|
37 |
fd2ea6ceadc8
updated docs on every controller
Marcin Kuzminski <marcin@python-works.com>
parents:
761
diff
changeset
|
38 import rhodecode.lib.helpers as h |
547
1e757ac98988
renamed project to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
474
diff
changeset
|
39 from rhodecode.lib.auth import AuthUser, HasPermissionAnyDecorator |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4095
diff
changeset
|
40 from rhodecode.lib.auth_modules import importplugin |
547
1e757ac98988
renamed project to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
474
diff
changeset
|
41 from rhodecode.lib.base import BaseController, render |
4074
3b136af34329
Added pre-create user hook.
Marcin Kuzminski <marcin@python-works.com>
parents:
3960
diff
changeset
|
42 from rhodecode.lib.exceptions import UserCreationError |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4095
diff
changeset
|
43 from rhodecode.model.db import User, RhodeCodeSetting |
547
1e757ac98988
renamed project to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
474
diff
changeset
|
44 from rhodecode.model.forms import LoginForm, RegisterForm, PasswordResetForm |
629
7e536d1af60d
Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents:
564
diff
changeset
|
45 from rhodecode.model.user import UserModel |
1731
31e6eb2fb4b2
implements #222 registration feedback
Marcin Kuzminski <marcin@python-works.com>
parents:
1718
diff
changeset
|
46 from rhodecode.model.meta import Session |
861
fd2ea6ceadc8
updated docs on every controller
Marcin Kuzminski <marcin@python-works.com>
parents:
761
diff
changeset
|
47 |
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
|
48 |
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
|
49 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
|
50 |
1212 | 51 |
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
|
52 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
|
53 |
202
3fd2af1ba5ea
updated logging in logout. Added before, on login page.
Marcin Kuzminski <marcin@python-works.com>
parents:
195
diff
changeset
|
54 def __before__(self): |
3fd2af1ba5ea
updated logging in logout. Added before, on login page.
Marcin Kuzminski <marcin@python-works.com>
parents:
195
diff
changeset
|
55 super(LoginController, self).__before__() |
3fd2af1ba5ea
updated logging in logout. Added before, on login page.
Marcin Kuzminski <marcin@python-works.com>
parents:
195
diff
changeset
|
56 |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4095
diff
changeset
|
57 def _store_user_in_session(self, username, remember=False): |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4095
diff
changeset
|
58 user = User.get_by_username(username, case_insensitive=True) |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4095
diff
changeset
|
59 auth_user = AuthUser(user.user_id) |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4095
diff
changeset
|
60 auth_user.set_authenticated() |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4095
diff
changeset
|
61 cs = auth_user.get_cookie_store() |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4095
diff
changeset
|
62 session['rhodecode_user'] = cs |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4095
diff
changeset
|
63 user.update_lastlogin() |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4095
diff
changeset
|
64 Session().commit() |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4095
diff
changeset
|
65 |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4095
diff
changeset
|
66 # If they want to be remembered, update the cookie |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4095
diff
changeset
|
67 if remember: |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4095
diff
changeset
|
68 _year = (datetime.datetime.now() + |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4095
diff
changeset
|
69 datetime.timedelta(seconds=60 * 60 * 24 * 365)) |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4095
diff
changeset
|
70 session._set_cookie_expires(_year) |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4095
diff
changeset
|
71 |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4095
diff
changeset
|
72 session.save() |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4095
diff
changeset
|
73 |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4095
diff
changeset
|
74 log.info('user %s is now authenticated and stored in ' |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4095
diff
changeset
|
75 'session, session attrs %s' % (username, cs)) |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4095
diff
changeset
|
76 |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4095
diff
changeset
|
77 # dumps session attrs back to cookie |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4095
diff
changeset
|
78 session._update_cookie_out() |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4095
diff
changeset
|
79 # we set new cookie |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4095
diff
changeset
|
80 headers = None |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4095
diff
changeset
|
81 if session.request['set_cookie']: |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4095
diff
changeset
|
82 # send set-cookie headers back to response to update cookie |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4095
diff
changeset
|
83 headers = [('Set-Cookie', session.request['cookie_out'])] |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4095
diff
changeset
|
84 return headers |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4095
diff
changeset
|
85 |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4095
diff
changeset
|
86 def _validate_came_from(self, came_from): |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4095
diff
changeset
|
87 if not came_from: |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4095
diff
changeset
|
88 return came_from |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4095
diff
changeset
|
89 |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4095
diff
changeset
|
90 parsed = urlparse.urlparse(came_from) |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4095
diff
changeset
|
91 server_parsed = urlparse.urlparse(url.current()) |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4095
diff
changeset
|
92 allowed_schemes = ['http', 'https'] |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4095
diff
changeset
|
93 if parsed.scheme and parsed.scheme not in allowed_schemes: |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4095
diff
changeset
|
94 log.error('Suspicious URL scheme detected %s for url %s' % |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4095
diff
changeset
|
95 (parsed.scheme, parsed)) |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4095
diff
changeset
|
96 came_from = url('home') |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4095
diff
changeset
|
97 elif server_parsed.netloc != parsed.netloc: |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4095
diff
changeset
|
98 log.error('Suspicious NETLOC detected %s for url %s server url ' |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4095
diff
changeset
|
99 'is: %s' % (parsed.netloc, parsed, server_parsed)) |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4095
diff
changeset
|
100 came_from = url('home') |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4095
diff
changeset
|
101 return came_from |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4095
diff
changeset
|
102 |
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
|
103 def index(self): |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4095
diff
changeset
|
104 _default_came_from = url('home') |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4095
diff
changeset
|
105 came_from = self._validate_came_from(request.GET.get('came_from')) |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4095
diff
changeset
|
106 c.came_from = came_from or _default_came_from |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4095
diff
changeset
|
107 |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4095
diff
changeset
|
108 not_default = self.rhodecode_user.username != User.DEFAULT_USER |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4095
diff
changeset
|
109 ip_allowed = self.rhodecode_user.ip_allowed |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4095
diff
changeset
|
110 |
1628
de71a4bde097
Some code cleanups and fixes
Marcin Kuzminski <marcin@python-works.com>
parents:
1530
diff
changeset
|
111 # redirect if already logged in |
3146
c5169e445fb8
Full IP restrictions enabled
Marcin Kuzminski <marcin@python-works.com>
parents:
2679
diff
changeset
|
112 if self.rhodecode_user.is_authenticated and not_default and ip_allowed: |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4095
diff
changeset
|
113 raise HTTPFound(location=c.came_from) |
636
ffd07396d315
Fixes for raw_id, needed for git
Marcin Kuzminski <marcin@python-works.com>
parents:
629
diff
changeset
|
114 |
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
|
115 if request.POST: |
1718
f78bee8eec78
reduce cookie size for better support of client side sessions
Marcin Kuzminski <marcin@python-works.com>
parents:
1628
diff
changeset
|
116 # import Login Form validator class |
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
|
117 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
|
118 try: |
2623
44678a64cfae
Use HttpFound response in login.
Marcin Kuzminski <marcin@python-works.com>
parents:
2045
diff
changeset
|
119 session.invalidate() |
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
|
120 c.form_result = login_form.to_python(dict(request.POST)) |
1628
de71a4bde097
Some code cleanups and fixes
Marcin Kuzminski <marcin@python-works.com>
parents:
1530
diff
changeset
|
121 # form checks for username/password, now we're authenticated |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4095
diff
changeset
|
122 headers = self._store_user_in_session( |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4095
diff
changeset
|
123 username=c.form_result['username'], |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4095
diff
changeset
|
124 remember=c.form_result['remember']) |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4095
diff
changeset
|
125 raise HTTPFound(location=c.came_from, headers=headers) |
564
ba7e24cd4786
refactor codes and setup for python 2.5
Marcin Kuzminski <marcin@python-works.com>
parents:
549
diff
changeset
|
126 except formencode.Invalid, errors: |
4095
b59568e929ef
fixed password refill in login form when wrong password was given
Marcin Kuzminski <marcin@python-works.com>
parents:
4074
diff
changeset
|
127 defaults = errors.value |
b59568e929ef
fixed password refill in login form when wrong password was given
Marcin Kuzminski <marcin@python-works.com>
parents:
4074
diff
changeset
|
128 # remove password from filling in form again |
b59568e929ef
fixed password refill in login form when wrong password was given
Marcin Kuzminski <marcin@python-works.com>
parents:
4074
diff
changeset
|
129 del defaults['password'] |
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
|
130 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
|
131 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
|
132 defaults=errors.value, |
360
db187729c40c
new style error display for login
Marcin Kuzminski <marcin@python-works.com>
parents:
252
diff
changeset
|
133 errors=errors.error_dict or {}, |
db187729c40c
new style error display for login
Marcin Kuzminski <marcin@python-works.com>
parents:
252
diff
changeset
|
134 prefix_error=False, |
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
|
135 encoding="UTF-8") |
4074
3b136af34329
Added pre-create user hook.
Marcin Kuzminski <marcin@python-works.com>
parents:
3960
diff
changeset
|
136 except UserCreationError, e: |
3b136af34329
Added pre-create user hook.
Marcin Kuzminski <marcin@python-works.com>
parents:
3960
diff
changeset
|
137 # container auth or other auth functions that create users on |
3b136af34329
Added pre-create user hook.
Marcin Kuzminski <marcin@python-works.com>
parents:
3960
diff
changeset
|
138 # the fly can throw this exception signaling that there's issue |
3b136af34329
Added pre-create user hook.
Marcin Kuzminski <marcin@python-works.com>
parents:
3960
diff
changeset
|
139 # with user creation, explanation should be provided in |
3b136af34329
Added pre-create user hook.
Marcin Kuzminski <marcin@python-works.com>
parents:
3960
diff
changeset
|
140 # Exception itself |
3b136af34329
Added pre-create user hook.
Marcin Kuzminski <marcin@python-works.com>
parents:
3960
diff
changeset
|
141 h.flash(e, 'error') |
636
ffd07396d315
Fixes for raw_id, needed for git
Marcin Kuzminski <marcin@python-works.com>
parents:
629
diff
changeset
|
142 |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4095
diff
changeset
|
143 # check if we use container plugin, and try to login using it. |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4095
diff
changeset
|
144 auth_plugins = RhodeCodeSetting.get_auth_plugins() |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4095
diff
changeset
|
145 if any((importplugin(name).is_container_auth for name in auth_plugins)): |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4095
diff
changeset
|
146 from rhodecode.lib import auth_modules |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4095
diff
changeset
|
147 try: |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4095
diff
changeset
|
148 auth_info = auth_modules.authenticate('', '', request.environ) |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4095
diff
changeset
|
149 except UserCreationError, e: |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4095
diff
changeset
|
150 log.error(e) |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4095
diff
changeset
|
151 h.flash(e, 'error') |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4095
diff
changeset
|
152 # render login, with flash message about limit |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4095
diff
changeset
|
153 return render('/login.html') |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4095
diff
changeset
|
154 |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4095
diff
changeset
|
155 if auth_info: |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4095
diff
changeset
|
156 headers = self._store_user_in_session(auth_info.get('username')) |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4095
diff
changeset
|
157 raise HTTPFound(location=c.came_from, headers=headers) |
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
|
158 return render('/login.html') |
636
ffd07396d315
Fixes for raw_id, needed for git
Marcin Kuzminski <marcin@python-works.com>
parents:
629
diff
changeset
|
159 |
474
a3d9d24acbec
Implemented password reset(forms/models/ tasks) and mailing tasks.
Marcin Kuzminski <marcin@python-works.com>
parents:
459
diff
changeset
|
160 @HasPermissionAnyDecorator('hg.admin', 'hg.register.auto_activate', |
442
d66a7fa7689b
moved loged in user propagation out of forms,
Marcin Kuzminski <marcin@python-works.com>
parents:
437
diff
changeset
|
161 'hg.register.manual_activate') |
363
98abf8953b87
Added user registration, changed login url schema, moved it into _admin/ for safety
Marcin Kuzminski <marcin@python-works.com>
parents:
360
diff
changeset
|
162 def register(self): |
3734
a8f520540ab0
New default permissions definition for user group create
Marcin Kuzminski <marcin@python-works.com>
parents:
3625
diff
changeset
|
163 c.auto_active = 'hg.register.auto_activate' in User.get_default_user()\ |
3370
fdb0f59b2189
fixes #762, LDAP and container created users are now activated based on
Marcin Kuzminski <marcin@python-works.com>
parents:
3146
diff
changeset
|
164 .AuthUser.permissions['global'] |
636
ffd07396d315
Fixes for raw_id, needed for git
Marcin Kuzminski <marcin@python-works.com>
parents:
629
diff
changeset
|
165 |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4095
diff
changeset
|
166 settings = RhodeCodeSetting.get_app_settings() |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4095
diff
changeset
|
167 captcha_private_key = settings.get('rhodecode_captcha_private_key') |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4095
diff
changeset
|
168 c.captcha_active = bool(captcha_private_key) |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4095
diff
changeset
|
169 c.captcha_public_key = settings.get('rhodecode_captcha_public_key') |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4095
diff
changeset
|
170 |
363
98abf8953b87
Added user registration, changed login url schema, moved it into _admin/ for safety
Marcin Kuzminski <marcin@python-works.com>
parents:
360
diff
changeset
|
171 if request.POST: |
98abf8953b87
Added user registration, changed login url schema, moved it into _admin/ for safety
Marcin Kuzminski <marcin@python-works.com>
parents:
360
diff
changeset
|
172 register_form = RegisterForm()() |
98abf8953b87
Added user registration, changed login url schema, moved it into _admin/ for safety
Marcin Kuzminski <marcin@python-works.com>
parents:
360
diff
changeset
|
173 try: |
98abf8953b87
Added user registration, changed login url schema, moved it into _admin/ for safety
Marcin Kuzminski <marcin@python-works.com>
parents:
360
diff
changeset
|
174 form_result = register_form.to_python(dict(request.POST)) |
417
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
363
diff
changeset
|
175 form_result['active'] = c.auto_active |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4095
diff
changeset
|
176 |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4095
diff
changeset
|
177 if c.captcha_active: |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4095
diff
changeset
|
178 from rhodecode.lib.recaptcha import submit |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4095
diff
changeset
|
179 response = submit(request.POST.get('recaptcha_challenge_field'), |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4095
diff
changeset
|
180 request.POST.get('recaptcha_response_field'), |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4095
diff
changeset
|
181 private_key=captcha_private_key, |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4095
diff
changeset
|
182 remoteip=self.ip_addr) |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4095
diff
changeset
|
183 if c.captcha_active and not response.is_valid: |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4095
diff
changeset
|
184 _value = form_result |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4095
diff
changeset
|
185 _msg = _('bad captcha') |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4095
diff
changeset
|
186 error_dict = {'recaptcha_field': _msg} |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4095
diff
changeset
|
187 raise formencode.Invalid(_msg, _value, None, |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4095
diff
changeset
|
188 error_dict=error_dict) |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4095
diff
changeset
|
189 |
1749
8ecc6b8229a5
commit less models
Marcin Kuzminski <marcin@python-works.com>
parents:
1731
diff
changeset
|
190 UserModel().create_registration(form_result) |
3370
fdb0f59b2189
fixes #762, LDAP and container created users are now activated based on
Marcin Kuzminski <marcin@python-works.com>
parents:
3146
diff
changeset
|
191 h.flash(_('You have successfully registered into RhodeCode'), |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4095
diff
changeset
|
192 category='success') |
2623
44678a64cfae
Use HttpFound response in login.
Marcin Kuzminski <marcin@python-works.com>
parents:
2045
diff
changeset
|
193 Session().commit() |
363
98abf8953b87
Added user registration, changed login url schema, moved it into _admin/ for safety
Marcin Kuzminski <marcin@python-works.com>
parents:
360
diff
changeset
|
194 return redirect(url('login_home')) |
636
ffd07396d315
Fixes for raw_id, needed for git
Marcin Kuzminski <marcin@python-works.com>
parents:
629
diff
changeset
|
195 |
564
ba7e24cd4786
refactor codes and setup for python 2.5
Marcin Kuzminski <marcin@python-works.com>
parents:
549
diff
changeset
|
196 except formencode.Invalid, errors: |
363
98abf8953b87
Added user registration, changed login url schema, moved it into _admin/ for safety
Marcin Kuzminski <marcin@python-works.com>
parents:
360
diff
changeset
|
197 return htmlfill.render( |
98abf8953b87
Added user registration, changed login url schema, moved it into _admin/ for safety
Marcin Kuzminski <marcin@python-works.com>
parents:
360
diff
changeset
|
198 render('/register.html'), |
98abf8953b87
Added user registration, changed login url schema, moved it into _admin/ for safety
Marcin Kuzminski <marcin@python-works.com>
parents:
360
diff
changeset
|
199 defaults=errors.value, |
98abf8953b87
Added user registration, changed login url schema, moved it into _admin/ for safety
Marcin Kuzminski <marcin@python-works.com>
parents:
360
diff
changeset
|
200 errors=errors.error_dict or {}, |
98abf8953b87
Added user registration, changed login url schema, moved it into _admin/ for safety
Marcin Kuzminski <marcin@python-works.com>
parents:
360
diff
changeset
|
201 prefix_error=False, |
98abf8953b87
Added user registration, changed login url schema, moved it into _admin/ for safety
Marcin Kuzminski <marcin@python-works.com>
parents:
360
diff
changeset
|
202 encoding="UTF-8") |
4074
3b136af34329
Added pre-create user hook.
Marcin Kuzminski <marcin@python-works.com>
parents:
3960
diff
changeset
|
203 except UserCreationError, e: |
3b136af34329
Added pre-create user hook.
Marcin Kuzminski <marcin@python-works.com>
parents:
3960
diff
changeset
|
204 # container auth or other auth functions that create users on |
3b136af34329
Added pre-create user hook.
Marcin Kuzminski <marcin@python-works.com>
parents:
3960
diff
changeset
|
205 # the fly can throw this exception signaling that there's issue |
3b136af34329
Added pre-create user hook.
Marcin Kuzminski <marcin@python-works.com>
parents:
3960
diff
changeset
|
206 # with user creation, explanation should be provided in |
3b136af34329
Added pre-create user hook.
Marcin Kuzminski <marcin@python-works.com>
parents:
3960
diff
changeset
|
207 # Exception itself |
3b136af34329
Added pre-create user hook.
Marcin Kuzminski <marcin@python-works.com>
parents:
3960
diff
changeset
|
208 h.flash(e, 'error') |
636
ffd07396d315
Fixes for raw_id, needed for git
Marcin Kuzminski <marcin@python-works.com>
parents:
629
diff
changeset
|
209 |
363
98abf8953b87
Added user registration, changed login url schema, moved it into _admin/ for safety
Marcin Kuzminski <marcin@python-works.com>
parents:
360
diff
changeset
|
210 return render('/register.html') |
474
a3d9d24acbec
Implemented password reset(forms/models/ tasks) and mailing tasks.
Marcin Kuzminski <marcin@python-works.com>
parents:
459
diff
changeset
|
211 |
a3d9d24acbec
Implemented password reset(forms/models/ tasks) and mailing tasks.
Marcin Kuzminski <marcin@python-works.com>
parents:
459
diff
changeset
|
212 def password_reset(self): |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4095
diff
changeset
|
213 settings = RhodeCodeSetting.get_app_settings() |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4095
diff
changeset
|
214 captcha_private_key = settings.get('rhodecode_captcha_private_key') |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4095
diff
changeset
|
215 c.captcha_active = bool(captcha_private_key) |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4095
diff
changeset
|
216 c.captcha_public_key = settings.get('rhodecode_captcha_public_key') |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4095
diff
changeset
|
217 |
474
a3d9d24acbec
Implemented password reset(forms/models/ tasks) and mailing tasks.
Marcin Kuzminski <marcin@python-works.com>
parents:
459
diff
changeset
|
218 if request.POST: |
a3d9d24acbec
Implemented password reset(forms/models/ tasks) and mailing tasks.
Marcin Kuzminski <marcin@python-works.com>
parents:
459
diff
changeset
|
219 password_reset_form = PasswordResetForm()() |
a3d9d24acbec
Implemented password reset(forms/models/ tasks) and mailing tasks.
Marcin Kuzminski <marcin@python-works.com>
parents:
459
diff
changeset
|
220 try: |
a3d9d24acbec
Implemented password reset(forms/models/ tasks) and mailing tasks.
Marcin Kuzminski <marcin@python-works.com>
parents:
459
diff
changeset
|
221 form_result = password_reset_form.to_python(dict(request.POST)) |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4095
diff
changeset
|
222 if c.captcha_active: |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4095
diff
changeset
|
223 from rhodecode.lib.recaptcha import submit |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4095
diff
changeset
|
224 response = submit(request.POST.get('recaptcha_challenge_field'), |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4095
diff
changeset
|
225 request.POST.get('recaptcha_response_field'), |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4095
diff
changeset
|
226 private_key=captcha_private_key, |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4095
diff
changeset
|
227 remoteip=self.ip_addr) |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4095
diff
changeset
|
228 if c.captcha_active and not response.is_valid: |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4095
diff
changeset
|
229 _value = form_result |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4095
diff
changeset
|
230 _msg = _('bad captcha') |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4095
diff
changeset
|
231 error_dict = {'recaptcha_field': _msg} |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4095
diff
changeset
|
232 raise formencode.Invalid(_msg, _value, None, |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4095
diff
changeset
|
233 error_dict=error_dict) |
1749
8ecc6b8229a5
commit less models
Marcin Kuzminski <marcin@python-works.com>
parents:
1731
diff
changeset
|
234 UserModel().reset_password_link(form_result) |
1417
5875955def39
fixes #223 improve password reset form
Marcin Kuzminski <marcin@python-works.com>
parents:
1400
diff
changeset
|
235 h.flash(_('Your password reset link was sent'), |
636
ffd07396d315
Fixes for raw_id, needed for git
Marcin Kuzminski <marcin@python-works.com>
parents:
629
diff
changeset
|
236 category='success') |
474
a3d9d24acbec
Implemented password reset(forms/models/ tasks) and mailing tasks.
Marcin Kuzminski <marcin@python-works.com>
parents:
459
diff
changeset
|
237 return redirect(url('login_home')) |
636
ffd07396d315
Fixes for raw_id, needed for git
Marcin Kuzminski <marcin@python-works.com>
parents:
629
diff
changeset
|
238 |
564
ba7e24cd4786
refactor codes and setup for python 2.5
Marcin Kuzminski <marcin@python-works.com>
parents:
549
diff
changeset
|
239 except formencode.Invalid, errors: |
474
a3d9d24acbec
Implemented password reset(forms/models/ tasks) and mailing tasks.
Marcin Kuzminski <marcin@python-works.com>
parents:
459
diff
changeset
|
240 return htmlfill.render( |
a3d9d24acbec
Implemented password reset(forms/models/ tasks) and mailing tasks.
Marcin Kuzminski <marcin@python-works.com>
parents:
459
diff
changeset
|
241 render('/password_reset.html'), |
a3d9d24acbec
Implemented password reset(forms/models/ tasks) and mailing tasks.
Marcin Kuzminski <marcin@python-works.com>
parents:
459
diff
changeset
|
242 defaults=errors.value, |
a3d9d24acbec
Implemented password reset(forms/models/ tasks) and mailing tasks.
Marcin Kuzminski <marcin@python-works.com>
parents:
459
diff
changeset
|
243 errors=errors.error_dict or {}, |
a3d9d24acbec
Implemented password reset(forms/models/ tasks) and mailing tasks.
Marcin Kuzminski <marcin@python-works.com>
parents:
459
diff
changeset
|
244 prefix_error=False, |
a3d9d24acbec
Implemented password reset(forms/models/ tasks) and mailing tasks.
Marcin Kuzminski <marcin@python-works.com>
parents:
459
diff
changeset
|
245 encoding="UTF-8") |
636
ffd07396d315
Fixes for raw_id, needed for git
Marcin Kuzminski <marcin@python-works.com>
parents:
629
diff
changeset
|
246 |
474
a3d9d24acbec
Implemented password reset(forms/models/ tasks) and mailing tasks.
Marcin Kuzminski <marcin@python-works.com>
parents:
459
diff
changeset
|
247 return render('/password_reset.html') |
636
ffd07396d315
Fixes for raw_id, needed for git
Marcin Kuzminski <marcin@python-works.com>
parents:
629
diff
changeset
|
248 |
1417
5875955def39
fixes #223 improve password reset form
Marcin Kuzminski <marcin@python-works.com>
parents:
1400
diff
changeset
|
249 def password_reset_confirmation(self): |
5875955def39
fixes #223 improve password reset form
Marcin Kuzminski <marcin@python-works.com>
parents:
1400
diff
changeset
|
250 if request.GET and request.GET.get('key'): |
5875955def39
fixes #223 improve password reset form
Marcin Kuzminski <marcin@python-works.com>
parents:
1400
diff
changeset
|
251 try: |
5875955def39
fixes #223 improve password reset form
Marcin Kuzminski <marcin@python-works.com>
parents:
1400
diff
changeset
|
252 user = User.get_by_api_key(request.GET.get('key')) |
5875955def39
fixes #223 improve password reset form
Marcin Kuzminski <marcin@python-works.com>
parents:
1400
diff
changeset
|
253 data = dict(email=user.email) |
1749
8ecc6b8229a5
commit less models
Marcin Kuzminski <marcin@python-works.com>
parents:
1731
diff
changeset
|
254 UserModel().reset_password(data) |
1417
5875955def39
fixes #223 improve password reset form
Marcin Kuzminski <marcin@python-works.com>
parents:
1400
diff
changeset
|
255 h.flash(_('Your password reset was successful, ' |
5875955def39
fixes #223 improve password reset form
Marcin Kuzminski <marcin@python-works.com>
parents:
1400
diff
changeset
|
256 'new password has been sent to your email'), |
5875955def39
fixes #223 improve password reset form
Marcin Kuzminski <marcin@python-works.com>
parents:
1400
diff
changeset
|
257 category='success') |
5875955def39
fixes #223 improve password reset form
Marcin Kuzminski <marcin@python-works.com>
parents:
1400
diff
changeset
|
258 except Exception, e: |
5875955def39
fixes #223 improve password reset form
Marcin Kuzminski <marcin@python-works.com>
parents:
1400
diff
changeset
|
259 log.error(e) |
5875955def39
fixes #223 improve password reset form
Marcin Kuzminski <marcin@python-works.com>
parents:
1400
diff
changeset
|
260 return redirect(url('reset_password')) |
5875955def39
fixes #223 improve password reset form
Marcin Kuzminski <marcin@python-works.com>
parents:
1400
diff
changeset
|
261 |
5875955def39
fixes #223 improve password reset form
Marcin Kuzminski <marcin@python-works.com>
parents:
1400
diff
changeset
|
262 return redirect(url('login_home')) |
5875955def39
fixes #223 improve password reset form
Marcin Kuzminski <marcin@python-works.com>
parents:
1400
diff
changeset
|
263 |
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
|
264 def logout(self): |
1802
145677a36675
Remember Me option on login
Matt Zuba <matt.zuba@goodwillaz.org>
parents:
1749
diff
changeset
|
265 session.delete() |
145677a36675
Remember Me option on login
Matt Zuba <matt.zuba@goodwillaz.org>
parents:
1749
diff
changeset
|
266 log.info('Logging out and deleting session for user') |
636
ffd07396d315
Fixes for raw_id, needed for git
Marcin Kuzminski <marcin@python-works.com>
parents:
629
diff
changeset
|
267 redirect(url('home')) |