1 16 17 package org.apache.jetspeed.modules.actions; 18 19 import org.apache.jetspeed.services.JetspeedSecurity; 21 import org.apache.jetspeed.services.logging.JetspeedLogFactoryService; 22 import org.apache.jetspeed.services.logging.JetspeedLogger; 23 import org.apache.jetspeed.services.resources.JetspeedResources; 24 import org.apache.jetspeed.om.security.JetspeedUser; 25 import org.apache.jetspeed.services.rundata.JetspeedRunData; 26 import org.apache.jetspeed.services.Profiler; 27 28 import org.apache.turbine.modules.Action; 30 import org.apache.turbine.modules.ActionLoader; 31 import org.apache.turbine.services.localization.Localization; 32 import org.apache.turbine.util.RunData; 33 import org.apache.turbine.TurbineConstants; 34 35 41 public class ChangePassword extends Action 42 { 43 44 47 private static final JetspeedLogger logger = JetspeedLogFactoryService.getLogger(ChangePassword.class.getName()); 48 49 public void doPerform(RunData rundata) throws Exception 50 { 51 52 String cancelBtn = rundata.getParameters().getString(Localization.getString(rundata, "PASSWORDFORM_CANCEL")); 53 String username = rundata.getParameters().getString("username" , ""); 54 String oldPassword = JetspeedSecurity.convertPassword(rundata.getParameters().getString("old_password" , "")); 55 String password = JetspeedSecurity.convertPassword(rundata.getParameters().getString("password", "")); 56 String password2 = JetspeedSecurity.convertPassword(rundata.getParameters().getString("password_confirm", "")); 57 58 if (cancelBtn != null && cancelBtn.equalsIgnoreCase(Localization.getString(rundata, "PASSWORDFORM_CANCEL"))) 63 { 64 return; 65 } 66 67 String returnTemplate = JetspeedResources.getString(JetspeedResources.CHANGE_PASSWORD_TEMPLATE, "ChangePassword"); 68 69 try 70 { 71 72 JetspeedUser user = JetspeedSecurity.getUser(username); 73 74 if (!password.equals(password2)) 75 { 76 rundata.setMessage(Localization.getString(rundata, "UPDATEACCOUNT_PWNOTMATCH")); 77 rundata.setScreenTemplate(returnTemplate); 78 return; 79 } 80 81 if (password.equals(oldPassword)) 82 { 83 rundata.setMessage(Localization.getString(rundata, "PASSWORDFORM_THESAME_MSG")); 84 rundata.setScreenTemplate(returnTemplate); 85 return; 86 } 87 88 JetspeedSecurity.changePassword(user, oldPassword, password); 90 rundata.setMessage(Localization.getString(rundata, "PASSWORDFORM_DONE")); 91 92 rundata.getParameters().setString("username", username); 94 rundata.getParameters().setString("password", password); 95 String userRequestsRememberMe = rundata.getParameters().getString("rememberme"); 96 rundata.getParameters().setString("rememberme", userRequestsRememberMe); 97 ActionLoader.getInstance().getInstance( 98 JetspeedResources.getString(TurbineConstants.ACTION_LOGIN) 99 ).doPerform(rundata); 100 101 JetspeedRunData jdata = (JetspeedRunData) rundata; 103 jdata.setProfile(Profiler.getProfile(jdata)); 104 105 } 106 catch (Exception e) 107 { 108 logger.error("Exception", e); 109 rundata.setMessage(e.getMessage() != null ? e.getMessage() : e.toString()); 110 rundata.setScreenTemplate(returnTemplate); 111 } 112 } 113 114 } 115 | Popular Tags |