Commit 1a6fdefd authored by Alan Marchiori's avatar Alan Marchiori
Browse files

fixed mongo uri quotes and added forgot password db

parent 4249cb1c
......@@ -15,7 +15,9 @@ def db():
def show():
"shows the db config data"
with config.UserConfig() as uc:
db = MongoClient(make_connect_str()).get_default_database()
s = make_connect_str()
debug('db connection string:', s)
db = MongoClient(s).get_default_database()
users = db.command({'usersInfo':1})
pprint(users)
......@@ -43,6 +45,26 @@ def add(username, role):
pprint(res)
echo('password: ', epass.decode())
@db.command()
@click.argument('username')
def forgot(username):
"reset (forgotten) password USERNAME to gradedb"
with config.UserConfig() as uc:
db = MongoClient(make_connect_str()).get_default_database()
pwd = make_password()
epass = encrypt_pass(pwd)
try:
res = db.command('updateUser', username, pwd=pwd)
except pymongo.errors.DuplicateKeyError as x:
error('failed --> ')
pprint(x)
return
echo('success --> ')
pprint(res)
echo('password: ', epass.decode())
@db.command()
@click.argument('username')
def rm(username):
......
......@@ -22,7 +22,7 @@ import os
import platform
import sys
__version__ = '2.1.1'
__version__ = '2.1.2'
__date__ = '2021-01-05T14:53:15.549387'
__user__ = 'cs206'
__host__ = 'linuxremote3.bucknell.edu'
......
......@@ -6,6 +6,8 @@ import binascii
import random
import string
import math
from config.echo import *
import urllib
def __extract_pass(secret):
# derive key
key = scrypt(config.crypto_pkey, salt=config.crypto_salt,
......@@ -34,10 +36,11 @@ def make_connect_str():
who = uc.cfg['gradedb_user']
else:
who = os.environ['USER']
debug("make_connect_str: user is '{}'".format(who))
if 'gradedb_pass' in uc.cfg:
return config.labtool_mongodb_format.format(
who,
__extract_pass(uc.cfg['gradedb_pass'])
urllib.parse.quote_plus(__extract_pass(uc.cfg['gradedb_pass']))
)
else:
return config.labtool_mongodb_format.format(
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment