1 2 23 package com.geinuke.module.login; 24 25 import javax.servlet.http.HttpServletRequest ; 26 import javax.servlet.http.HttpServletResponse ; 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 checkAction(Context ctx,String uname,String passw){ 47 String action=null; 48 action="ok"; 49 String [] 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 checkLogin(Context ctx,HttpServletRequest req,String uname,String passw)throws Exception { 62 String action=null; 63 UserVO user=new UserVO(); 64 GeiServlet.intLog("LoginModule.handleAction(...), trace AAA1"); 65 String 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 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 req, HttpServletResponse res, UserI user, GlobalConfigurationI gConf) throws Exception { 83 NukeModuleI mod=null; 84 String moduleTempName=null; 85 String login=req.getParameter("login"); 86 String op=null; 87 GeiServlet.intLog("LoginModule.handleAction(...), start"); 89 if(login!=null && login.equals("yes")){ 90 GeiServlet.intLog("LoginModule.handleAction(...), trace A"); 91 String uname=req.getParameter("username"); 92 String 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 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 |