Show More
@@ -38,7 +38,6 b' repos_name = etelko' | |||
|
38 | 38 | ################################################################################ |
|
39 | 39 | #set debug = false |
|
40 | 40 | |
|
41 | ||
|
42 | 41 | ################################ |
|
43 | 42 | ### LOGGING CONFIGURATION #### |
|
44 | 43 | ################################ |
@@ -91,5 +90,5 b' formatter = generic' | |||
|
91 | 90 | |
|
92 | 91 | [formatter_generic] |
|
93 | 92 | format = %(asctime)s,%(msecs)03d %(levelname)-5.5s [%(name)s] %(message)s |
|
94 | datefmt = %H:%M:%S | |
|
93 | datefmt = %Y-%m-%d %H:%M:%S | |
|
95 | 94 |
@@ -26,7 +26,7 b' port = 8001' | |||
|
26 | 26 | [app:main] |
|
27 | 27 | use = egg:pylons_app |
|
28 | 28 | full_stack = true |
|
29 |
static_files = |
|
|
29 | static_files = true | |
|
30 | 30 | lang=en |
|
31 | 31 | cache_dir = %(here)s/data |
|
32 | 32 | repos_name = etelko |
@@ -90,5 +90,5 b' formatter = generic' | |||
|
90 | 90 | |
|
91 | 91 | [formatter_generic] |
|
92 | 92 | format = %(asctime)s,%(msecs)03d %(levelname)-5.5s [%(name)s] %(message)s |
|
93 | datefmt = %H:%M:%S | |
|
93 | datefmt = %Y-%m-%d %H:%M:%S | |
|
94 | 94 |
@@ -52,7 +52,7 b' def make_app(global_conf, full_stack=Tru' | |||
|
52 | 52 | # 500 when debug is disabled) |
|
53 | 53 | if asbool(config['debug']): |
|
54 | 54 | #don't handle 404, since mercurial does it for us. |
|
55 | app = StatusCodeRedirect(app, [400, 401, 403]) | |
|
55 | app = StatusCodeRedirect(app, [400, 401, 403, 500]) | |
|
56 | 56 | else: |
|
57 | 57 | app = StatusCodeRedirect(app, [400, 401, 403, 500]) |
|
58 | 58 |
@@ -30,8 +30,7 b' class AdminController(BaseController):' | |||
|
30 | 30 | |
|
31 | 31 | try: |
|
32 | 32 | c.form_result = login_form.to_python(dict(request.params)) |
|
33 |
if auth.auth |
|
|
34 | c.form_result['username'] == 'admin': | |
|
33 | if auth.admin_auth(c.form_result['username'], c.form_result['password']): | |
|
35 | 34 | session['admin_user'] = True |
|
36 | 35 | session['admin_username'] = c.form_result['username'] |
|
37 | 36 | session.save() |
@@ -13,6 +13,28 b' def get_sqlite_conn_cur():' | |||
|
13 | 13 | cur = conn.cursor() |
|
14 | 14 | return conn, cur |
|
15 | 15 | |
|
16 | ||
|
17 | def admin_auth(username, password): | |
|
18 | conn, cur = get_sqlite_conn_cur() | |
|
19 | password_crypt = crypt.crypt(password, '6a') | |
|
20 | ||
|
21 | try: | |
|
22 | cur.execute("SELECT * FROM users WHERE username=?", (username,)) | |
|
23 | data = cur.fetchone() | |
|
24 | except sqlite3.OperationalError as e: | |
|
25 | data = None | |
|
26 | log.error(e) | |
|
27 | ||
|
28 | if data: | |
|
29 | if data[3]: | |
|
30 | if data[1] == username and data[2] == password_crypt and data[4]: | |
|
31 | log.info('user %s authenticated correctly', username) | |
|
32 | return True | |
|
33 | else: | |
|
34 | log.error('user %s is disabled', username) | |
|
35 | ||
|
36 | return False | |
|
37 | ||
|
16 | 38 | def authfunc(environ, username, password): |
|
17 | 39 | conn, cur = get_sqlite_conn_cur() |
|
18 | 40 | password_crypt = crypt.crypt(password, '6a') |
@@ -65,7 +87,8 b' def create_user_table():' | |||
|
65 | 87 | (id INTEGER PRIMARY KEY AUTOINCREMENT, |
|
66 | 88 | username TEXT, |
|
67 | 89 | password TEXT, |
|
68 |
active INTEGER |
|
|
90 | active INTEGER, | |
|
91 | admin INTEGER)''') | |
|
69 | 92 | log.info('creating table %s', 'user_logs') |
|
70 | 93 | cur.execute('''DROP TABLE IF EXISTS user_logs ''') |
|
71 | 94 | cur.execute('''CREATE TABLE user_logs |
@@ -80,14 +103,13 b' def create_user_table():' | |||
|
80 | 103 | |
|
81 | 104 | cur.close() |
|
82 | 105 | |
|
83 | def create_user(username, password): | |
|
106 | def create_user(username, password, admin=False): | |
|
84 | 107 | conn, cur = get_sqlite_conn_cur() |
|
85 | 108 | password_crypt = crypt.crypt(password, '6a') |
|
86 | cur_date = datetime.now() | |
|
87 | 109 | log.info('creating user %s', username) |
|
88 | 110 | try: |
|
89 | cur.execute('''INSERT INTO users values (?,?,?,?) ''', | |
|
90 | (None, username, password_crypt, 1,)) | |
|
111 | cur.execute('''INSERT INTO users values (?,?,?,?,?) ''', | |
|
112 | (None, username, password_crypt, 1, admin)) | |
|
91 | 113 | conn.commit() |
|
92 | 114 | except: |
|
93 | 115 | conn.rollback() |
@@ -95,7 +117,7 b' def create_user(username, password):' | |||
|
95 | 117 | |
|
96 | 118 | if __name__ == "__main__": |
|
97 | 119 | create_user_table() |
|
98 | create_user('marcink', 'qweqwe') | |
|
120 | create_user('marcink', 'qweqwe', True) | |
|
99 | 121 | create_user('lukaszd', 'qweqwe') |
|
100 | 122 | create_user('adriand', 'qweqwe') |
|
101 | 123 | create_user('radek', 'qweqwe') |
@@ -103,6 +125,5 b' if __name__ == "__main__":' | |||
|
103 | 125 | create_user('bart', 'qweqwe') |
|
104 | 126 | create_user('maho', 'qweqwe') |
|
105 | 127 | create_user('michalg', 'qweqwe') |
|
106 | create_user('admin', 'qwe123qwe') | |
|
107 | 128 | |
|
108 | 129 | #authfunc('', 'marcink', 'qweqwe') |
General Comments 0
You need to be logged in to leave comments.
Login now