📄 cmsadminusers.java
字号:
/*
* File : $Source: /usr/local/cvs/opencms/src-modules/com/opencms/workplace/CmsAdminUsers.java,v $
* Date : $Date: 2006/03/27 14:52:36 $
* Version: $Revision: 1.7 $
*
* This library is part of OpenCms -
* the Open Source Content Mananagement System
*
* Copyright (C) 2001 The OpenCms Group
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* For further information about OpenCms, please see the
* OpenCms Website: http://www.opencms.org
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package com.opencms.workplace;
import org.opencms.db.CmsUserSettings;
import org.opencms.file.CmsGroup;
import org.opencms.file.CmsObject;
import org.opencms.file.CmsRequestContext;
import org.opencms.file.CmsUser;
import org.opencms.main.CmsException;
import org.opencms.main.CmsLog;
import org.opencms.main.OpenCms;
import com.opencms.core.I_CmsSession;
import com.opencms.legacy.CmsLegacyException;
import com.opencms.legacy.CmsLegacySecurityException;
import com.opencms.legacy.CmsXmlTemplateLoader;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.List;
import java.util.Vector;
/**
* Template class for displaying OpenCms workplace admin users screens.
* <P>
*
* @author Mario Stanke
* @version $Revision: 1.7 $ $Date: 2006/03/27 14:52:36 $
* @see com.opencms.workplace.CmsXmlWpTemplateFile
*
* @deprecated Will not be supported past the OpenCms 6 release.
*/
public class CmsAdminUsers extends CmsWorkplaceDefault {
/**
* change the groups of the user
* <P>
* the Vector newGroups holds all groups, which theUser will be in afterwards
* the amount of database access is kept small with this funcion
* @param cms CmsObject Object for accessing system resources.
* @param theUser the user whose data will be changed
* @param newGroups Vector of Strings with the names of the new groups of theUser
* @throws CmsException
*/
private void changeGroups(CmsObject cms, CmsUser theUser, Vector newGroups) throws CmsException {
String username = theUser.getName();
List oldGroups = cms.getGroupsOfUser(username);
List oldGroupnames = new Vector();
cms.writeUser(theUser); // update in the database
theUser = cms.readUser(username);
if(oldGroups != null) {
for(int z = 0;z < oldGroups.size();z++) {
oldGroupnames.add(((CmsGroup)oldGroups.get(z)).getName());
}
// delete the user from the groups which are not in newGroups
for(int z = 0;z < oldGroupnames.size();z++) {
String groupname = (String)oldGroupnames.get(z);
if(!newGroups.contains(groupname)) {
try {
cms.removeUserFromGroup(username, groupname);
}catch(CmsException e) {
// can happen when this group has been deleted _indirectly_ before
}
}
}
}
if(newGroups != null) {
// now add the user to the new groups, which he not yet belongs to
for(int z = 0;z < newGroups.size();z++) {
String groupname = (String)newGroups.elementAt(z);
if(!cms.userInGroup(username, groupname)) {
cms.addUserToGroup(username, groupname);
}
}
}
cms.writeUser(theUser); // update in the database
theUser = cms.readUser(username);
}
/**
* Gets the content of a defined section in a given template file and its subtemplates
* with the given parameters.
*
* @see #getContent(CmsObject, String, String, Hashtable, String)
* @param cms CmsObject Object for accessing system resources.
* @param templateFile Filename of the template file.
* @param elementName Element name of this template in our parent template.
* @param parameters Hashtable with all template class parameters.
* @param templateSelector template section that should be processed.
*/
public byte[] getContent(CmsObject cms, String templateFile, String elementName,
Hashtable parameters, String templateSelector) throws CmsException {
if(CmsLog.getLog(this).isDebugEnabled() && C_DEBUG) {
CmsLog.getLog(this).debug("Getting content of element " + ((elementName==null)?"<root>":elementName));
CmsLog.getLog(this).debug("Template file is: " + templateFile);
CmsLog.getLog(this).debug("Selected template section is: " + ((templateSelector==null)?"<default>":templateSelector));
}
I_CmsSession session = CmsXmlTemplateLoader.getSession(cms.getRequestContext(), true);
CmsRequestContext reqCont = cms.getRequestContext();
CmsXmlWpTemplateFile xmlTemplateDocument = new CmsXmlWpTemplateFile(cms, templateFile);
boolean userYetChanged = true;
boolean userYetEstablished = true;
// find out which template (=perspective) should be used
String perspective = (String)parameters.get("perspective");
if(perspective != null && perspective.equals("user")) {
session.removeValue("ERROR");
if(CmsXmlTemplateLoader.getRequest(reqCont).getParameter("CHANGE") != null) {
// change data of selected user
perspective = "changeuser";
userYetChanged = false;
}else {
if(CmsXmlTemplateLoader.getRequest(reqCont).getParameter("DELETE") != null) {
// delete the selected user
perspective = "deleteuser";
}else {
if(CmsXmlTemplateLoader.getRequest(reqCont).getParameter("NEW") != null) {
// establish a new user
perspective = "newuser";
userYetEstablished = false;
}
}
}
}
if(perspective == null) {
// display the first template, which lets you chose the action
perspective = new String("user");
}
if(perspective.equals("newuser") || perspective.equals("changeuser")) {
// first the common part of the two actions:
// read the common parameters like first name, description, ...
String firstname, desc, street, pwd, pwd2, user, userLastname, town, zipcode,
email, defaultGroup;
if(session.getValue("ERROR") == null) {
firstname = (String)parameters.get("USERFIRSTNAME");
desc = (String)parameters.get("USERDESC");
street = (String)parameters.get("USERSTREET");
pwd = (String)parameters.get("PWD");
pwd2 = (String)parameters.get("PWD2");
user = (String)parameters.get("USER");
userLastname = (String)parameters.get("USERNAME");
town = (String)parameters.get("TOWN");
zipcode = (String)parameters.get("ZIP");
email = (String)parameters.get("USEREMAIL");
defaultGroup = (String)parameters.get("DEFAULTGROUP");
}else {
// an error has occurred before, retrieve the form data from the session
firstname = (String)session.getValue("USERFIRSTNAME");
desc = (String)session.getValue("USERDESC");
street = (String)session.getValue("USERSTREET");
pwd = (String)session.getValue("PWD");
pwd2 = (String)session.getValue("PWD2");
user = (String)session.getValue("USER");
userLastname = (String)session.getValue("USERNAME");
town = (String)session.getValue("TOWN");
zipcode = (String)session.getValue("ZIP");
email = (String)session.getValue("USEREMAIL");
defaultGroup = (String)session.getValue("DEFAULTGROUP");
session.removeValue("ERROR");
}
if(firstname == null) {
firstname = "";
}
if(desc == null) {
desc = "";
}
if(street == null) {
street = "";
}
if(pwd == null) {
pwd = "";
}
if(pwd2 == null) {
pwd2 = "";
}
if(user == null) {
user = "";
}
if(userLastname == null) {
userLastname = "";
}
if(town == null) {
town = "";
}
if(zipcode == null) {
zipcode = "";
}
if(email == null) {
email = "";
}
if(defaultGroup == null) {
defaultGroup = "";
}
// vectors of Strings that hold the selected and not selected Groups
Vector selectedGroups = (Vector)session.getValue("selectedGroups");
Vector notSelectedGroups = (Vector)session.getValue("notSelectedGroups");
if(perspective.equals("newuser")) {
// input is the form for establishing new users
templateSelector = "newuser";
if(!userYetEstablished) {
// first time the form is visited
user = "";
selectedGroups = new Vector();
notSelectedGroups = new Vector();
selectedGroups.addElement(OpenCms.getDefaultUsers().getGroupUsers()); // preselect Users
List groups = cms.getGroups();
for(int z = 0;z < groups.size();z++) {
String aName = ((CmsGroup)groups.get(z)).getName();
if(!OpenCms.getDefaultUsers().getGroupUsers().equals(aName)) {
notSelectedGroups.addElement(aName);
}
}
session.putValue("selectedGroups", selectedGroups);
session.putValue("notSelectedGroups", notSelectedGroups);
}
if(CmsXmlTemplateLoader.getRequest(reqCont).getParameter("ADD") != null) {
// add a new group to selectedGroups
String groupname = (String)parameters.get("notselectgroup");
if(groupname != null) {
selectedGroups.addElement(groupname);
notSelectedGroups.removeElement(groupname);
}
session.putValue("selectedGroups", selectedGroups);
session.putValue("notSelectedGroups", notSelectedGroups);
}else {
if(CmsXmlTemplateLoader.getRequest(reqCont).getParameter("REMOVE") != null) {
// delete a new group from selectedGroups
// and move it to notSelectedGroups
String groupname = (String)parameters.get("selectgroup");
if(groupname != null) {
notSelectedGroups.addElement(groupname);
selectedGroups.removeElement(groupname);
if(groupname.equals(defaultGroup)) {
defaultGroup = "";
}
}
session.putValue("selectedGroups", selectedGroups);
session.putValue("notSelectedGroups", notSelectedGroups);
}else {
if(CmsXmlTemplateLoader.getRequest(reqCont).getParameter("OK") != null) {
// form submitted, try to establish new user
try {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -