1 package org.nemesis.forum.webapp.admin.action; 2 3 import java.util.Iterator ; 4 5 import javax.servlet.http.HttpServletRequest ; 6 import javax.servlet.http.HttpServletResponse ; 7 8 import org.apache.commons.beanutils.PropertyUtils; 9 import org.apache.commons.logging.Log; 10 import org.apache.commons.logging.LogFactory; 11 import org.apache.struts.action.ActionError; 12 import org.apache.struts.action.ActionErrors; 13 import org.apache.struts.action.ActionForm; 14 import org.apache.struts.action.ActionForward; 15 import org.apache.struts.action.ActionMapping; 16 import org.nemesis.forum.ForumFactory; 17 import org.nemesis.forum.ProfileManager; 18 import org.nemesis.forum.User; 19 import org.nemesis.forum.exception.AlreadyExistsException; 20 import org.nemesis.forum.exception.UnauthorizedException; 21 import org.nemesis.forum.webapp.admin.bean.UserBean; 22 23 29 public class AddUserAction extends BaseAction { 30 31 static protected Log log = LogFactory.getLog(AddUserAction.class); 32 33 public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { 34 35 checkUser(request); 37 checkPermission(request, OperationConstants.ADD_USER); 39 40 ActionErrors errors = new ActionErrors(); 41 if (isCancelled(request)) { 43 return (mapping.findForward("cancel")); 44 45 } 46 47 try { 48 49 ForumFactory forumFactory = ForumFactory.getInstance(getAuthToken(request)); 50 ProfileManager manager = forumFactory.getProfileManager(); 51 User user = manager.getUser(getAuthToken(request).getUserID()); 52 try { 53 UserBean ub = (UserBean) PropertyUtils.getProperty(form, "userBean"); 54 User u = manager.createUser(ub.getUserName(), ub.getPassword(), ub.getEmail()); 55 u.setEmailVisible(ub.isEmailVisible()); 56 u.setName(ub.getName()); 57 u.setNameVisible(ub.isNameVisible()); 58 59 String temp = null; 61 for (Iterator it = ub.getProperties().keySet().iterator(); it.hasNext();) { 62 temp = (String ) it.next(); 63 u.setProperty(temp, (String ) ub.getProperties().get(temp)); 64 } 65 66 } catch (AlreadyExistsException aee) { 67 errors.add("general", new ActionError("addUser.alreadyExist")); 68 } catch (UnauthorizedException aee) { 69 errors.add("general", new ActionError("addUser.unauthorized")); 70 return mapping.findForward("cancel"); 71 } 72 73 } catch (Exception e) { 74 String eid = this.getClass().getName() + "_" + System.currentTimeMillis(); 75 log.error("eid:" + eid + "\nsessionID" + request.getSession().getId(), e); 76 errors.add("general", new ActionError("error.general", "erreur id:" + eid)); 77 } 78 79 if (!errors.isEmpty()) { 80 saveErrors(request, errors); 81 return (mapping.getInputForward()); 82 } 83 84 return mapping.findForward("success"); 85 } 86 87 } | Popular Tags |