1 package org.nextime.ion.backoffice.action.security; 2 3 import java.io.IOException ; 4 import javax.servlet.ServletException ; 5 import javax.servlet.http.HttpServletRequest ; 6 import javax.servlet.http.HttpServletResponse ; 7 8 import org.apache.struts.action.ActionErrors; 9 import org.apache.struts.action.ActionForm; 10 import org.apache.struts.action.ActionForward; 11 import org.apache.struts.action.ActionMapping; 12 import org.nextime.ion.backoffice.action.BaseAction; 13 import org.nextime.ion.backoffice.form.EditUserForm; 14 15 import org.nextime.ion.framework.business.User; 16 import org.nextime.ion.framework.mapping.Mapping; 17 18 public class EditMyProfileAction extends BaseAction { 19 20 public ActionForward perform( 21 ActionMapping mapping, 22 ActionForm form, 23 HttpServletRequest request, 24 HttpServletResponse response) 25 throws IOException , ServletException { 26 27 checkUser(request); 29 30 EditUserForm sform = (EditUserForm) form; 32 ActionErrors errors = sform.myValidate(request); 33 34 if (request.getParameter("cancel") != null) { 36 return (mapping.findForward("cancel")); 38 } 39 40 String id = request.getSession().getAttribute("userLogin")+""; 42 43 if (sform.getName() == null) { 45 try { 46 Mapping.begin(); 47 User user = User.getInstance(id); 48 Mapping.rollback(); 49 50 sform.setEmail((String )user.getMetaData("email")); 51 sform.setName((String )user.getMetaData("name")); 52 sform.setGroups(user.getGroupsIds()); 53 sform.setPassword(user.getPassword()); 54 55 } catch (Exception e) { 56 Mapping.rollback(); 57 throw new ServletException (e); 58 } 59 60 return (mapping.findForward("view")); 62 } 63 64 if (errors.size() > 0) { 66 try { 67 request.setAttribute(ERROR_KEY, errors); 68 69 } catch (Exception e) { 70 Mapping.rollback(); 71 throw new ServletException (e); 72 } 73 74 return (mapping.findForward("view")); 76 } 77 78 try { 80 Mapping.begin(); 81 User user = User.getInstance(id); 82 user.setMetaData("name", sform.getName()); 83 user.setMetaData("email", sform.getEmail()); 84 user.setPassword(sform.getPassword()); 85 Mapping.commit(); 86 87 } catch (Exception e) { 88 Mapping.rollback(); 89 throw new ServletException (e); 90 } 91 92 return (mapping.findForward("ok")); 94 } 95 96 } 97 | Popular Tags |