##// END OF EJS Templates
Added user registration, changed login url schema, moved it into _admin/ for safety
marcink -
r363:98abf895 default
parent child Browse files
Show More
@@ -77,6 +77,11 b' def make_map(config):'
77 m.connect('admin_add_repo', '/add_repo/{new_repo:[a-z0-9\. _-]*}',
77 m.connect('admin_add_repo', '/add_repo/{new_repo:[a-z0-9\. _-]*}',
78 action='add_repo')
78 action='add_repo')
79
79
80 #LOGIN/LOGOUT
81 map.connect('login_home', '/_admin/login', controller='login')
82 map.connect('logout_home', '/_admin/logout', controller='login', action='logout')
83 map.connect('register', '/_admin/register', controller='login', action='register')
84
80 #FEEDS
85 #FEEDS
81 map.connect('rss_feed_home', '/{repo_name:.*}/feed/rss',
86 map.connect('rss_feed_home', '/{repo_name:.*}/feed/rss',
82 controller='feed', action='rss',
87 controller='feed', action='rss',
@@ -85,9 +90,6 b' def make_map(config):'
85 controller='feed', action='atom',
90 controller='feed', action='atom',
86 conditions=dict(function=check_repo))
91 conditions=dict(function=check_repo))
87
92
88 #LOGIN/LOGOUT
89 map.connect('login_home', '/login', controller='login')
90 map.connect('logout_home', '/logout', controller='login', action='logout')
91
93
92 #OTHERS
94 #OTHERS
93 map.connect('changeset_home', '/{repo_name:.*}/changeset/{revision}',
95 map.connect('changeset_home', '/{repo_name:.*}/changeset/{revision}',
@@ -17,19 +17,20 b''
17 # along with this program; if not, write to the Free Software
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19 # MA 02110-1301, USA.
19 # MA 02110-1301, USA.
20 from formencode import htmlfill
21 from pylons import request, response, session, tmpl_context as c, url
22 from pylons.controllers.util import abort, redirect
23 from pylons_app.lib.auth import AuthUser
24 from pylons_app.lib.base import BaseController, render
25 from pylons_app.model.forms import LoginForm, RegisterForm
26 from pylons_app.model.user_model import UserModel
27 import formencode
28 import logging
20 """
29 """
21 Created on April 22, 2010
30 Created on April 22, 2010
22 login controller for pylons
31 login controller for pylons
23 @author: marcink
32 @author: marcink
24 """
33 """
25 import logging
26 from formencode import htmlfill
27 from pylons import request, response, session, tmpl_context as c, url
28 from pylons.controllers.util import abort, redirect
29 from pylons_app.lib.base import BaseController, render
30 import formencode
31 from pylons_app.model.forms import LoginForm
32 from pylons_app.lib.auth import AuthUser
33
34
34 log = logging.getLogger(__name__)
35 log = logging.getLogger(__name__)
35
36
@@ -60,6 +61,26 b' class LoginController(BaseController):'
60
61
61 return render('/login.html')
62 return render('/login.html')
62
63
64
65 def register(self):
66 if request.POST:
67 user_model = UserModel()
68 register_form = RegisterForm()()
69 try:
70 form_result = register_form.to_python(dict(request.POST))
71 user_model.create_registration(form_result)
72 return redirect(url('login_home'))
73
74 except formencode.Invalid as errors:
75 return htmlfill.render(
76 render('/register.html'),
77 defaults=errors.value,
78 errors=errors.error_dict or {},
79 prefix_error=False,
80 encoding="UTF-8")
81
82 return render('/register.html')
83
63 def logout(self):
84 def logout(self):
64 session['hg_app_user'] = AuthUser()
85 session['hg_app_user'] = AuthUser()
65 session.save()
86 session.save()
@@ -265,6 +265,9 b' def UserForm(edit=False, old_data={}):'
265
265
266 return _UserForm
266 return _UserForm
267
267
268 RegisterForm = UserForm
269
270
268 def RepoForm(edit=False, old_data={}):
271 def RepoForm(edit=False, old_data={}):
269 class _RepoForm(formencode.Schema):
272 class _RepoForm(formencode.Schema):
270 allow_extra_fields = True
273 allow_extra_fields = True
@@ -53,6 +53,21 b' class UserModel(object):'
53 self.sa.rollback()
53 self.sa.rollback()
54 raise
54 raise
55
55
56 def create_registration(self, form_data):
57 try:
58 new_user = User()
59 for k, v in form_data.items():
60 if k != 'admin' or k != 'active':
61 setattr(new_user, k, v)
62 setattr(new_user, 'active', True)
63
64 self.sa.add(new_user)
65 self.sa.commit()
66 except Exception as e:
67 log.error(e)
68 self.sa.rollback()
69 raise
70
56 def update(self, id, form_data):
71 def update(self, id, form_data):
57 try:
72 try:
58 new_user = self.sa.query(User).get(id)
73 new_user = self.sa.query(User).get(id)
General Comments 0
You need to be logged in to leave comments. Login now