From 616d40d225d10b7f6f6da882bbe65c9fe2befcf9 Mon Sep 17 00:00:00 2001 From: hoellen Date: Mon, 8 Jul 2019 10:35:59 +0200 Subject: [PATCH] Update password in commandline --- core/admin/mailu/manage.py | 20 ++++++++++++++++++++ docs/cli.rst | 9 +++++++++ towncrier/newsfragments/1066.feature | 1 + 3 files changed, 30 insertions(+) create mode 100644 towncrier/newsfragments/1066.feature diff --git a/core/admin/mailu/manage.py b/core/admin/mailu/manage.py index c39fc1b6..e113abfe 100644 --- a/core/admin/mailu/manage.py +++ b/core/admin/mailu/manage.py @@ -85,6 +85,26 @@ def user(localpart, domain_name, password, hash_scheme=None): db.session.commit() +@mailu.command() +@click.argument('localpart') +@click.argument('domain_name') +@click.argument('password') +@click.argument('hash_scheme', required=False) +@flask_cli.with_appcontext +def password(localpart, domain_name, password, hash_scheme=None): + """ Change the password of an user + """ + email = '{0}@{1}'.format(localpart, domain_name) + user = models.User.query.get(email) + if hash_scheme is None: + hash_scheme = app.config['PASSWORD_SCHEME'] + if user: + user.set_password(password, hash_scheme=hash_scheme) + else: + print("User " + email + " not found.") + db.session.commit() + + @mailu.command() @click.argument('domain_name') @click.option('-u', '--max-users') diff --git a/docs/cli.rst b/docs/cli.rst index bdd030f9..24ba22dd 100644 --- a/docs/cli.rst +++ b/docs/cli.rst @@ -6,6 +6,7 @@ Managing users and aliases can be done from CLI using commands: * alias * alias-delete * domain +* password * user * user-import * user-delete @@ -35,6 +36,14 @@ domain docker-compose exec admin flask mailu domain example.net +password +-------- + +.. code-block:: bash + + docker-compose exec admin flask mailu password myuser example.net 'password123' + + user ---- diff --git a/towncrier/newsfragments/1066.feature b/towncrier/newsfragments/1066.feature new file mode 100644 index 00000000..b9f5ea13 --- /dev/null +++ b/towncrier/newsfragments/1066.feature @@ -0,0 +1 @@ +Update user password in commandline