Back to index

moin  1.9.0~rc2
resetpw.py
Go to the documentation of this file.
00001 # -*- coding: iso-8859-1 -*-
00002 """
00003 MoinMoin - disable a user account
00004 
00005 @copyright: 2006 MoinMoin:ThomasWaldmann,
00006             2008 MoinMoin:JohannesBerg
00007 @license: GNU GPL, see COPYING for details.
00008 """
00009 
00010 from MoinMoin.script import MoinScript
00011 
00012 class PluginScript(MoinScript):
00013     """\
00014 Purpose:
00015 ========
00016 This tool allows you to change a user password via a command line interface.
00017 
00018 Detailed Instructions:
00019 ======================
00020 General syntax: moin [options] account resetpw [newpw-options] newpassword
00021 
00022 [options] usually should be:
00023     --config-dir=/path/to/my/cfg/ --wiki-url=wiki.example.org/
00024 
00025 [newpw-options] see below:
00026     1. To change JohnSmith's password:
00027        moin ... account resetpw --name JohnSmith new-password
00028 
00029     2. To change the password for the UID '1198872910.78.56322':
00030        moin ... account resetpw --uid 1198872910.78.56322 new-password
00031 """
00032 
00033     def __init__(self, argv, def_values):
00034         MoinScript.__init__(self, argv, def_values)
00035         self.parser.add_option(
00036             "--uid", metavar="UID", dest="uid",
00037             help="Reset password for the user with user id UID."
00038         )
00039         self.parser.add_option(
00040             "--name", metavar="NAME", dest="uname",
00041             help="Reset password for the user with user name NAME."
00042         )
00043 
00044     def mainloop(self):
00045         # we don't expect non-option arguments
00046         if len(self.args) != 1:
00047             self.parser.error("no new password given")
00048         newpass = self.args[0]
00049 
00050         flags_given = self.options.uid or self.options.uname
00051         if not flags_given:
00052             self.parser.print_help()
00053             import sys
00054             sys.exit(1)
00055 
00056         self.init_request()
00057         request = self.request
00058 
00059         from MoinMoin import user
00060         if self.options.uid:
00061             u = user.User(request, self.options.uid)
00062         elif self.options.uname:
00063             u = user.User(request, None, self.options.uname)
00064 
00065         if not u.exists():
00066             print 'This user "%s" does not exists!' % u.name
00067             return
00068 
00069         u.enc_password = user.encodePassword(newpass)
00070         u.save()