1 |
52118
|
sofia.balt
|
package eu.dnetlib.openaire.usermanagement;
|
2 |
|
|
|
3 |
|
|
import eu.dnetlib.openaire.user.utils.InputValidator;
|
4 |
|
|
import eu.dnetlib.openaire.user.utils.LDAPActions;
|
5 |
|
|
import eu.dnetlib.openaire.user.utils.VerificationActions;
|
6 |
|
|
import eu.dnetlib.openaire.usermanagement.utils.UrlConstructor;
|
7 |
|
|
import org.apache.log4j.Logger;
|
8 |
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
9 |
|
|
import org.springframework.web.context.support.SpringBeanAutowiringSupport;
|
10 |
|
|
|
11 |
|
|
import javax.servlet.ServletConfig;
|
12 |
|
|
import javax.servlet.ServletException;
|
13 |
|
|
import javax.servlet.http.HttpServlet;
|
14 |
|
|
import javax.servlet.http.HttpServletRequest;
|
15 |
|
|
import javax.servlet.http.HttpServletResponse;
|
16 |
|
|
import java.io.IOException;
|
17 |
|
|
import java.io.PrintWriter;
|
18 |
|
|
|
19 |
|
|
/**
|
20 |
|
|
* Created by sofia on 21/5/2018.
|
21 |
|
|
*/
|
22 |
|
|
public class VerifyToDeleteServlet extends HttpServlet {
|
23 |
|
|
|
24 |
|
|
public void init(ServletConfig config) throws ServletException {
|
25 |
|
|
super.init(config);
|
26 |
|
|
SpringBeanAutowiringSupport.processInjectionBasedOnServletContext(this,
|
27 |
|
|
config.getServletContext());
|
28 |
|
|
}
|
29 |
|
|
|
30 |
|
|
@Autowired
|
31 |
|
|
private VerificationActions verificationActions;
|
32 |
|
|
|
33 |
|
|
@Autowired
|
34 |
|
|
private LDAPActions ldapActions;
|
35 |
|
|
|
36 |
|
|
private Logger logger = Logger.getLogger(VerificationCodeServlet.class);
|
37 |
|
|
|
38 |
|
|
@Override
|
39 |
|
|
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException {
|
40 |
|
|
response.setContentType("text/html");
|
41 |
|
|
PrintWriter printWriter = response.getWriter();
|
42 |
|
|
|
43 |
|
|
String formUsername = request.getParameter("username").trim();
|
44 |
|
|
String formVerificationCode = request.getParameter("verification_code").trim();
|
45 |
|
|
|
46 |
|
|
try {
|
47 |
|
|
if (InputValidator.isFilled(formUsername) && InputValidator.isFilled(formVerificationCode)) {
|
48 |
|
|
if (verificationActions.verificationEntryExists(formUsername) && verificationActions.verificationCodeIsCorrect(formUsername, formVerificationCode)) {
|
49 |
|
|
if (!verificationActions.verificationCodeHasExpired(formUsername)) {
|
50 |
|
|
|
51 |
|
|
Boolean isRegistered = false;
|
52 |
|
|
Boolean isZombie = false;
|
53 |
|
|
|
54 |
|
|
if (ldapActions.usernameExists(formUsername)) {
|
55 |
|
|
logger.info("User " + formUsername + " is activated user!");
|
56 |
|
|
isRegistered = true;
|
57 |
|
|
} else if (ldapActions.isZombieUsersUsername(formUsername)) {
|
58 |
|
|
logger.info("User " + formUsername + " is zombie user!");
|
59 |
|
|
isZombie = true;
|
60 |
|
|
}
|
61 |
|
|
|
62 |
|
|
if (!isRegistered && !isZombie) {
|
63 |
|
|
request.getSession().setAttribute("message", "Username or verification code are not valid.");
|
64 |
|
|
response.sendRedirect("./verifyToDelete.jsp");
|
65 |
|
|
} else {
|
66 |
|
|
if (isRegistered) {
|
67 |
|
|
ldapActions.deleteUser(formUsername);
|
68 |
|
|
} else if (isZombie) {
|
69 |
|
|
ldapActions.deleteZombieUser(formUsername);
|
70 |
|
|
}
|
71 |
52132
|
sofia.balt
|
verificationActions.deleteVerificationEntry(formUsername);
|
72 |
52118
|
sofia.balt
|
response.sendRedirect(UrlConstructor.getRedirectUrl(request,"successDeleteAccount.jsp"));
|
73 |
|
|
|
74 |
|
|
}
|
75 |
|
|
} else {
|
76 |
|
|
logger.info("Verification code has expired!");
|
77 |
|
|
response.sendRedirect(UrlConstructor.getRedirectUrl(request, "expiredVerificationCode.jsp"));
|
78 |
|
|
}
|
79 |
|
|
} else {
|
80 |
|
|
logger.info("Username or verification code are not valid!");
|
81 |
|
|
request.getSession().setAttribute("message", "Username or verification code are not valid.");
|
82 |
|
|
response.sendRedirect("./verifyToDelete.jsp");
|
83 |
|
|
}
|
84 |
|
|
} else {
|
85 |
|
|
if (!InputValidator.isFilled(formUsername)) {
|
86 |
|
|
logger.info("No username");
|
87 |
|
|
request.getSession().setAttribute("msg_username_error", "Please enter your username.");
|
88 |
|
|
}
|
89 |
|
|
if (!InputValidator.isFilled(formVerificationCode)) {
|
90 |
|
|
logger.info("No verification code");
|
91 |
|
|
request.getSession().setAttribute("msg_verification_code_error", "Please enter your verification code.");
|
92 |
|
|
}
|
93 |
|
|
response.sendRedirect("./verifyToDelete.jsp");
|
94 |
|
|
}
|
95 |
|
|
} catch (Exception ldape) {
|
96 |
|
|
logger.error("Could not remove user with username " + formUsername, ldape);
|
97 |
|
|
response.sendRedirect(UrlConstructor.getRedirectUrl(request, "error.jsp"));
|
98 |
|
|
}
|
99 |
|
|
|
100 |
|
|
printWriter.close();
|
101 |
|
|
}
|
102 |
|
|
}
|