##// END OF EJS Templates
added db_manage script
Marcin Kuzminski -
r59:73607890 default
parent child Browse files
Show More
@@ -0,0 +1,52
1 import logging
2 import sqlite3
3 log = logging.getLogger(__name__)
4 import os
5 import crypt
6 from os.path import dirname as dn
7 ROOT = dn(dn(dn(os.path.realpath(__file__))))
8
9 def get_sqlite_conn_cur():
10 conn = sqlite3.connect(os.path.join(ROOT, 'auth.sqlite'))
11 cur = conn.cursor()
12 return conn, cur
13
14 def create_user_table():
15 """
16 Create a auth database
17 """
18 conn, cur = get_sqlite_conn_cur()
19 try:
20 log.info('creating table %s', 'users')
21 cur.execute("""DROP TABLE IF EXISTS users """)
22 cur.execute("""CREATE TABLE users
23 (user_id INTEGER PRIMARY KEY AUTOINCREMENT,
24 username TEXT,
25 password TEXT,
26 active INTEGER,
27 admin INTEGER)""")
28 log.info('creating table %s', 'user_logs')
29 cur.execute("""DROP TABLE IF EXISTS user_logs """)
30 cur.execute("""CREATE TABLE user_logs
31 (id INTEGER PRIMARY KEY AUTOINCREMENT,
32 user_id INTEGER,
33 last_action TEXT,
34 last_action_date DATETIME)""")
35 conn.commit()
36 except:
37 conn.rollback()
38 raise
39
40 cur.close()
41
42 def create_user(username, password, admin=False):
43 conn, cur = get_sqlite_conn_cur()
44 password_crypt = crypt.crypt(password, '6a')
45 log.info('creating user %s', username)
46 try:
47 cur.execute("""INSERT INTO users values (?,?,?,?,?) """,
48 (None, username, password_crypt, 1, admin))
49 conn.commit()
50 except:
51 conn.rollback()
52 raise
General Comments 0
You need to be logged in to leave comments. Login now