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