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