1 package org.campware.cream.modules.actions; 2 3 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 56 public class PasswordSQL extends CreamAction 57 { 58 59 67 public void doUpdate(RunData data, Context context) 68 throws Exception 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 79 String entryPass= new String (entry.getPassword()); 80 String oldPass= new String (data.getParameters().getString("oldpassword")); 81 String newPass= new String (data.getParameters().getString("newpassword1")); 82 83 86 88 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 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 |