KickJava   Java API By Example, From Geeks To Geeks.

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


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

22 package com.geinuke.module.login;
23 import java.util.ArrayList JavaDoc;
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.IPortalCFGBL;
35 import com.geinuke.middle.IUserBL;
36 import com.geinuke.module.ModuleWriter;
37 import com.geinuke.servlet.GeiServlet;
38 import com.geinuke.util.NukeResource;
39 import com.geinuke.util.TextUtil;
40 import com.geinuke.vo.ModuleDBVO;
41 import com.geinuke.vo.PortalCFGVO;
42 import com.geinuke.vo.UserVO;
43
44
45
46 public class NewUserModule implements ModuleWidgetI{
47
48     
49     protected UserVO check(){
50         UserVO u=null;
51         u=new UserVO();
52         return u;
53     }
54     
55     
56     
57     
58     protected NukeModuleI showFormInsertUser(ModuleDBVO module, Context ctx,HttpServletRequest JavaDoc req, HttpServletResponse JavaDoc res, UserI user, GlobalConfigurationI gConf) throws Exception JavaDoc {
59         NukeModuleI mod=null;
60         String JavaDoc moduleTempName=null;
61         String JavaDoc op=req.getParameter("op");
62         PortalCFGVO po=null;
63         IPortalCFGBL pbl=(IPortalCFGBL)GeiServlet.getBL("IPortalCFGBL");
64         po=pbl.getPortalCFG();
65         UserVO us=null;
66         us=new UserVO();
67         
68         if(TextUtil.isEmpty( po.getPortalStyle() ) ){
69             //GeiServlet.fixStyle(req.getSession(true),req.getParameter("newStyle"));
70

71             ctx.put("changeStyle","t");
72         }else{
73             us.setDefStyle( (String JavaDoc)req.getSession(true).getAttribute("style"));
74         }
75         
76         
77         ArrayList JavaDoc list=null;
78         list=NukeResource.getThemesList();
79         ctx.put("themes",list);
80         //ctx.put("u",us);
81
ctx.put("user",us);
82         moduleTempName=gConf.getModulePage(module.getName(),op);
83         mod=ModuleWriter.fill(ctx,module,moduleTempName);
84         return mod;
85     }
86     
87     protected UserVO checkSubscription(HttpServletRequest JavaDoc req,String JavaDoc repass,UserVO u,Context ctx) throws Exception JavaDoc{
88         UserVO us=null;
89         
90         
91         
92         IUserBL bl=(IUserBL)GeiServlet.getBL("IUserBL");
93         
94         
95         
96         ctx.put("errors",ctx);
97         String JavaDoc num=req.getParameter("number")+"";
98         String JavaDoc numS=(String JavaDoc)req.getSession(true).getAttribute("ImageValue");
99         if( TextUtil.isEmpty(u.getPassword()) ){
100             ctx.put("error","CHECK_PSW_MSG");
101         }else if( TextUtil.isEmpty(repass) ){
102             ctx.put("error","CHECK_REPSW_MSG");
103         }else if(! repass.equals(u.getPassword())){
104             ctx.put("error","CHECK_PSW_REPSW_MSG");
105         }else if( TextUtil.isEmpty(u.getName()) ){
106             ctx.put("error","CHECK_NAME_MSG");
107         }else if( TextUtil.isEmpty(u.getUName()) ){
108             ctx.put("error","CHECK_UNAME_MSG");
109         }else if(! num.equals(numS)){
110             ctx.put("error","CHECK_NUM_MSG");
111         }else if(bl.getUserByUName(u)!=null){
112             ctx.put("error","ERROR_ALREADY_UNAME");
113         }
114         if(ctx.get("error")!=null)
115             return u;
116         else
117             return us;
118     }
119     
120     protected NukeModuleI tryInsertUser(ModuleDBVO module, Context ctx,HttpServletRequest JavaDoc req, HttpServletResponse JavaDoc res, UserI user, GlobalConfigurationI gConf) throws Exception JavaDoc {
121         NukeModuleI mod=null;
122         String JavaDoc moduleTempName=null;
123         
124         String JavaDoc name=req.getParameter("name");
125         String JavaDoc uname=req.getParameter("uname");
126         String JavaDoc pass=req.getParameter("password");
127         String JavaDoc repass=req.getParameter("repassword");
128         String JavaDoc theme=req.getParameter("newStyle");
129         UserVO errorUser=null,us=new UserVO();
130         us.setDefStyle(theme);
131         us.setName(name);
132         us.setUName(uname);
133         us.setAvatar("robot.gif");
134         us.setPassword(pass);
135         us.setRegDate(System.currentTimeMillis());
136         //String
137
errorUser=this.checkSubscription(req,repass,us,ctx);
138         if(errorUser==null){
139             moduleTempName=gConf.getModulePage(module.getName(),"ins");
140             IUserBL ub=(IUserBL)GeiServlet.getBL("IUserBL");
141             us.getRole().setId(UserVO.USER_ID);
142             us.setPassword( TextUtil.encr( us.getPassword() ) );
143             ub.insUser(us);
144             us=ub.getUserByUName(us);
145             req.getSession(true).setAttribute("user",us);
146             ctx.put("user",us);
147             ctx.put("currentUser",us);
148             
149         }else{
150             
151             PortalCFGVO po=null;
152             IPortalCFGBL pbl=(IPortalCFGBL)GeiServlet.getBL("IPortalCFGBL");
153             po=pbl.getPortalCFG();
154             if(! TextUtil.isEmpty( po.getPortalStyle()) ){
155                 System.out.println("NewUserModule.tryInsertUser() false ");
156                 errorUser.setDefStyle(po.getPortalStyle());
157             }else{
158                 System.out.println("NewUserModule.tryInsertUser() true ");
159             }
160             ctx.put("user",errorUser);
161             ctx.put("themes",NukeResource.getThemesList());
162             moduleTempName=gConf.getModulePage(module.getName(),"inserror");
163         }
164         mod=ModuleWriter.fill(ctx,module,moduleTempName);
165         return mod;
166     }
167     
168     public NukeModuleI handleAction(ModuleDBVO module, Context ctx,HttpServletRequest JavaDoc req, HttpServletResponse JavaDoc res, UserI user, GlobalConfigurationI gConf) throws Exception JavaDoc {
169         
170         String JavaDoc op=req.getParameter("op");
171         if(op.equals("new")){
172             return this.showFormInsertUser(module, ctx,req, res,user,gConf);
173         }else if(op.equals("ins")){
174             return this.tryInsertUser(module, ctx,req, res,user,gConf);
175         }else{
176             throw new Exception JavaDoc();
177         }
178         
179     }
180
181 }
182
183
Popular Tags