1
|
package eu.dnetlib.openaire.usermanagement;
|
2
|
|
3
|
import com.unboundid.ldap.sdk.LDAPException;
|
4
|
import eu.dnetlib.openaire.user.utils.EmailActions;
|
5
|
import eu.dnetlib.openaire.user.utils.LDAPActions;
|
6
|
import org.apache.log4j.Logger;
|
7
|
import org.springframework.beans.factory.annotation.Autowired;
|
8
|
import org.springframework.stereotype.Component;
|
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
|
|
18
|
/**
|
19
|
* Created by kiatrop on 2/10/2017.
|
20
|
*/
|
21
|
@Component
|
22
|
public class RemindUsernameServlet 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 LDAPActions ldapActions;
|
32
|
|
33
|
private EmailActions emailActions;
|
34
|
|
35
|
private Logger logger = Logger.getLogger(RemindUsernameServlet.class);
|
36
|
|
37
|
@Override
|
38
|
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException {
|
39
|
String formEmail = request.getParameter("email");
|
40
|
|
41
|
if (formEmail == null){
|
42
|
request.getSession().setAttribute("message", "Error reading email.");
|
43
|
response.sendRedirect("./remindUsername.jsp");
|
44
|
}
|
45
|
|
46
|
try{
|
47
|
String username = ldapActions.getUsername(formEmail);
|
48
|
if ( username != null && !username.isEmpty()) {
|
49
|
//emailActions.sendUsernameReminder(formEmail);
|
50
|
|
51
|
} else {
|
52
|
request.getSession().setAttribute("message", "User not found");
|
53
|
response.sendRedirect("./remindUsername.jsp");
|
54
|
}
|
55
|
|
56
|
|
57
|
} catch (LDAPException ldape) {
|
58
|
//TODO create error page
|
59
|
logger.error("Could not find user with email " + formEmail, ldape);
|
60
|
response.sendRedirect("./error.jsp");
|
61
|
}
|
62
|
}
|
63
|
|
64
|
}
|