Author: bbrossaud Date: 2010-06-25 17:58:46 +0200 (Fri, 25 Jun 2010) New Revision: 78 Url: http://chorem.org/repositories/revision/bow/78 Log: to change the current password we have to fill the current and confirm the new Modified: trunk/src/main/java/org/chorem/bow/ControllerServlet.java trunk/src/main/webapp/preferences.jsp Modified: trunk/src/main/java/org/chorem/bow/ControllerServlet.java =================================================================== --- trunk/src/main/java/org/chorem/bow/ControllerServlet.java 2010-06-22 17:58:20 UTC (rev 77) +++ trunk/src/main/java/org/chorem/bow/ControllerServlet.java 2010-06-25 15:58:46 UTC (rev 78) @@ -982,32 +982,49 @@ private void actionChangePreferences(HttpServletRequest request, HttpSession session, User user) throws NoSuchAlgorithmException, AddressException, MessagingException { + WikittyProxy proxy = BowProxy.getInstance(); - String email = request.getParameter("email"); - String password = request.getParameter("password"); + Preference preference = (Preference) session.getAttribute("preference"); + // Retrieve Preference fields String colors = request.getParameter("colors"); + String tags = request.getParameter("tags"); + String bookmarks = request.getParameter("bookmarks"); + String searchEngineSuggestions = request.getParameter("searchEngineUrlSuggestions"); + String searchEngineResults = request.getParameter("searchEngineUrlResults"); + preference.setColors(colors); - String tags = request.getParameter("tags"); preference.setTags(Integer.valueOf(tags)); - String bookmarks = request.getParameter("bookmarks"); preference.setBookmarks(Integer.valueOf(bookmarks)); - String searchEngineSuggestions = request.getParameter("searchEngineUrlSuggestions"); preference.setSearchEngineUrlSuggestions(searchEngineSuggestions); - String searchEngineResults = request.getParameter("searchEngineUrlResults"); preference.setSearchEngineUrlResults(searchEngineResults); proxy.store(preference); + User newUser = proxy.restore(User.class, user.getWikittyId()); + // Retrieve User fields + String email = request.getParameter("email"); + String newPassword = request.getParameter("newPassword"); + String currentPassword = request.getParameter("currentPassword"); + String confirmNewPassword = request.getParameter("confirmNewPassword"); + if (email != null && !email.isEmpty()) { newUser.setEmail(email); } - if (password != null && !password.isEmpty()) { - String md5 = StringUtil.encodeMD5(password); - newUser.setPassword(md5); - sendMail(newUser.getEmail(), password); + if (newPassword != null && confirmNewPassword != null && currentPassword != null) { + if (!newPassword.isEmpty() && !confirmNewPassword.isEmpty() && !currentPassword.isEmpty()) { + if (newPassword.equals(confirmNewPassword)) { + currentPassword = StringUtil.encodeMD5(currentPassword); + if (currentPassword.equals(newUser.getPassword())) { + String md5 = StringUtil.encodeMD5(newPassword); + newUser.setPassword(md5); + sendMail(newUser.getEmail(), newPassword); + } + } + } } proxy.store(newUser); + session.setAttribute("user", newUser); preference = proxy.restore(Preference.class, newUser.getWikittyId()); request.setAttribute("preference", preference); Modified: trunk/src/main/webapp/preferences.jsp =================================================================== --- trunk/src/main/webapp/preferences.jsp 2010-06-22 17:58:20 UTC (rev 77) +++ trunk/src/main/webapp/preferences.jsp 2010-06-25 15:58:46 UTC (rev 78) @@ -49,9 +49,12 @@ <h1>User Informations</h1> <p>Email :</p> <input type="text" name="email" value="<%=user.getEmail()%>"/> - <p>Password :</p> - <input type=password name="password"/> - + <p>Current password :</p> + <input type=password name="currentPassword"/> + <p>New password :</p> + <input type=password name="newPassword"/> + <p>Confirm new password</p> + <input type=password name="confirmNewPassword"/> <br/> <h1>Site look</h1>