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