1 |
a60842d7
|
n.hoffmann
|
// $Id$
|
2 |
|
|
/**
|
3 |
|
|
* Copyright (C) 2007 EDIT
|
4 |
6410237a
|
Andreas Kohlbecker
|
* European Distributed Institute of Taxonomy
|
5 |
a60842d7
|
n.hoffmann
|
* http://www.e-taxonomy.eu
|
6 |
6410237a
|
Andreas Kohlbecker
|
*
|
7 |
a60842d7
|
n.hoffmann
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
8 |
|
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
9 |
|
|
*/
|
10 |
|
|
|
11 |
78222507
|
n.hoffmann
|
package eu.etaxonomy.taxeditor.ui.password;
|
12 |
a60842d7
|
n.hoffmann
|
|
13 |
|
|
import org.eclipse.jface.dialogs.IInputValidator;
|
14 |
|
|
import org.eclipse.swt.SWT;
|
15 |
|
|
import org.eclipse.swt.events.ModifyEvent;
|
16 |
|
|
import org.eclipse.swt.events.ModifyListener;
|
17 |
|
|
import org.eclipse.swt.widgets.Composite;
|
18 |
|
|
import org.eclipse.swt.widgets.Text;
|
19 |
|
|
|
20 |
|
|
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
|
21 |
|
|
import eu.etaxonomy.cdm.api.service.IUserService;
|
22 |
|
|
import eu.etaxonomy.cdm.model.common.User;
|
23 |
|
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
24 |
78222507
|
n.hoffmann
|
import eu.etaxonomy.taxeditor.ui.element.AbstractCdmEntityWizardPage;
|
25 |
|
|
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
|
26 |
dacb59c9
|
Patric Plitzner
|
import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
|
27 |
23783f7a
|
n.hoffmann
|
import eu.etaxonomy.taxeditor.ui.element.LayoutConstants;
|
28 |
78222507
|
n.hoffmann
|
import eu.etaxonomy.taxeditor.ui.element.TextWithLabelElement;
|
29 |
a60842d7
|
n.hoffmann
|
import eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailElement;
|
30 |
|
|
|
31 |
|
|
/**
|
32 |
|
|
* <p>UserWizardPage class.</p>
|
33 |
|
|
*
|
34 |
|
|
* @author n.hoffmann
|
35 |
|
|
* @created 02.07.2009
|
36 |
|
|
* @version 1.0
|
37 |
|
|
*/
|
38 |
|
|
public class PasswordWizardPage extends AbstractCdmEntityWizardPage<User> implements ModifyListener{
|
39 |
|
|
|
40 |
|
|
/** Constant <code>NAME="USER_WIZARD_PAGE"</code> */
|
41 |
|
|
public static final String NAME = "USER_WIZARD_PAGE";
|
42 |
6410237a
|
Andreas Kohlbecker
|
|
43 |
a60842d7
|
n.hoffmann
|
private TextWithLabelElement text_oldPassword;
|
44 |
|
|
private TextWithLabelElement text_password;
|
45 |
|
|
private TextWithLabelElement text_passwordRepeat;
|
46 |
6410237a
|
Andreas Kohlbecker
|
private final PasswordValidator passwordValidator;
|
47 |
a60842d7
|
n.hoffmann
|
|
48 |
6410237a
|
Andreas Kohlbecker
|
private final UniqueUserNameValidator uniqueUsernameValidator;
|
49 |
23783f7a
|
n.hoffmann
|
|
50 |
a60842d7
|
n.hoffmann
|
/**
|
51 |
|
|
* @param formFactory
|
52 |
|
|
* @param conversation
|
53 |
|
|
* @param entity
|
54 |
|
|
*/
|
55 |
|
|
protected PasswordWizardPage(CdmFormFactory formFactory,
|
56 |
|
|
ConversationHolder conversation, User entity) {
|
57 |
|
|
super(formFactory, conversation, entity);
|
58 |
6410237a
|
Andreas Kohlbecker
|
|
59 |
a60842d7
|
n.hoffmann
|
passwordValidator = new PasswordValidator();
|
60 |
23783f7a
|
n.hoffmann
|
uniqueUsernameValidator = new UniqueUserNameValidator();
|
61 |
a60842d7
|
n.hoffmann
|
}
|
62 |
|
|
|
63 |
|
|
/* (non-Javadoc)
|
64 |
|
|
* @see eu.etaxonomy.taxeditor.ui.forms.AbstractCdmEntityWizardPage#createControl(org.eclipse.swt.widgets.Composite)
|
65 |
|
|
*/
|
66 |
|
|
@Override
|
67 |
|
|
public void createControl(Composite parent) {
|
68 |
|
|
Composite control = formFactory.createComposite(parent);
|
69 |
23783f7a
|
n.hoffmann
|
control.setLayoutData(LayoutConstants.FILL());
|
70 |
6410237a
|
Andreas Kohlbecker
|
|
71 |
a60842d7
|
n.hoffmann
|
setPageComplete(false);
|
72 |
6410237a
|
Andreas Kohlbecker
|
|
73 |
23783f7a
|
n.hoffmann
|
control.setLayout(LayoutConstants.LAYOUT(2, false));
|
74 |
a60842d7
|
n.hoffmann
|
WizardPageRootElement rootElement = new WizardPageRootElement(formFactory, control, getConversationHolder());
|
75 |
6410237a
|
Andreas Kohlbecker
|
|
76 |
|
|
if(isChangingOwnPassword()) {
|
77 |
|
|
text_oldPassword = formFactory.createTextWithLabelElement(rootElement, "Old Password", null, SWT.PASSWORD);
|
78 |
0c8d552e
|
n.hoffmann
|
}
|
79 |
a60842d7
|
n.hoffmann
|
text_password = formFactory.createTextWithLabelElement(rootElement, "New Password", null, SWT.PASSWORD);
|
80 |
|
|
text_passwordRepeat = formFactory.createTextWithLabelElement(rootElement, "Repeat Password", null, SWT.PASSWORD);
|
81 |
6410237a
|
Andreas Kohlbecker
|
|
82 |
a60842d7
|
n.hoffmann
|
((Text)text_passwordRepeat.getMainControl()).addModifyListener(this);
|
83 |
6410237a
|
Andreas Kohlbecker
|
|
84 |
a60842d7
|
n.hoffmann
|
setControl(control);
|
85 |
|
|
}
|
86 |
6410237a
|
Andreas Kohlbecker
|
|
87 |
|
|
protected boolean isChangingOwnPassword() {
|
88 |
|
|
return getEntity() != null && getEntity().getUsername().equals(CdmStore.getCurrentAuthentiation().getName());
|
89 |
|
|
}
|
90 |
|
|
|
91 |
|
|
|
92 |
a60842d7
|
n.hoffmann
|
/* (non-Javadoc)
|
93 |
|
|
* @see eu.etaxonomy.taxeditor.ui.forms.AbstractCdmEntityWizardPage#createElement(eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement)
|
94 |
|
|
*/
|
95 |
|
|
@Override
|
96 |
|
|
public AbstractCdmDetailElement<User> createElement(
|
97 |
|
|
ICdmFormElement rootElement) {
|
98 |
|
|
// not used
|
99 |
|
|
return null;
|
100 |
|
|
}
|
101 |
6410237a
|
Andreas Kohlbecker
|
|
102 |
a60842d7
|
n.hoffmann
|
/* (non-Javadoc)
|
103 |
|
|
* @see org.eclipse.swt.events.ModifyListener#modifyText(org.eclipse.swt.events.ModifyEvent)
|
104 |
|
|
*/
|
105 |
|
|
/** {@inheritDoc} */
|
106 |
6410237a
|
Andreas Kohlbecker
|
@Override
|
107 |
|
|
public void modifyText(ModifyEvent e) {
|
108 |
a60842d7
|
n.hoffmann
|
validate();
|
109 |
|
|
}
|
110 |
6410237a
|
Andreas Kohlbecker
|
|
111 |
a60842d7
|
n.hoffmann
|
private void validate(){
|
112 |
|
|
String message;
|
113 |
6410237a
|
Andreas Kohlbecker
|
|
114 |
a60842d7
|
n.hoffmann
|
if((message = passwordValidator.passwordsMatch(text_password.getText(), text_passwordRepeat.getText())) != null){
|
115 |
|
|
// pass
|
116 |
|
|
}
|
117 |
|
|
else if((message = passwordValidator.isValid(text_password.getText())) != null){
|
118 |
|
|
// pass
|
119 |
|
|
}
|
120 |
6410237a
|
Andreas Kohlbecker
|
|
121 |
|
|
setErrorMessage(message);
|
122 |
a60842d7
|
n.hoffmann
|
}
|
123 |
6410237a
|
Andreas Kohlbecker
|
|
124 |
a60842d7
|
n.hoffmann
|
private class UniqueUserNameValidator implements IInputValidator{
|
125 |
|
|
|
126 |
|
|
private static final String USER_EXISTS = "Username already exists";
|
127 |
|
|
private static final String NAME_TO_SHORT = "Username is empty";
|
128 |
6410237a
|
Andreas Kohlbecker
|
|
129 |
a60842d7
|
n.hoffmann
|
/* (non-Javadoc)
|
130 |
|
|
* @see org.eclipse.jface.dialogs.IInputValidator#isValid(java.lang.String)
|
131 |
|
|
*/
|
132 |
6410237a
|
Andreas Kohlbecker
|
@Override
|
133 |
|
|
public String isValid(String newText) {
|
134 |
a60842d7
|
n.hoffmann
|
// query for username
|
135 |
|
|
if(newText.length() < 1){
|
136 |
|
|
setPageComplete(false);
|
137 |
|
|
return NAME_TO_SHORT;
|
138 |
|
|
}
|
139 |
|
|
if(CdmStore.getService(IUserService.class).userExists(newText)){
|
140 |
|
|
setPageComplete(false);
|
141 |
|
|
return USER_EXISTS;
|
142 |
|
|
}
|
143 |
6410237a
|
Andreas Kohlbecker
|
|
144 |
a60842d7
|
n.hoffmann
|
setPageComplete(true);
|
145 |
|
|
return null;
|
146 |
|
|
}
|
147 |
|
|
}
|
148 |
6410237a
|
Andreas Kohlbecker
|
|
149 |
a60842d7
|
n.hoffmann
|
private class PasswordValidator implements IInputValidator{
|
150 |
|
|
|
151 |
|
|
private static final int PW_MIN_LENGTH = 5;
|
152 |
6410237a
|
Andreas Kohlbecker
|
|
153 |
a60842d7
|
n.hoffmann
|
private static final String TO_SHORT = "Password has to have at least " + PW_MIN_LENGTH + " characters";
|
154 |
|
|
private static final String NO_MATCH = "The passwords do not match";
|
155 |
6410237a
|
Andreas Kohlbecker
|
|
156 |
a60842d7
|
n.hoffmann
|
/* (non-Javadoc)
|
157 |
|
|
* @see org.eclipse.jface.dialogs.IInputValidator#isValid(java.lang.String)
|
158 |
|
|
*/
|
159 |
6410237a
|
Andreas Kohlbecker
|
@Override
|
160 |
|
|
public String isValid(String newText) {
|
161 |
a60842d7
|
n.hoffmann
|
if(newText.length() < PW_MIN_LENGTH){
|
162 |
|
|
setPageComplete(false);
|
163 |
|
|
return TO_SHORT;
|
164 |
|
|
}
|
165 |
6410237a
|
Andreas Kohlbecker
|
|
166 |
a60842d7
|
n.hoffmann
|
setPageComplete(true);
|
167 |
|
|
return null;
|
168 |
|
|
}
|
169 |
6410237a
|
Andreas Kohlbecker
|
|
170 |
a60842d7
|
n.hoffmann
|
public String passwordsMatch(String password1, String password2){
|
171 |
|
|
|
172 |
|
|
if(! password1.equals(password2)){
|
173 |
|
|
setPageComplete(false);
|
174 |
|
|
return NO_MATCH;
|
175 |
|
|
}
|
176 |
6410237a
|
Andreas Kohlbecker
|
|
177 |
a60842d7
|
n.hoffmann
|
setPageComplete(true);
|
178 |
|
|
return null;
|
179 |
|
|
}
|
180 |
6410237a
|
Andreas Kohlbecker
|
|
181 |
a60842d7
|
n.hoffmann
|
}
|
182 |
|
|
|
183 |
|
|
/**
|
184 |
|
|
* @return
|
185 |
|
|
*/
|
186 |
|
|
public String getOldPassword() {
|
187 |
|
|
return text_oldPassword.getText();
|
188 |
|
|
}
|
189 |
|
|
|
190 |
|
|
/**
|
191 |
|
|
* @return
|
192 |
|
|
*/
|
193 |
|
|
public String getNewPassword() {
|
194 |
|
|
return text_password.getText();
|
195 |
|
|
}
|
196 |
|
|
}
|