diff --git a/pylons_app/config/routing.py b/pylons_app/config/routing.py --- a/pylons_app/config/routing.py +++ b/pylons_app/config/routing.py @@ -77,6 +77,11 @@ def make_map(config): m.connect('admin_add_repo', '/add_repo/{new_repo:[a-z0-9\. _-]*}', action='add_repo') + #LOGIN/LOGOUT + map.connect('login_home', '/_admin/login', controller='login') + map.connect('logout_home', '/_admin/logout', controller='login', action='logout') + map.connect('register', '/_admin/register', controller='login', action='register') + #FEEDS map.connect('rss_feed_home', '/{repo_name:.*}/feed/rss', controller='feed', action='rss', @@ -85,9 +90,6 @@ def make_map(config): controller='feed', action='atom', conditions=dict(function=check_repo)) - #LOGIN/LOGOUT - map.connect('login_home', '/login', controller='login') - map.connect('logout_home', '/logout', controller='login', action='logout') #OTHERS map.connect('changeset_home', '/{repo_name:.*}/changeset/{revision}', diff --git a/pylons_app/controllers/login.py b/pylons_app/controllers/login.py --- a/pylons_app/controllers/login.py +++ b/pylons_app/controllers/login.py @@ -17,19 +17,20 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, # MA 02110-1301, USA. +from formencode import htmlfill +from pylons import request, response, session, tmpl_context as c, url +from pylons.controllers.util import abort, redirect +from pylons_app.lib.auth import AuthUser +from pylons_app.lib.base import BaseController, render +from pylons_app.model.forms import LoginForm, RegisterForm +from pylons_app.model.user_model import UserModel +import formencode +import logging """ Created on April 22, 2010 login controller for pylons @author: marcink """ -import logging -from formencode import htmlfill -from pylons import request, response, session, tmpl_context as c, url -from pylons.controllers.util import abort, redirect -from pylons_app.lib.base import BaseController, render -import formencode -from pylons_app.model.forms import LoginForm -from pylons_app.lib.auth import AuthUser log = logging.getLogger(__name__) @@ -60,6 +61,26 @@ class LoginController(BaseController): return render('/login.html') + + def register(self): + if request.POST: + user_model = UserModel() + register_form = RegisterForm()() + try: + form_result = register_form.to_python(dict(request.POST)) + user_model.create_registration(form_result) + return redirect(url('login_home')) + + except formencode.Invalid as errors: + return htmlfill.render( + render('/register.html'), + defaults=errors.value, + errors=errors.error_dict or {}, + prefix_error=False, + encoding="UTF-8") + + return render('/register.html') + def logout(self): session['hg_app_user'] = AuthUser() session.save() diff --git a/pylons_app/model/forms.py b/pylons_app/model/forms.py --- a/pylons_app/model/forms.py +++ b/pylons_app/model/forms.py @@ -265,6 +265,9 @@ def UserForm(edit=False, old_data={}): return _UserForm +RegisterForm = UserForm + + def RepoForm(edit=False, old_data={}): class _RepoForm(formencode.Schema): allow_extra_fields = True diff --git a/pylons_app/model/user_model.py b/pylons_app/model/user_model.py --- a/pylons_app/model/user_model.py +++ b/pylons_app/model/user_model.py @@ -53,6 +53,21 @@ class UserModel(object): self.sa.rollback() raise + def create_registration(self, form_data): + try: + new_user = User() + for k, v in form_data.items(): + if k != 'admin' or k != 'active': + setattr(new_user, k, v) + setattr(new_user, 'active', True) + + self.sa.add(new_user) + self.sa.commit() + except Exception as e: + log.error(e) + self.sa.rollback() + raise + def update(self, id, form_data): try: new_user = self.sa.query(User).get(id)