[opencms-dev] Add new User via Script

Armen Markarian markarian at inexweb.de
Thu Mar 11 16:14:01 CET 2004


Hi Steffen, i suggest that u did not set the Additional Info Hashtable!

Here my script: 

<%
	String filter	   		= "";
	String firstname      	= "";
	String lastname		   = "";
	String username			= "";
	String telefon				= "";
	String email          	= "";
	String adress				= "";
	String section				= "";
	String oldPWD		    	= "";
	String newPWD      		= "";
	String confirmPWD       = "";
	String status				= "";
	String pSearch				= "";
	String defaultUserGroup	= "Users";
	boolean lockStatus		= true;
	boolean dOK					= false;
	boolean mOK					= false;
	boolean cOK					= false;
	int type						= 0;
	boolean AlreadyExistsException 	= false;;
	String documentTitle					=
"Bestätigung";
	
	Hashtable additionalInfos			= new
Hashtable();
	
additionalInfos.put(I_CmsConstants.C_ADDITIONAL_INFO_TOWN,"Neuss");
	
additionalInfos.put(I_CmsConstants.C_ADDITIONAL_INFO_ZIPCODE,"41460");
	
	long lastlogin
= 0L;
	long lastused
= 0L;
	
%>

<%-- ************************** END DECLARATIONS
************************************ --%>      
<%   
  
	   // get request parameter	   
	   filter				=
request.getParameter("form_action");
		firstname      	=
request.getParameter("form_firstname");
	   lastname		  		=
request.getParameter("form_lastname");
	   username				=
request.getParameter("form_username");
	   telefon				=
request.getParameter("form_telefon");
	   email          	= request.getParameter("form_email");
	   oldPWD      		= request.getParameter("form_oldPWD");
	   newPWD      		= request.getParameter("form_newPWD");
	   confirmPWD       	=
request.getParameter("form_confirmPWD");
	   hotelIDs				=
request.getParameter("form_groupnames");
	   anz_gruppen			=
request.getParameter("form_anz_gruppen");
	   status				=
request.getParameter("form_status");
	   pSearch				=
request.getParameter("form_profile");
	   section				=
request.getParameter("form_usersection");
	   
	   
		
	   if(filter == null) 		filter = "";
	   if(firstname == null) 	firstname = "";
	   if(lastname == null) 	lastname = "";
	   if(username == null) 	username = "";
	   if(telefon == null) 		telefon = "";
	   if(email == null) 		email = "";
	   if(oldPWD == null) 		oldPWD = "";
	   if(newPWD == null) 		newPWD = "";
	   if(confirmPWD == null) 	confirmPWD = "";
	   if(status == null) 		status = "";
	   
	   if(status.equals("locked")) {
	   	lockStatus = true;
	   } else {
	   	lockStatus = false;
	   }
	   
	   if(filter.equals("deleteUser")) {
			
			/**
			 * delete User
			 */
			
			if(username!=null) {
				try
					{
					// delete User by given username
					cmsObj.deleteUser(username);
					dOK = true;
				}
				catch (Throwable t){
					....
				}
			}
		} 					
		
		if(filter.equals("createUser")) {
				
			// create User
			if(username!=null && !username.equals("")) {
				try
					{
					// create a new cms user
					CmsUser createdUser =
cmsObj.addImportUser(username,cmsObj.digest(newPWD),cmsObj.digest(confir
mPWD),telefon,firstname,lastname,email,0,additionalInfos,defaultUserGrou
p,adress,section,type);
	
cmsObj.addUserToGroup(username,"Projectmanager"); //optional
					
					
					
					
				}
				catch (Throwable t){
	
System.out.println("ADMIN-USERDATA-CHILD-RESULT (CREATE USER): " + t);
					String searchStr = "Duplicate
entry";
	
if(t.toString().indexOf(searchStr) != -1) {
						AlreadyExistsException =
true;
					}

				}
			} 			
		}
		
		if(filter.equals("modifyUser")) {
				
			// modify User
			try
				{
					CmsUser modifiedUser =
cmsObj.readUser(username);
	
modifiedUser.setFirstname(firstname);
	
modifiedUser.setLastname(lastname);
	
modifiedUser.setDescription(telefon);
					modifiedUser.setEmail(email);
					if(lockStatus) {
	
modifiedUser.setDisabled();						
					} else {
	
modifiedUser.setEnabled();
					}
					
					
					
					if (
(!newPWD.equals(""))&&(!confirmPWD.equals("")) ) {      
						try 
							{
	
cmsObj.setPassword(username,newPWD);

			   		}
			   		catch (Throwable t){
	
System.out.println("ADMIN-USERDATA-CHILD-RESULT (CHANGE PASSWD): " + t);
						} 
					}  
					
					cmsObj.writeUser(modifiedUser);
					mOK = true;
			}
			catch (Throwable t){
				...
			}
		}


Hope help :)

Regards

Armen




More information about the opencms-dev mailing list