KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > campware > cream > modules > actions > PasswordSQL


1 package org.campware.cream.modules.actions;
2
3 /* ====================================================================
4  * Copyright (C) 2003-2005 Media Development Loan Fund
5  *
6  * * contact: contact@campware.org - http://www.campware.org
7  * Campware encourages further development. Please let us know.
8  *
9  * This program is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU General Public License
11  * as published by the Free Software Foundation; either version 2
12  * of the License, or (at your option) any later version.
13  *
14  * This program 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 this program; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22  *
23  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
24  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
25  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26  * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
27  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
29  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
30  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
31  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
32  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
33  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34  * SUCH DAMAGE.
35  * ====================================================================
36  *
37  * This software consists of voluntary contributions made by many
38  * individuals on behalf of the Apache Software Foundation. For more
39  * information on the Apache Software Foundation, please see
40  * <http://www.apache.org/>.
41  */

42
43 import org.apache.velocity.context.Context;
44
45 import org.apache.turbine.util.RunData;
46 import org.apache.torque.util.Criteria;
47
48 import org.campware.cream.om.TurbineUser;
49 import org.campware.cream.om.TurbineUserPeer;
50
51 import org.apache.turbine.om.security.User;
52 /**
53  * This class provides a simple set of methods to
54  * insert/update/delete records in a database.
55  */

56 public class PasswordSQL extends CreamAction
57 {
58
59     /**
60      * Update a record in the database with the
61      * information present in the web form.
62      *
63      * Again, this is merely an example. The data
64      * should be checked before being allowed
65      * into the database.
66      */

67     public void doUpdate(RunData data, Context context)
68         throws Exception JavaDoc
69     {
70
71         Criteria crit = new Criteria();
72         crit.add(TurbineUserPeer.LOGIN_NAME, data.getUser().getName());
73
74         TurbineUser entry = (TurbineUser) TurbineUserPeer.doSelect(crit).get(0);
75
76         User myUser= data.getUser();
77 // UserManager myManager= data.getUser();
78

79         String JavaDoc entryPass= new String JavaDoc(entry.getPassword());
80         String JavaDoc oldPass= new String JavaDoc(data.getParameters().getString("oldpassword"));
81         String JavaDoc newPass= new String JavaDoc(data.getParameters().getString("newpassword1"));
82         
83 // try{
84
// UserManager.changePassword(myUser, oldPass, newPass);
85

86 // }catch (PasswordMismatchException e){
87

88 // data.setMessage("Sorry, wrong old password!");
89
// this.setTemplate( data, "CreamError.vm");
90
// }
91

92         if (entryPass.equalsIgnoreCase(oldPass)){
93             entry.setPassword(newPass);
94             
95             entry.setModified(true);
96             entry.setNew(false);
97             entry.save();
98
99             myUser.setPassword(newPass);
100
101         }else{
102             
103             data.setMessage("Sorry, wrong old password!");
104             this.setTemplate( data, "CreamError.vm");
105         }
106
107     }
108
109     protected boolean isAuthorized( RunData data ) throws Exception JavaDoc
110     {
111         boolean isAuthorized = false;
112
113         if (data.getUser().hasLoggedIn())
114         {
115             isAuthorized = true;
116         }
117         else
118         {
119             data.setMessage("Sorry, you don't have permission for this operation!");
120             this.setTemplate( data, "CreamError.vm");
121
122             isAuthorized = false;
123         }
124
125         return isAuthorized;
126     }
127
128 }
129
Popular Tags