newuser.py
Go to the documentation of this file.
00001 #! /usr/bin/env python
00002 
00003 """
00004 usage: %(progname)s username
00005 """
00006 
00007 
00008 import nstart
00009 import os, sys, string, time, getopt
00010 
00011 from pyclearsilver.log import *
00012 
00013 import config
00014 
00015 from pyclearsilver import odb, hdfhelp, odb_sqlite3
00016 from pyclearsilver import CSPage
00017 
00018 from pyclearsilver.odb import *
00019 import db_auth
00020 
00021 def createuser(db, username, password, role=""):
00022   row = db.users.new(username, password)
00023   row.role = role
00024   row.changePassword = 1
00025   row.save()
00026 
00027 
00028 def usage(progname):
00029   print __doc__ % vars()
00030 
00031 def main(argv, stdout, environ):
00032   progname = argv[0]
00033   optlist, args = getopt.getopt(argv[1:], "", ["help", "test", "debug", "admin"])
00034 
00035   testflag = 0
00036   if len(args) not in (1, 2):
00037     usage(progname)
00038     return
00039 
00040   role = ""
00041 
00042   for (field, val) in optlist:
00043     if field == "--help":
00044       usage(progname)
00045       return
00046     elif field == "--debug":
00047       debugfull()
00048     elif field == "--test":
00049       testflag = 1
00050     elif field == "--admin":
00051       role = "admin"
00052 
00053   if testflag:
00054     test()
00055     return
00056 
00057   db = db_auth.initSchema(create=0)
00058 
00059   username = args[0]
00060   
00061   if len(args) > 1:
00062     password1 = args[1]
00063     print "---------------"
00064     print "Creating new user:"
00065     print "  Username: %s" % username
00066     print "  Password: %s" % password1
00067     print "You will be asked to change this password the first time you log in to the web interface."
00068   else:
00069     import getpass
00070 
00071     print "New User: %s" % username
00072     print "---------------------------"
00073     print 
00074     while 1:
00075       print "Please enter a password:"
00076       password1 = getpass.getpass("Password 1:")
00077       password2 = getpass.getpass("Password 2:")
00078       if password1 != password2:
00079         print "password mismatch."
00080         continue
00081       else:
00082         break
00083 
00084   user = createuser(db, username, password1, role=role)
00085     
00086 
00087 
00088 
00089 if __name__ == "__main__":
00090   main(sys.argv, sys.stdout, os.environ)
00091 
00092   
00093   


webui
Author(s): Scott Hassan/hassan@willowgarage.com
autogenerated on Wed Apr 23 2014 10:36:00