1 40 package org.dspace.app.webui.servlet; 41 42 import java.io.IOException ; 43 import java.sql.SQLException ; 44 45 import javax.servlet.ServletException ; 46 import javax.servlet.http.HttpServletRequest ; 47 import javax.servlet.http.HttpServletResponse ; 48 49 import org.apache.log4j.Logger; 50 import org.dspace.app.webui.util.JSPManager; 51 import org.dspace.authorize.AuthorizeException; 52 import org.dspace.core.Context; 53 import org.dspace.core.LogManager; 54 import org.dspace.eperson.EPerson; 55 56 62 public class EditProfileServlet extends DSpaceServlet 63 { 64 65 private static Logger log = Logger.getLogger(EditProfileServlet.class); 66 67 protected void doDSGet(Context context, HttpServletRequest request, 68 HttpServletResponse response) throws ServletException , IOException , 69 SQLException , AuthorizeException 70 { 71 log.info(LogManager.getHeader(context, "view_profile", "")); 74 75 request.setAttribute("eperson", context.getCurrentUser()); 76 77 JSPManager.showJSP(request, response, "/register/edit-profile.jsp"); 78 } 79 80 protected void doDSPost(Context context, HttpServletRequest request, 81 HttpServletResponse response) throws ServletException , IOException , 82 SQLException , AuthorizeException 83 { 84 EPerson eperson = context.getCurrentUser(); 86 87 boolean settingPassword = false; 89 90 if ((eperson.getRequireCertificate() == false) 91 && (request.getParameter("password") != null) 92 && !request.getParameter("password").equals("")) 93 { 94 settingPassword = true; 95 } 96 97 boolean ok = updateUserProfile(eperson, request); 99 100 if (!ok) 101 { 102 request.setAttribute("missing.fields", new Boolean (true)); 103 } 104 105 String passwordProblem = null; 106 107 if (ok && settingPassword) 108 { 109 ok = confirmAndSetPassword(eperson, request); 111 112 if (!ok) 113 { 114 request.setAttribute("password.problem", new Boolean (true)); 115 } 116 } 117 118 if (ok) 119 { 120 log.info(LogManager.getHeader(context, "edit_profile", 122 "password_changed=" + settingPassword)); 123 eperson.update(); 124 125 request.setAttribute("password.updated", new Boolean ( 127 settingPassword)); 128 JSPManager.showJSP(request, response, 129 "/register/profile-updated.jsp"); 130 131 context.complete(); 132 } 133 else 134 { 135 log.info(LogManager.getHeader(context, "view_profile", 136 "problem=true")); 137 138 request.setAttribute("eperson", eperson); 139 140 JSPManager.showJSP(request, response, "/register/edit-profile.jsp"); 141 } 142 } 143 144 157 public static boolean updateUserProfile(EPerson eperson, 158 HttpServletRequest request) 159 { 160 String lastName = request.getParameter("last_name"); 162 String firstName = request.getParameter("first_name"); 163 String phone = request.getParameter("phone"); 164 165 eperson.setFirstName(firstName); 167 eperson.setLastName(lastName); 168 eperson.setMetadata("phone", phone); 169 170 if ((lastName == null) || lastName.equals("") || (firstName == null) 172 || firstName.equals("")) 173 { 174 return false; 175 } 176 else 177 { 178 return true; 179 } 180 } 181 182 194 public static boolean confirmAndSetPassword(EPerson eperson, 195 HttpServletRequest request) 196 { 197 String password = request.getParameter("password"); 199 String passwordConfirm = request.getParameter("password_confirm"); 200 201 if ((password == null) || (password.length() < 6)) 203 { 204 return false; 205 } 206 207 if (!password.equals(passwordConfirm)) 209 { 210 return false; 211 } 212 213 eperson.setPassword(password); 215 216 return true; 217 } 218 } 219 | Popular Tags |