Rev 961 | Rev 1051 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
924 | dev | 1 | package ak.hostadmiral.core.action; |
919 | dev | 2 | |
3 | import javax.servlet.http.HttpServletRequest; |
||
4 | import javax.servlet.http.HttpServletResponse; |
||
5 | |||
950 | dev | 6 | import org.apache.struts.Globals; |
919 | dev | 7 | import org.apache.struts.action.Action; |
8 | import org.apache.struts.action.ActionMapping; |
||
9 | import org.apache.struts.action.ActionForm; |
||
10 | import org.apache.struts.action.DynaActionForm; |
||
11 | import org.apache.struts.action.ActionForward; |
||
12 | import org.apache.struts.action.ActionMessages; |
||
13 | import org.apache.struts.action.ActionErrors; |
||
14 | import org.apache.struts.action.ActionError; |
||
15 | |||
16 | import ak.backpath.BackPath; |
||
17 | |||
924 | dev | 18 | import ak.hostadmiral.core.CoreResources; |
19 | import ak.hostadmiral.core.model.User; |
||
20 | import ak.hostadmiral.core.model.UserManager; |
||
919 | dev | 21 | |
22 | public final class LoginAction |
||
23 | extends Action |
||
24 | { |
||
25 | public ActionForward execute(ActionMapping mapping, ActionForm form, |
||
26 | HttpServletRequest request, HttpServletResponse response) |
||
27 | throws Exception |
||
28 | { |
||
1014 | dev | 29 | ActionUtils.prepare(request, response); |
919 | dev | 30 | |
1014 | dev | 31 | if("show".equals(mapping.getParameter())) { |
32 | return mapping.findForward("default"); |
||
33 | } |
||
34 | else if("submit".equals(mapping.getParameter())) { |
||
35 | DynaActionForm theForm = (DynaActionForm)form; |
||
36 | User user = UserManager.getInstance().loginUser((String)theForm.get("login"), |
||
37 | (String)theForm.get("password"), request.getRemoteAddr()); |
||
919 | dev | 38 | |
1014 | dev | 39 | if(user == null) { |
40 | Thread.sleep(1000); // FIXME: make this delay configurable |
||
951 | dev | 41 | |
1014 | dev | 42 | ActionErrors errors = new ActionErrors(); |
43 | errors.add(ActionMessages.GLOBAL_MESSAGE, |
||
44 | new ActionError(CoreResources.LOGIN_FAILED)); |
||
45 | saveErrors(request, errors); |
||
46 | return mapping.getInputForward(); |
||
47 | } |
||
48 | else { |
||
49 | request.getSession().setAttribute("user", user); |
||
50 | request.getSession().setAttribute(Globals.LOCALE_KEY, user.getLocale()); |
||
919 | dev | 51 | |
1014 | dev | 52 | String origin = BackPath.findBackPath(request).getBackwardUrl(); |
53 | if(origin == null || origin.length() <= 0) { |
||
54 | return mapping.findForward("default"); |
||
55 | } |
||
56 | else { |
||
57 | response.sendRedirect(origin); |
||
58 | return null; |
||
59 | } |
||
919 | dev | 60 | } |
61 | } |
||
1014 | dev | 62 | else { |
63 | throw new Exception("unknown mapping parameter"); |
||
64 | } |
||
919 | dev | 65 | } |
66 | } |