Webgui: filter and pagination working
This commit is contained in:
Executable
+51
@@ -0,0 +1,51 @@
|
||||
#!/usr/bin/python3
|
||||
|
||||
import os
|
||||
import sys
|
||||
import configparser
|
||||
from yms import database
|
||||
from getpass import getpass
|
||||
import bcrypt
|
||||
|
||||
cfg = {
|
||||
'cfgfile': '~/.config/ymsgui.conf',
|
||||
'host': 'localhost',
|
||||
'db': 'yms',
|
||||
'user': 'yms'
|
||||
}
|
||||
|
||||
def set_pass():
|
||||
newpass = getpass('New Password: ')
|
||||
cryptpass = bcrypt.hashpw(newpass.encode(), bcrypt.gensalt())
|
||||
print(cryptpass.decode())
|
||||
|
||||
sql = "UPDATE user SET pass=%s WHERE userid=%s"
|
||||
|
||||
def get_user():
|
||||
username = input('Username: ')
|
||||
sql = "SELECT userid FROM user WHERE login=%s"
|
||||
db.cur.execute(sql, (username,))
|
||||
row = db.cur.fetchone()
|
||||
if not row:
|
||||
print("User not found")
|
||||
return -1
|
||||
else:
|
||||
return row[0]
|
||||
|
||||
if __name__ == "__main__":
|
||||
config = configparser.ConfigParser()
|
||||
configfile = os.path.expanduser(cfg['cfgfile']);
|
||||
if not config.read(configfile):
|
||||
print(f"Configuration file '{configfile}' not found.")
|
||||
else:
|
||||
cfg['host'] = config.get('DB', 'host')
|
||||
cfg['db'] = config.get('DB', 'db')
|
||||
cfg['user'] = config.get('DB', 'user')
|
||||
cfg['pass'] = config.get('DB', 'pass')
|
||||
db = database.Database(cfg['host'], cfg['db'])
|
||||
if db.connect(cfg['user'], cfg['pass']):
|
||||
print("Connected to database")
|
||||
print(get_user())
|
||||
db.disconnect()
|
||||
else:
|
||||
print("Cannot connect to database {}@{}".format(cfg['db'], cfg['host']))
|
||||
Reference in New Issue
Block a user