1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 package info.magnolia.cms.gui.dialog;
35
36 import info.magnolia.cms.gui.control.ControlImpl;
37 import info.magnolia.cms.gui.control.Password;
38 import info.magnolia.cms.gui.misc.CssConstants;
39
40 import java.io.IOException;
41 import java.io.Writer;
42
43 import org.apache.commons.codec.binary.Base64;
44 import org.apache.commons.lang.StringUtils;
45 import org.slf4j.Logger;
46 import org.slf4j.LoggerFactory;
47
48
49
50
51
52
53 public class DialogPassword extends DialogBox {
54
55 private static final Logger log = LoggerFactory.getLogger(DialogPassword.class);
56
57
58
59
60 public void drawHtml(Writer out) throws IOException {
61 Password control = new Password(this.getName(), this.getValue());
62 if (this.getConfigValue("saveInfo").equals("false")) {
63 control.setSaveInfo(false);
64 }
65 control.setCssClass(CssConstants.CSSCLASS_EDIT);
66 control.setCssStyles("width", this.getConfigValue("width", "100%"));
67 control.setEncoding(ControlImpl.ENCODING_BASE64);
68 if (this.getConfigValue("onchange", null) != null) {
69 control.setEvent("onchange", this.getConfigValue("onchange"));
70 }
71 this.drawHtmlPre(out);
72 out.write(control.getHtml());
73 if (this.getConfigValue("verification", "true").equals("true")) {
74 Password control2 = new Password(this.getName() + "_verification", StringUtils.EMPTY);
75
76
77 control2.setSaveInfo(false);
78 control2.setCssClass(CssConstants.CSSCLASS_EDIT);
79 control2.setCssStyles("width",
80 this.getConfigValue("width", "100%"));
81 control2.setEvent("onchange",
82 "mgnlDialogPasswordVerify('" + this.getName() + "')");
83
84 out.write("<div class=\""
85 + CssConstants.CSSCLASS_DESCRIPTION
86 + "\">"
87 + getMessage("dialog.password.verify")
88 + "</div>");
89 out.write(control2.getHtml());
90 }
91 this.drawHtmlPost(out);
92 }
93
94 public boolean validate() {
95 if (super.getConfigValue("verification", "true").equals("true")) {
96 String newP = super.getRequest().getParameter(getName());
97 String verP = super.getRequest().getParameter(getName() + "_verification");
98 String oriP = this.getStorageNode().getNodeData(getName()).getString();
99 if (Base64.isArrayByteBase64(oriP.getBytes())) {
100 oriP = new String(Base64.decodeBase64(oriP.getBytes()));
101 }
102
103
104 if (!(newP.trim().length() == 0 && verP.length() == 0) && !newP.equals(verP)) {
105 setValidationMessage(getMessage("dialog.password.failed.js"));
106 return false;
107 }
108 }
109 return super.validate();
110 }
111
112
113 }