6
0
mirror of https://github.com/ChristianLight/tutor.git synced 2024-12-12 14:17:46 +00:00

Define a password from the CLI on user creation

Add a `-p/--password` option to `createuser` commands.
This commit is contained in:
Régis Behmo 2019-07-11 11:55:12 +08:00
parent 002d9edccc
commit d9a18790d3
5 changed files with 28 additions and 12 deletions

View File

@ -4,6 +4,7 @@ Note: Breaking changes between versions are indicated by "💥".
## Latest
- [Feature] Modify ``createuser`` commands to define a password from the command line
- [Improvement] Better yaml value parsing from command line
- [Feature] Add `dev exec` command
- [Bugfix] Fix incorrect notes settings definition

View File

@ -115,13 +115,20 @@ def init(root):
@opts.root
@click.option("--superuser", is_flag=True, help="Make superuser")
@click.option("--staff", is_flag=True, help="Make staff user")
@click.option(
"-p",
"--password",
help="Specify password from the command line. If undefined, you will be prompted to input a password",
)
@click.argument("name")
@click.argument("email")
def createuser(root, superuser, staff, name, email):
def createuser(root, superuser, staff, password, name, email):
config = tutor_config.load(root)
runner = K8sScriptRunner(root, config)
runner.check_service_is_activated("lms")
command = scripts.create_user_command(superuser, staff, name, email)
command = scripts.create_user_command(
superuser, staff, name, email, password=password
)
kubectl_exec(config, "lms", command, attach=True)

View File

@ -270,13 +270,20 @@ def logs(root, follow, tail, service):
@opts.root
@click.option("--superuser", is_flag=True, help="Make superuser")
@click.option("--staff", is_flag=True, help="Make staff user")
@click.option(
"-p",
"--password",
help="Specify password from the command line. If undefined, you will be prompted to input a password",
)
@click.argument("name")
@click.argument("email")
def createuser(root, superuser, staff, name, email):
def createuser(root, superuser, staff, password, name, email):
config = tutor_config.load(root)
runner = ScriptRunner(root, config)
runner.check_service_is_activated("lms")
command = scripts.create_user_command(superuser, staff, name, email)
command = scripts.create_user_command(
superuser, staff, name, email, password=password
)
runner.exec("lms", command)

View File

@ -58,17 +58,20 @@ def initialise(runner):
fmt.echo_info("All services initialised.")
def create_user_command(superuser, staff, username, email):
def create_user_command(superuser, staff, username, email, password=None):
opts = ""
if superuser:
opts += " --superuser"
if staff:
opts += " --staff"
command = (
"./manage.py lms --settings=tutor.production manage_user {opts} {username} {email}\n"
command = "./manage.py lms --settings=tutor.production manage_user {opts} {username} {email}\n"
if password:
command += "./manage.py lms --settings=tutor.production shell -c \"from django.contrib.auth import get_user_model; u = get_user_model().objects.get(username='{username}'); u.set_password('{password}'); u.save()\""
else:
command += (
"./manage.py lms --settings=tutor.production changepassword {username}"
).format(opts=opts, username=username, email=email)
return command
)
return command.format(opts=opts, username=username, email=email, password=password)
def import_demo_course(runner):

View File

@ -1,2 +0,0 @@
./manage.py lms --settings=tutor.production manage_user {{ OPTS }} {{ USERNAME }} {{ EMAIL }}
./manage.py lms --settings=tutor.production changepassword {{ USERNAME }}