Show More
@@ -1,6 +1,4 b'' | |||
|
1 | 1 | import logging |
|
2 | import os | |
|
3 | ||
|
4 | 2 | from pylons import request, response, session, tmpl_context as c, url, app_globals as g |
|
5 | 3 | from pylons.controllers.util import abort, redirect |
|
6 | 4 | from pylons_app.lib.base import BaseController, render |
@@ -1,12 +1,13 b'' | |||
|
1 | 1 | from pylons import request, response, session, tmpl_context as c, url, \ |
|
2 | 2 | app_globals as g |
|
3 | 3 | from pylons.controllers.util import abort, redirect |
|
4 | from pylons_app.lib.auth import LoginRequired | |
|
4 | 5 | from pylons_app.lib.base import BaseController, render |
|
6 | from pylons_app.lib.filters import clean_repo | |
|
5 | 7 | from pylons_app.lib.utils import check_repo, invalidate_cache |
|
6 | 8 | import logging |
|
7 | 9 | import os |
|
8 | 10 | import shutil |
|
9 | from pylons_app.lib.filters import clean_repo | |
|
10 | 11 | log = logging.getLogger(__name__) |
|
11 | 12 | |
|
12 | 13 | class ReposController(BaseController): |
@@ -14,7 +15,7 b' class ReposController(BaseController):' | |||
|
14 | 15 | # To properly map this controller, ensure your config/routing.py |
|
15 | 16 | # file has a resource setup: |
|
16 | 17 | # map.resource('repo', 'repos') |
|
17 | ||
|
18 | @LoginRequired() | |
|
18 | 19 | def __before__(self): |
|
19 | 20 | c.admin_user = session.get('admin_user') |
|
20 | 21 | c.admin_username = session.get('admin_username') |
@@ -1,12 +1,16 b'' | |||
|
1 | from formencode import htmlfill | |
|
2 | from pylons import request, response, session, tmpl_context as c, url, \ | |
|
3 | app_globals as g | |
|
4 | from pylons.controllers.util import abort, redirect | |
|
5 | from pylons_app.lib.auth import LoginRequired | |
|
6 | from pylons_app.lib.base import BaseController, render | |
|
7 | from pylons_app.model.db import User, UserLog | |
|
8 | from pylons_app.model.forms import UserForm | |
|
9 | from pylons_app.model.user_model import UserModel | |
|
10 | import formencode | |
|
1 | 11 | import logging |
|
2 | 12 | |
|
3 | from pylons import request, response, session, tmpl_context as c, url, app_globals as g | |
|
4 | from pylons.controllers.util import abort, redirect | |
|
5 | 13 | |
|
6 | from pylons_app.lib.base import BaseController, render | |
|
7 | from formencode import htmlfill | |
|
8 | from pylons_app.model.db import User, UserLog | |
|
9 | import crypt | |
|
10 | 14 | |
|
11 | 15 | log = logging.getLogger(__name__) |
|
12 | 16 | |
@@ -15,7 +19,7 b' class UsersController(BaseController):' | |||
|
15 | 19 | # To properly map this controller, ensure your config/routing.py |
|
16 | 20 | # file has a resource setup: |
|
17 | 21 | # map.resource('user', 'users') |
|
18 | ||
|
22 | @LoginRequired() | |
|
19 | 23 | def __before__(self): |
|
20 | 24 | c.admin_user = session.get('admin_user') |
|
21 | 25 | c.admin_username = session.get('admin_username') |
@@ -31,21 +35,20 b' class UsersController(BaseController):' | |||
|
31 | 35 | def create(self): |
|
32 | 36 | """POST /users: Create a new item""" |
|
33 | 37 | # url('users') |
|
34 | params = dict(request.params) | |
|
35 | ||
|
38 | ||
|
39 | user_model = UserModel() | |
|
40 | login_form = UserForm() | |
|
36 | 41 | try: |
|
37 | new_user = User() | |
|
38 | new_user.active = params.get('active', False) | |
|
39 | new_user.username = params.get('username') | |
|
40 | new_user.password = crypt.crypt(params.get('password'), '6a') | |
|
41 | new_user.admin = False | |
|
42 | self.sa.add(new_user) | |
|
43 | self.sa.commit() | |
|
44 | except: | |
|
45 | self.sa.rollback() | |
|
46 | raise | |
|
47 | ||
|
48 | return redirect(url('users')) | |
|
42 | form_result = login_form.to_python(dict(request.POST)) | |
|
43 | user_model.create(form_result) | |
|
44 | return redirect(url('users')) | |
|
45 | ||
|
46 | except formencode.Invalid as errors: | |
|
47 | c.form_errors = errors.error_dict | |
|
48 | return htmlfill.render( | |
|
49 | render('admin/users/user_add.html'), | |
|
50 | defaults=errors.value, | |
|
51 | encoding="UTF-8") | |
|
49 | 52 | |
|
50 | 53 | def new(self, format='html'): |
|
51 | 54 | """GET /users/new: Form to create a new item""" |
@@ -60,21 +63,21 b' class UsersController(BaseController):' | |||
|
60 | 63 | # h.form(url('user', id=ID), |
|
61 | 64 | # method='put') |
|
62 | 65 | # url('user', id=ID) |
|
63 | params = dict(request.params) | |
|
64 | ||
|
66 | user_model = UserModel() | |
|
67 | login_form = UserForm() | |
|
65 | 68 | try: |
|
66 | new_user = self.sa.query(User).get(id) | |
|
67 | new_user.active = params.get('active', False) | |
|
68 | new_user.username = params.get('username') | |
|
69 | if params.get('new_password'): | |
|
70 | new_user.password = crypt.crypt(params.get('new_password'), '6a') | |
|
71 | self.sa.add(new_user) | |
|
72 | self.sa.commit() | |
|
73 | except: | |
|
74 | self.sa.rollback() | |
|
75 | raise | |
|
76 | ||
|
77 | return redirect(url('users')) | |
|
69 | form_result = login_form.to_python(dict(request.POST)) | |
|
70 | user_model.update(id, form_result) | |
|
71 | return redirect(url('users')) | |
|
72 | ||
|
73 | except formencode.Invalid as errors: | |
|
74 | errors.value | |
|
75 | c.user = user_model.get_user(id) | |
|
76 | c.form_errors = errors.error_dict | |
|
77 | return htmlfill.render( | |
|
78 | render('admin/users/user_edit.html'), | |
|
79 | defaults=errors.value, | |
|
80 | encoding="UTF-8") | |
|
78 | 81 | |
|
79 | 82 | def delete(self, id): |
|
80 | 83 | """DELETE /users/id: Delete an existing item""" |
General Comments 0
You need to be logged in to leave comments.
Login now