Source code: org/acs/damsel/client/edit/ChangePasswordAdminAction.java
1 package org.acs.damsel.client.edit;
2
3 import org.apache.struts.action.*;
4 import javax.servlet.http.*;
5 import org.acs.damsel.client.ClientApp;
6 import org.acs.damsel.srvr.user.*;
7 import org.acs.damsel.srvr.db.*;
8 import java.sql.*;
9
10 public class ChangePasswordAdminAction extends Action {
11 public ActionForward execute(ActionMapping actionMapping,
12 ActionForm actionForm,
13 HttpServletRequest httpServletRequest,
14 HttpServletResponse httpServletResponse) {
15 /**@todo: complete the business logic here, this is just a skeleton.*/
16 ChangePasswordAdminForm changePasswordAdminForm = (ChangePasswordAdminForm) actionForm;
17 ActionErrors errors = new ActionErrors();
18 String newPassword = changePasswordAdminForm.getNewPassword();
19 String newPassword2 = changePasswordAdminForm.getNewPassword2();
20 String oldHash = null;
21 String newHash = null;
22
23 // get the user object from the session
24 EditUserAdminForm euaf = (EditUserAdminForm) httpServletRequest.getSession().getAttribute("editUserAdminForm");
25 String userName = euaf.getUserSelect();
26 try {
27 User user = ClientApp.instance().getUserMgr().getUserFromName(userName);
28
29 // if we can't hash the passwords for some reason, fail
30 newHash = DBUtils.instance().hash(newPassword);
31
32 // if the new password doesn't match the reentered new password, fail
33 if(!newPassword.equals(newPassword2)) {
34 errors.add("password", new ActionError("passwords.dont.match"));
35 this.saveErrors(httpServletRequest, errors);
36 return (actionMapping.findForward("failure"));
37 }
38
39 // finally, if updating doesn't work, fail
40 user.setPassword(newHash);
41
42 AssetDB.instance().updateUser(user);
43 }
44 catch (SQLException ex1) {
45 return (actionMapping.findForward("failure"));
46 }
47
48 // since we've only been playing with the user object from the session,
49 // we don't have to worry about setting the user object again
50 return (actionMapping.findForward("success"));
51 }
52
53 }