01: package org.contineo.web.settings;
02:
03: import org.apache.commons.logging.Log;
04: import org.apache.commons.logging.LogFactory;
05:
06: import org.contineo.core.CryptBean;
07: import org.contineo.core.security.User;
08: import org.contineo.core.security.dao.UserDAO;
09:
10: import org.contineo.util.Context;
11:
12: import org.contineo.web.SessionManagement;
13: import org.contineo.web.i18n.Messages;
14:
15: /**
16: * Change password form
17: *
18: * @author Marco Meschieri
19: * @version $Id:$
20: * @since ###release###
21: */
22: public class PasswordForm {
23: protected static Log log = LogFactory.getLog(PasswordForm.class);
24: String oldPassword;
25: String password;
26: String repass;
27:
28: public PasswordForm() {
29: oldPassword = "";
30: password = "";
31: repass = "";
32: }
33:
34: public String getOldPassword() {
35: return oldPassword;
36: }
37:
38: public String getPassword() {
39: return password;
40: }
41:
42: public String getRepass() {
43: return repass;
44: }
45:
46: public void setOldPassword(String opwd) {
47: oldPassword = opwd;
48: }
49:
50: public void setPassword(String npwd) {
51: password = npwd;
52: }
53:
54: public void setRepass(String re) {
55: repass = re;
56: }
57:
58: public String save() {
59: if (SessionManagement.isValid()) {
60: try {
61: if (password.equals(repass)) {
62: String username = SessionManagement.getUsername();
63: UserDAO udao = (UserDAO) Context.getInstance()
64: .getBean(UserDAO.class);
65: User user = udao.findByPrimaryKey(username);
66: String opwd = CryptBean.cryptString(oldPassword);
67:
68: if (opwd.equals(user.getPassword())) {
69: user.setDecodedPassword(password);
70: udao.store(user);
71: Messages
72: .addLocalizedInfo("msg.action.passwordchanged");
73: } else {
74: Messages
75: .addLocalizedError("errors.action.password.mismatch");
76: }
77: } else {
78: Messages.addLocalizedError("errors.val.password");
79: }
80: } catch (Exception e) {
81: log.error(e.getMessage(), e);
82: Messages
83: .addLocalizedError("errors.action.changepassword");
84: }
85:
86: return null;
87: } else {
88: return "login";
89: }
90: }
91: }
|