diff options
author | Daniel Schadt <kingdread@gmx.de> | 2023-06-19 20:18:37 +0200 |
---|---|---|
committer | Daniel Schadt <kingdread@gmx.de> | 2023-06-19 20:18:37 +0200 |
commit | 6a871bc794def553b54a58fc8314edd7a0ea57e0 (patch) | |
tree | bb20b620703c9598f23ec0cb7ca3e720ec2e5b37 | |
parent | 4ca35b938e6ccd07e47b04869fbe30e9109bcbe4 (diff) | |
download | fietsboek-6a871bc794def553b54a58fc8314edd7a0ea57e0.tar.gz fietsboek-6a871bc794def553b54a58fc8314edd7a0ea57e0.tar.bz2 fietsboek-6a871bc794def553b54a58fc8314edd7a0ea57e0.zip |
add fietsctl modify --set-email
-rw-r--r-- | doc/man/fietsctl.rst | 7 | ||||
-rw-r--r-- | fietsboek/scripts/fietsctl.py | 13 |
2 files changed, 19 insertions, 1 deletions
diff --git a/doc/man/fietsctl.rst b/doc/man/fietsctl.rst index 67cbed4..5319a42 100644 --- a/doc/man/fietsctl.rst +++ b/doc/man/fietsctl.rst @@ -130,7 +130,7 @@ MODIFYING USERS .. code-block:: text - fietsctl user modify [-c CONFIG] [-i/--id ID] [-e/--email EMAIL] [--admin/--no-admin] [--verified/--no-verified] + fietsctl user modify [-c CONFIG] [-i/--id ID] [-e/--email EMAIL] [--admin/--no-admin] [--verified/--no-verified] [--set-email EMAIL] Modifies a user. This can currently be used to set the admin and verification status of a user. If you want to change the password, use ``fietsctl user @@ -142,6 +142,11 @@ If you do not specifiy either ``--admin`` or ``--no-admin``, then the current value of the user is not changed. The same goes for ``--verified`` and ``--no-verified``, if neither is given, the current value is not changed. +To change a user's email address, you can specify the ``--set-email`` option +with the desired new email address. Note that — just like with adding users — +no email verification is taking place, so be careful when using this. The new +email address is automatically registered as verified. + CHANGING USER PASSWORDS ####################### diff --git a/fietsboek/scripts/fietsctl.py b/fietsboek/scripts/fietsctl.py index 59462df..3e987d5 100644 --- a/fietsboek/scripts/fietsctl.py +++ b/fietsboek/scripts/fietsctl.py @@ -8,6 +8,7 @@ from click_option_group import RequiredMutuallyExclusiveOptionGroup, optgroup from pyramid.paster import bootstrap, setup_logging from pyramid.scripting import AppEnvironment from sqlalchemy import select +from sqlalchemy.exc import NoResultFound from .. import __VERSION__, hittekaart, models, util from ..data import DataManager @@ -229,6 +230,7 @@ def cms_user_passwd( @config_option @click.option("--admin/--no-admin", help="Make the user an admin.", default=None) @click.option("--verified/--no-verified", help="Set the user verification status.", default=None) +@click.option("--set-email", help="Set the user's email address") @optgroup.group("User selection", cls=RequiredMutuallyExclusiveOptionGroup) @optgroup.option("--id", "-i", "id_", help="Database ID of the user.", type=int) @optgroup.option("--email", "-e", help="Email address of the user.") @@ -240,6 +242,7 @@ def cms_user_modify( verified: Optional[bool], id_: Optional[int], email: Optional[str], + set_email: Optional[str], ): """Modify a user.""" env = setup(config) @@ -258,6 +261,16 @@ def cms_user_modify( user.is_admin = admin if verified is not None: user.is_verified = verified + if set_email is not None: + # Try to ensure that the email is unique. We do have the constraint + # for that, but capitalization might screw us here. + try: + dbsession.execute(models.User.query_by_email(set_email)).scalar_one() + except NoResultFound: + user.email = set_email + else: + click.echo("Error: E-Mail already exists", err=True) + ctx.exit(EXIT_FAILURE) user_name = click.style(user.name, fg=FG_USER_NAME) user_email = click.style(user.email, fg=FG_USER_EMAIL) |