view MoinMoin/script/account/ @ 1914:591c6df0f900

moint account_password: allow to invalidate a stored pw hash add test for pw hash invalidation set_password: giving an empty or None password means to invalidate the stored pw hash. added docstring.
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Sun, 20 Jan 2013 17:16:14 +0100
parents dbcadc76561a
children a2d2f4a93e0b
line wrap: on
line source
# Copyright: 2006-2013 MoinMoin:ThomasWaldmann
# Copyright: 2008 MoinMoin:JohannesBerg
# Copyright: 2011 MoinMoin:ReimarBauer
# License: GNU GPL v2 (or any later version), see LICENSE.txt for details.

MoinMoin - set a user password

from flask import current_app as app
from flask import g as flaskg
from flask.ext.script import Command, Option

from MoinMoin import user
from import before_wiki

class Set_Password(Command):
    description = 'This command allows you to set a user password.'
    option_list = (
        Option('--name', '-n', required=False, dest='name', type=unicode,
               help='Set password for the user with user name NAME.'),
        Option('--uid', '-u', required=False, dest='uid', type=unicode,
               help='Set password for the user with user id UID.'),
        Option('--password', '-p', required=False, dest='password', type=unicode,
               help='New password for this account.'),

    def run(self, name, uid, password):
        flags_given = name or uid
        if not flags_given:
            print 'incorrect number of arguments'
            import sys

        if uid:
            u = user.User(uid)
        elif name:
            u = user.User(auth_username=name)

        if not u.exists():
            print 'This user "{0!r}" does not exists!'.format(

        except (TypeError, ValueError) as err:
            print "Error: Password could not get processed, aborting."
            if password:
                print 'Password set.'
                print 'Password invalidated.'