KickJava   Java API By Example, From Geeks To Geeks.

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


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

24 package com.geinuke.module.login;
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.IModuleBL;
35 import com.geinuke.middle.IPortalCFGBL;
36 import com.geinuke.middle.IUserBL;
37 import com.geinuke.module.ModuleWriter;
38 import com.geinuke.servlet.GeiServlet;
39 import com.geinuke.util.NukeResource;
40 import com.geinuke.util.TextUtil;
41 import com.geinuke.vo.ModuleDBVO;
42 import com.geinuke.vo.UserVO;
43
44
45
46 public class EditAccountModule implements ModuleWidgetI{
47     
48     protected boolean checkUpdate(String JavaDoc pass,String JavaDoc oldPass,String JavaDoc repass,UserVO u,Context ctx)throws Exception JavaDoc{
49         UserVO aux=null;
50         IUserBL ubl=(IUserBL)GeiServlet.getBL("IUserBL");
51         aux=ubl.getUserByUName(u);
52         
53         ctx.put("errors",ctx);
54         GeiServlet.intLog("EditAccountModule.EditAccountModule(...), aux.getPassword()"+aux.getPassword());
55         if(! aux.getPassword().equals( TextUtil.encr(oldPass) ) ){
56             ctx.put("error","CHECK_OLDPSW_MSG");
57         }else if( TextUtil.isEmpty(pass) ){
58             ctx.put("error","CHECK_PSW_MSG");
59         }else if( TextUtil.isEmpty(repass) ){
60             ctx.put("error","CHECK_REPSW_MSG");
61         }else if(! repass.equals(pass)){
62             ctx.put("error","CHECK_PSW_REPSW_MSG");
63         }else if( TextUtil.isEmpty(u.getUName()) ){
64             ctx.put("error","CHECK_UNAME_MSG");
65         }
66         if(ctx.get("error")!=null)
67             return false;
68         else
69             return true;
70     }
71     
72     protected NukeModuleI tryUpdateUser(ModuleDBVO module, Context ctx,HttpServletRequest JavaDoc req, HttpServletResponse JavaDoc res, UserI user, GlobalConfigurationI gConf) throws Exception JavaDoc {
73         NukeModuleI mod=null;
74         String JavaDoc moduleTempName=null;
75         GeiServlet.intLog("EditAccountModule.tryUpdateUser(...),1 user.role.levela="+user.getRole().getLevela());
76         IUserBL ubl=(IUserBL)GeiServlet.getBL("IUserBL");
77         String JavaDoc name=req.getParameter("name");
78         String JavaDoc uname=user.getUName();
79         String JavaDoc oldPass=req.getParameter("oldpassword");
80         String JavaDoc pass=req.getParameter("password");
81         String JavaDoc repass=req.getParameter("repassword");
82         //String theme=req.getParameter("newStyle");
83

84         UserVO newU=ubl.getUserByID(user.getId());
85         //newU.setName(name);
86
//newU.setUName(uname);
87
//newU.setId(user.getId());
88
newU.setPassword( TextUtil.encr( pass ) );
89         //newU.setRole(user.getRole());
90
//newU.setDefStyle(theme);
91
if(this.checkUpdate(pass,oldPass,repass,newU,ctx)){
92             moduleTempName=gConf.getModulePage(module.getName(),"update");
93             ctx.put("themes",NukeResource.getThemesList());
94             ctx.put("defaultT",newU.getDefStyle());
95             ctx.put("userX",newU);
96             ubl.updateUser(newU);
97             req.getSession(true).setAttribute("user",newU);
98         }else{
99             ctx.put("themes",NukeResource.getThemesList());
100             ctx.put("defaultT",user.getDefStyle());
101             ctx.put("userX",user);
102             moduleTempName=gConf.getModulePage(module.getName(),"upderror");
103         
104         }
105         
106         mod=ModuleWriter.fill(ctx,module,moduleTempName);
107         return mod;
108     }
109     
110     
111     public NukeModuleI handleAction(ModuleDBVO module, Context ctx,HttpServletRequest JavaDoc req, HttpServletResponse JavaDoc res, UserI user, GlobalConfigurationI gConf) throws Exception JavaDoc {
112         
113         String JavaDoc moduleTempName=null;
114         String JavaDoc op=req.getParameter("op");
115         //IPortalCFGBL pbl=(IPortalCFGBL)GeiServlet.getBL("IPortalCFGBL");
116
if(req.getSession(true).getAttribute("user")!=null
117                     && !( (UserI)req.getSession(true).getAttribute("user")).getName().equals(UserI.ANONYMOUS) ){
118             GeiServlet.intLog("EditAccountModule.handleAction(...),trace A");
119             if(op.equals("edit")){
120                 ctx.put("themes",NukeResource.getThemesList());
121                 ctx.put("defaultT",user.getDefStyle());
122                 ctx.put("userX",req.getSession(true).getAttribute("user"));
123             }else if(op.equals("update")){
124                 
125                 return this.tryUpdateUser(module,ctx,req,res,user,gConf);
126             }
127         
128         
129         }else{
130             GeiServlet.intLog("EditAccountModule.handleAction(...),trace B");
131             IModuleBL bl=(IModuleBL)GeiServlet.getBL("IModuleBL");
132             module=bl.getModule("Error");
133             module.setActive(true);
134             op="";
135             ctx.put("defaultT","");
136             ctx.put("errors",ctx);
137             ctx.put("error","ERROR_NA4MODULEULE_MSG");
138         }
139         
140         moduleTempName=gConf.getModulePage(module.getName(),op);
141         return ModuleWriter.fill(ctx,module,moduleTempName);
142         
143     }
144
145 }
146
147
Popular Tags