auth/newuser.py
Go to the documentation of this file.
1 #! /usr/bin/env python
2 
3 """
4 usage: %(progname)s username
5 """
6 
7 
8 import nstart
9 import os, sys, string, time, getopt
10 
11 from pyclearsilver.log import *
12 
13 import config
14 
15 from pyclearsilver import odb, hdfhelp, odb_sqlite3
16 from pyclearsilver import CSPage
17 
18 from pyclearsilver.odb import *
19 import db_auth
20 
21 def createuser(db, username, password, role=""):
22  row = db.users.new(username, password)
23  row.role = role
24  row.changePassword = 1
25  row.save()
26 
27 
28 def usage(progname):
29  print __doc__ % vars()
30 
31 def main(argv, stdout, environ):
32  progname = argv[0]
33  optlist, args = getopt.getopt(argv[1:], "", ["help", "test", "debug", "admin"])
34 
35  testflag = 0
36  if len(args) not in (1, 2):
37  usage(progname)
38  return
39 
40  role = ""
41 
42  for (field, val) in optlist:
43  if field == "--help":
44  usage(progname)
45  return
46  elif field == "--debug":
47  debugfull()
48  elif field == "--test":
49  testflag = 1
50  elif field == "--admin":
51  role = "admin"
52 
53  if testflag:
54  test()
55  return
56 
57  db = db_auth.initSchema(create=0)
58 
59  username = args[0]
60 
61  if len(args) > 1:
62  password1 = args[1]
63  print "---------------"
64  print "Creating new user:"
65  print " Username: %s" % username
66  print " Password: %s" % password1
67  print "You will be asked to change this password the first time you log in to the web interface."
68  else:
69  import getpass
70 
71  print "New User: %s" % username
72  print "---------------------------"
73  print
74  while 1:
75  print "Please enter a password:"
76  password1 = getpass.getpass("Password 1:")
77  password2 = getpass.getpass("Password 2:")
78  if password1 != password2:
79  print "password mismatch."
80  continue
81  else:
82  break
83 
84  user = createuser(db, username, password1, role=role)
85 
86 
87 
88 
89 if __name__ == "__main__":
90  main(sys.argv, sys.stdout, os.environ)
91 
92 
93 
def main(argv, stdout, environ)
Definition: auth/newuser.py:31
def usage(progname)
Definition: auth/newuser.py:28
def createuser(db, username, password, role="")
Definition: auth/newuser.py:21


webui
Author(s): Scott Hassan
autogenerated on Mon Jun 10 2019 15:51:24