1 25 package org.snipsnap.net; 26 27 import org.snipsnap.app.Application; 28 import org.snipsnap.snip.SnipLink; 29 import org.snipsnap.user.User; 30 import org.snipsnap.user.UserManager; 31 import org.snipsnap.user.PasswordService; 32 import org.snipsnap.user.UserManagerFactory; 33 import org.snipsnap.container.Components; 34 import org.snipsnap.container.SessionService; 35 import org.snipsnap.config.Configuration; 36 37 import javax.servlet.RequestDispatcher ; 38 import javax.servlet.ServletException ; 39 import javax.servlet.http.HttpServlet ; 40 import javax.servlet.http.HttpServletRequest ; 41 import javax.servlet.http.HttpServletResponse ; 42 import javax.servlet.http.HttpSession ; 43 import java.io.IOException ; 44 45 52 public class ChangePasswordServlet extends HttpServlet { 53 private final static String ERR_PASSWORD = "User name and password do not match!"; 54 55 public void doPost(HttpServletRequest request, HttpServletResponse response) 56 throws ServletException , IOException { 57 Configuration config = Application.get().getConfiguration(); 58 59 String password1 = request.getParameter("password"); 60 String password2 = request.getParameter("password2"); 61 String key = request.getParameter("key"); 62 63 if (request.getParameter("cancel") == null) { 64 User user; 65 if (null != password1 && password1.equals(password2)) { 66 PasswordService passwordService = (PasswordService) Components.getComponent(PasswordService.class); 67 user = passwordService.changePassWord(key, password1); 68 } else { 69 request.setAttribute("error", "user.password.error.nomatch"); 70 RequestDispatcher dispatcher = request.getRequestDispatcher("/exec/changepass.jsp"); 71 dispatcher.forward(request, response); 72 return; 73 } 74 75 if (null != user) { 76 if (Application.getCurrentUsers().contains(user)) { 77 Application.getCurrentUsers().remove(user); 78 } 79 HttpSession session = request.getSession(); 80 Application.get().setUser(user, session); 81 82 SessionService service = (SessionService) Components.getComponent(SessionService.class); 83 service.setUser(request, response, user); 84 response.sendRedirect(config.getUrl("/space/"+SnipLink.encode(user.getLogin()))); 85 } else { 86 request.setAttribute("error", "user.password.error.keymismatch"); 87 RequestDispatcher dispatcher = request.getRequestDispatcher("/exec/forgot.jsp"); 88 dispatcher.forward(request, response); 89 } 90 } else { 91 response.sendRedirect(config.getUrl("/space/"+Application.get().getConfiguration().getStartSnip())); 92 } 93 } 94 } 95 | Popular Tags |