KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > geinuke > module > login > LoginModule


1
2  /*
3  -- GeiNuke --
4 Copyright (c) 2005 by Roberto Sidoti [geinuke@users.sourceforge.net]
5  http://www.hostingjava.it/-geinuke/
6
7 This file is part of GeiNuke.
8
9     GeiNuke is free software; you can redistribute it and/or modify
10     it under the terms of the GNU General Public License as published by
11     the Free Software Foundation; either version 2 of the License, or
12     (at your option) any later version.
13
14     GeiNuke is distributed in the hope that it will be useful,
15     but WITHOUT ANY WARRANTY; without even the implied warranty of
16     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17     GNU General Public License for more details.
18
19     You should have received a copy of the GNU General Public License
20     along with GeiNuke; if not, write to the Free Software
21     Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 */

23 package com.geinuke.module.login;
24
25 import javax.servlet.http.HttpServletRequest JavaDoc;
26 import javax.servlet.http.HttpServletResponse JavaDoc;
27
28 import org.apache.velocity.context.Context;
29
30 import com.geinuke.common.GlobalConfigurationI;
31 import com.geinuke.common.ModuleWidgetI;
32 import com.geinuke.common.NukeModuleI;
33 import com.geinuke.common.UserI;
34 import com.geinuke.middle.IUserBL;
35 import com.geinuke.module.ModuleWriter;
36 import com.geinuke.servlet.GeiServlet;
37 import com.geinuke.util.TextUtil;
38 import com.geinuke.vo.ModuleDBVO;
39 import com.geinuke.vo.UserVO;
40
41
42
43 public class LoginModule implements ModuleWidgetI{
44
45     
46     protected String JavaDoc checkAction(Context ctx,String JavaDoc uname,String JavaDoc passw){
47         String JavaDoc action=null;
48         action="ok";
49         String JavaDoc[] badChars=TextUtil.badChars;
50         if(uname==null || uname.trim().equals("")){
51             action="nok";
52         }else if(passw==null || passw.trim().equals("")){
53             action="nok";
54         }else if( TextUtil.hasChars(passw,badChars) || TextUtil.hasChars(uname,badChars) ){
55             ctx.put("badChars",TextUtil.convert(badChars));
56             action="badChars";
57         }
58         return action;
59     }
60     
61     protected String JavaDoc checkLogin(Context ctx,HttpServletRequest JavaDoc req,String JavaDoc uname,String JavaDoc passw)throws Exception JavaDoc{
62         String JavaDoc action=null;
63         UserVO user=new UserVO();
64         GeiServlet.intLog("LoginModule.handleAction(...), trace AAA1");
65         String JavaDoc password=TextUtil.encr(passw);
66         GeiServlet.intLog("LoginModule.handleAction(...), trace AAA2");
67         user.setUName(uname);
68         user.setPassword(password);
69         IUserBL bl=(IUserBL)GeiServlet.getBL("IUserBL");
70         user=bl.getUserByAuth(user);
71         if(user!=null){
72             req.getSession(true).setAttribute("user",user);
73             String JavaDoc newStyle=user.getDefStyle();
74             GeiServlet.fixStyle(req.getSession(true),newStyle);
75             action="ok";
76         }else{
77             action="nok";
78         }
79         return action;
80     }
81     
82     public NukeModuleI handleAction(ModuleDBVO module, Context ctx,HttpServletRequest JavaDoc req, HttpServletResponse JavaDoc res, UserI user, GlobalConfigurationI gConf) throws Exception JavaDoc {
83         NukeModuleI mod=null;
84         String JavaDoc moduleTempName=null;
85         String JavaDoc login=req.getParameter("login");
86         String JavaDoc op=null;
87         //login from Login Block
88
GeiServlet.intLog("LoginModule.handleAction(...), start");
89         if(login!=null && login.equals("yes")){
90             GeiServlet.intLog("LoginModule.handleAction(...), trace A");
91             String JavaDoc uname=req.getParameter("username");
92             String JavaDoc passw=req.getParameter("password");
93             op=this.checkAction(ctx,uname,passw);
94             if(op.equals("ok")){
95                 op=this.checkLogin(ctx,req,uname,passw);
96             }
97             GeiServlet.intLog("LoginModule.handleAction(...), trace AA1");
98             if(op.equals("ok")){
99                 GeiServlet.intLog("LoginModule.handleAction(...),calling \nuser=UserBL.singleton().getUserByUName((UserVO)user)");
100                 UserVO tmp=new UserVO();
101                 tmp.setUName(req.getParameter("username"));
102                 IUserBL bl=(IUserBL)GeiServlet.getBL("IUserBL");
103                 user=bl.getUserByUName(tmp);
104                 GeiServlet.intLog("LoginModule.handleAction(...),levela="+user.getRole().getLevela());
105             }
106         
107         }else if(req.getParameter("op")==null && !user.getUName().equals(UserI.ANONYMOUS)){
108             GeiServlet.intLog("LoginModule.handleAction(...), trace B "+user.getUName());
109             GeiServlet.intLog("LoginModule.handleAction(...), trace B1 "+user.getUName()+UserI.ANONYMOUS+"-");
110             op="ok";
111         }else if(req.getParameter("op")!=null && req.getParameter("op").equals("edit")){
112             GeiServlet.intLog("LoginModule.handleAction(...), trace C");
113             op="edit";
114             if(req.getSession(true).getAttribute("user")!=null
115                     && ((UserI)req.getSession(true).getAttribute("user")).getName().equals(UserI.ANONYMOUS) ){
116                 
117                 
118             }
119                 
120         
121         }else if(req.getParameter("op")!=null && req.getParameter("op").equals("logout")){
122             GeiServlet.intLog("LoginModule.handleAction(...), trace D");
123             IUserBL ubl=(IUserBL)GeiServlet.getBL("IUserBL");
124             req.getSession(true).setAttribute("user",ubl.getDefUser());
125             GeiServlet.home(res);
126             //module=ModuleBL.singleton().getDefModule();
127
op="";
128             
129         }else {
130             GeiServlet.intLog("LoginModule.handleAction(...), trace E");
131             op="login";
132         }
133         
134         GeiServlet.intLog("LoginModule.handleAction(...), op="+op);
135         GeiServlet.intLog("LoginModule.handleAction(...), START");
136         ctx.put("currentUser",user);
137         
138         moduleTempName=gConf.getModulePage(module.getName(),op);
139         mod=ModuleWriter.fill(ctx,module,moduleTempName);
140         return mod;
141     }
142
143 }
144
Popular Tags