# Path: omw/common_login.py
# def hash_pass(password):
#     """ Return the md5 hash of the password+salt """
#     salted_password = password + app.secret_key
#     return hashlib.md5(salted_password.encode('utf-8')).hexdigest()


import sys
import os
import argparse
import sqlite3
from getpass import getpass
from omw.common_login import hash_pass
parser = argparse.ArgumentParser()
parser.add_argument('db', help='path to the user database')
parser.add_argument('--user', help='username')
parser.add_argument('--name', help='real name')
parser.add_argument('--email', help='email address')
parser.add_argument('--level', type=int, default=0,
                    help='access level (default: 0)')
parser.add_argument('--group', choices=('common', 'admin'), default='common',
                    help='access group (common|admin)')
parser.add_argument('--affiliation', default='sys',
                    help="user's affiliation (default: sys)")
args = parser.parse_args()

if not os.path.isfile(args.db):
    sys.exit('no such database file: ' + str(args.db))

user = args.user
if user is None:
    user = input('Username: ')
assert user, 'A username must be specified.'

name = args.name
if name is None:
    name = input('Full name: ')

email = args.email
if email is None:
    email = input('Email: ')

# hash the password immediately

# Path: omw/common_login.py
# def hash_pass(password):
#     """ Return the md5 hash of the password+salt """
#     salted_password = password + app.secret_key
#     return hashlib.md5(salted_password.encode('utf-8')).hexdigest()


# Path: scripts/add-user.py
import sys
import os
import argparse
import sqlite3
from getpass import getpass
from omw.common_login import hash_pass

parser = argparse.ArgumentParser()
parser.add_argument('db', help='path to the user database')
parser.add_argument('--user', help='username')
parser.add_argument('--name', help='real name')
parser.add_argument('--email', help='email address')
parser.add_argument('--level', type=int, default=0,
                    help='access level (default: 0)')
parser.add_argument('--group', choices=('common', 'admin'), default='common',
                    help='access group (common|admin)')
parser.add_argument('--affiliation', default='sys',
                    help="user's affiliation (default: sys)")
args = parser.parse_args()

if not os.path.isfile(args.db):
    sys.exit('no such database file: ' + str(args.db))

user = args.user
if user is None:
    user = input('Username: ')
assert user, 'A username must be specified.'

name = args.name
if name is None:
    name = input('Full name: ')

email = args.email
if email is None:
    email = input('Email: ')

# hash the password immediately

pw = hash_pass(getpass('Password: '))