1
|
package eu.dnetlib.openaire.usermanagement;
|
2
|
|
3
|
import eu.dnetlib.openaire.user.utils.LDAPActions;
|
4
|
import eu.dnetlib.openaire.user.utils.VerificationActions;
|
5
|
import org.apache.log4j.Logger;
|
6
|
import org.springframework.beans.factory.annotation.Autowired;
|
7
|
import org.springframework.web.context.support.SpringBeanAutowiringSupport;
|
8
|
|
9
|
import javax.servlet.ServletConfig;
|
10
|
import javax.servlet.ServletException;
|
11
|
import javax.servlet.http.HttpServlet;
|
12
|
import javax.servlet.http.HttpServletRequest;
|
13
|
import javax.servlet.http.HttpServletResponse;
|
14
|
import java.io.IOException;
|
15
|
import java.io.PrintWriter;
|
16
|
|
17
|
/**
|
18
|
* Created by kiatrop on 28/9/2017.
|
19
|
*/
|
20
|
public class ResetPasswordServlet extends HttpServlet {
|
21
|
|
22
|
public void init(ServletConfig config) throws ServletException {
|
23
|
super.init(config);
|
24
|
SpringBeanAutowiringSupport.processInjectionBasedOnServletContext(this,
|
25
|
config.getServletContext());
|
26
|
}
|
27
|
|
28
|
@Autowired
|
29
|
private VerificationActions verificationActions;
|
30
|
|
31
|
@Autowired
|
32
|
private LDAPActions ldapActions;
|
33
|
|
34
|
private Logger logger = Logger.getLogger(ResetPasswordServlet.class);
|
35
|
|
36
|
@Override
|
37
|
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException {
|
38
|
response.setContentType("text/html");
|
39
|
PrintWriter printWriter = response.getWriter();
|
40
|
|
41
|
String username = request.getParameter("username");
|
42
|
String password = request.getParameter("password");
|
43
|
String confirmPassword = request.getParameter("password_conf");
|
44
|
|
45
|
//logger.info("username: " + username);
|
46
|
logger.info("password: " + password);
|
47
|
logger.info("confirmPassword: " + confirmPassword);
|
48
|
|
49
|
//String username = (String)request.getAttribute("username");
|
50
|
|
51
|
logger.info("username: " + username);
|
52
|
|
53
|
if (password.equals(confirmPassword) && username != null) {
|
54
|
|
55
|
|
56
|
logger.info("username: " + username);
|
57
|
try {
|
58
|
|
59
|
ldapActions.resetPassword(username, password);
|
60
|
logger.info("password reseted");
|
61
|
|
62
|
} catch (Exception e) {
|
63
|
e.printStackTrace();
|
64
|
request.getSession().setAttribute("message", "Error reseting password.");
|
65
|
response.sendRedirect("./verify.jsp");
|
66
|
}
|
67
|
}
|
68
|
|
69
|
response.sendRedirect("./success.jsp");
|
70
|
printWriter.close();
|
71
|
}
|
72
|
}
|