newuser.py
Go to the documentation of this file.
00001 #! /usr/bin/env python
00002 
00003 """
00004 usage: %(progname)s [args]
00005 """
00006 
00007 import nstart
00008 
00009 import os, sys, string, time, getopt, re
00010 from pyclearsilver.log import *
00011 
00012 import neo_cgi, neo_util, neo_cs
00013 
00014 from pyclearsilver import CSPage
00015 from pyclearsilver import odb
00016 
00017 import MBPage
00018 import db_webui
00019 
00020 import roslib
00021 import roslib.scriptutil
00022 #import rospy
00023 import webutil
00024 
00025 class MyPage(MBPage.MBPage):
00026   def setup(self, hdf):
00027     self.db = db_webui.initSchema()
00028     
00029   def display(self, hdf):
00030     webutil.set_tabs(hdf, ["admin", "users"])
00031 
00032   def Action_CreateUser(self, hdf):
00033     # load params from request
00034     username = hdf.getValue("Query.username", "").strip()
00035     password = hdf.getValue("Query.password", "").strip()
00036     role = hdf.getValue("Query.role", "").strip()
00037     
00038     # check some error conditions
00039     if self.authdb.users.lookup(username=username):
00040       hdf.setValue("CGI.cur.error_message.username", "User %s already exists." % username)
00041     if len(username) < 3:
00042       hdf.setValue("CGI.cur.error_message.username", "Please specify a user name (3 or more characters).")
00043     if len(password) < 3:
00044       hdf.setValue("CGI.cur.error_message.password", "Please specify a password (3 or more characters).")   
00045     if hdf.getObj("CGI.cur.error_message"):
00046       return
00047       
00048     # save the new user record
00049     try:
00050       row = self.authdb.users.newRow()
00051       row.username = hdf.getValue("Query.username", "")
00052       new_password = hdf.getValue("Query.password", "")
00053       row.setPassword(new_password)
00054       row.role = hdf.getValue("Query.role", "")
00055       row.save()
00056     except:
00057       hdf.setValue("CGI.cur.error_message.password", "There was an error when trying to save this user.")
00058     
00059     self.redirectUri("users.py")
00060     
00061 def run(context):
00062   return MyPage(context, pagename="newuser", nologin=False)
00063 
00064 def main():
00065   context = CSPage.Context()
00066   run(context).start()
00067 
00068 if __name__ == "__main__":
00069   main()


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