Revision 6410237a
Added by Andreas Kohlbecker about 10 years ago
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/password/PasswordWizardPage.java | ||
---|---|---|
1 | 1 |
// $Id$ |
2 | 2 |
/** |
3 | 3 |
* Copyright (C) 2007 EDIT |
4 |
* European Distributed Institute of Taxonomy
|
|
4 |
* European Distributed Institute of Taxonomy |
|
5 | 5 |
* http://www.e-taxonomy.eu |
6 |
*
|
|
6 |
* |
|
7 | 7 |
* The contents of this file are subject to the Mozilla Public License Version 1.1 |
8 | 8 |
* See LICENSE.TXT at the top of this package for the full license terms. |
9 | 9 |
*/ |
... | ... | |
39 | 39 |
|
40 | 40 |
/** Constant <code>NAME="USER_WIZARD_PAGE"</code> */ |
41 | 41 |
public static final String NAME = "USER_WIZARD_PAGE"; |
42 |
|
|
42 |
|
|
43 | 43 |
private TextWithLabelElement text_oldPassword; |
44 | 44 |
private TextWithLabelElement text_password; |
45 | 45 |
private TextWithLabelElement text_passwordRepeat; |
46 |
private PasswordValidator passwordValidator; |
|
46 |
private final PasswordValidator passwordValidator;
|
|
47 | 47 |
|
48 |
private UniqueUserNameValidator uniqueUsernameValidator; |
|
48 |
private final UniqueUserNameValidator uniqueUsernameValidator;
|
|
49 | 49 |
|
50 | 50 |
/** |
51 | 51 |
* @param formFactory |
... | ... | |
55 | 55 |
protected PasswordWizardPage(CdmFormFactory formFactory, |
56 | 56 |
ConversationHolder conversation, User entity) { |
57 | 57 |
super(formFactory, conversation, entity); |
58 |
|
|
58 |
|
|
59 | 59 |
passwordValidator = new PasswordValidator(); |
60 | 60 |
uniqueUsernameValidator = new UniqueUserNameValidator(); |
61 | 61 |
} |
... | ... | |
67 | 67 |
public void createControl(Composite parent) { |
68 | 68 |
Composite control = formFactory.createComposite(parent); |
69 | 69 |
control.setLayoutData(LayoutConstants.FILL()); |
70 |
|
|
70 |
|
|
71 | 71 |
setPageComplete(false); |
72 |
|
|
72 |
|
|
73 | 73 |
control.setLayout(LayoutConstants.LAYOUT(2, false)); |
74 | 74 |
WizardPageRootElement rootElement = new WizardPageRootElement(formFactory, control, getConversationHolder()); |
75 |
|
|
76 |
if(!CdmStore.getLoginManager().isAdmin()){
|
|
77 |
text_oldPassword = formFactory.createTextWithLabelElement(rootElement, "Old Password", null, SWT.PASSWORD);
|
|
75 |
|
|
76 |
if(isChangingOwnPassword()) {
|
|
77 |
text_oldPassword = formFactory.createTextWithLabelElement(rootElement, "Old Password", null, SWT.PASSWORD);
|
|
78 | 78 |
} |
79 | 79 |
text_password = formFactory.createTextWithLabelElement(rootElement, "New Password", null, SWT.PASSWORD); |
80 | 80 |
text_passwordRepeat = formFactory.createTextWithLabelElement(rootElement, "Repeat Password", null, SWT.PASSWORD); |
81 |
|
|
81 |
|
|
82 | 82 |
((Text)text_passwordRepeat.getMainControl()).addModifyListener(this); |
83 |
|
|
83 |
|
|
84 | 84 |
setControl(control); |
85 | 85 |
} |
86 |
|
|
87 |
|
|
86 |
|
|
87 |
protected boolean isChangingOwnPassword() { |
|
88 |
return getEntity() != null && getEntity().getUsername().equals(CdmStore.getCurrentAuthentiation().getName()); |
|
89 |
} |
|
90 |
|
|
91 |
|
|
88 | 92 |
/* (non-Javadoc) |
89 | 93 |
* @see eu.etaxonomy.taxeditor.ui.forms.AbstractCdmEntityWizardPage#createElement(eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement) |
90 | 94 |
*/ |
... | ... | |
94 | 98 |
// not used |
95 | 99 |
return null; |
96 | 100 |
} |
97 |
|
|
101 |
|
|
98 | 102 |
/* (non-Javadoc) |
99 | 103 |
* @see org.eclipse.swt.events.ModifyListener#modifyText(org.eclipse.swt.events.ModifyEvent) |
100 | 104 |
*/ |
101 | 105 |
/** {@inheritDoc} */ |
102 |
public void modifyText(ModifyEvent e) { |
|
106 |
@Override |
|
107 |
public void modifyText(ModifyEvent e) { |
|
103 | 108 |
validate(); |
104 | 109 |
} |
105 |
|
|
110 |
|
|
106 | 111 |
private void validate(){ |
107 | 112 |
String message; |
108 |
|
|
113 |
|
|
109 | 114 |
if((message = passwordValidator.passwordsMatch(text_password.getText(), text_passwordRepeat.getText())) != null){ |
110 | 115 |
// pass |
111 | 116 |
} |
112 | 117 |
else if((message = passwordValidator.isValid(text_password.getText())) != null){ |
113 | 118 |
// pass |
114 | 119 |
} |
115 |
|
|
116 |
setErrorMessage(message);
|
|
120 |
|
|
121 |
setErrorMessage(message); |
|
117 | 122 |
} |
118 |
|
|
123 |
|
|
119 | 124 |
private class UniqueUserNameValidator implements IInputValidator{ |
120 | 125 |
|
121 | 126 |
private static final String USER_EXISTS = "Username already exists"; |
122 | 127 |
private static final String NAME_TO_SHORT = "Username is empty"; |
123 |
|
|
128 |
|
|
124 | 129 |
/* (non-Javadoc) |
125 | 130 |
* @see org.eclipse.jface.dialogs.IInputValidator#isValid(java.lang.String) |
126 | 131 |
*/ |
127 |
public String isValid(String newText) { |
|
132 |
@Override |
|
133 |
public String isValid(String newText) { |
|
128 | 134 |
// query for username |
129 | 135 |
if(newText.length() < 1){ |
130 | 136 |
setPageComplete(false); |
... | ... | |
134 | 140 |
setPageComplete(false); |
135 | 141 |
return USER_EXISTS; |
136 | 142 |
} |
137 |
|
|
143 |
|
|
138 | 144 |
setPageComplete(true); |
139 | 145 |
return null; |
140 | 146 |
} |
141 | 147 |
} |
142 |
|
|
148 |
|
|
143 | 149 |
private class PasswordValidator implements IInputValidator{ |
144 | 150 |
|
145 | 151 |
private static final int PW_MIN_LENGTH = 5; |
146 |
|
|
152 |
|
|
147 | 153 |
private static final String TO_SHORT = "Password has to have at least " + PW_MIN_LENGTH + " characters"; |
148 | 154 |
private static final String NO_MATCH = "The passwords do not match"; |
149 |
|
|
155 |
|
|
150 | 156 |
/* (non-Javadoc) |
151 | 157 |
* @see org.eclipse.jface.dialogs.IInputValidator#isValid(java.lang.String) |
152 | 158 |
*/ |
153 |
public String isValid(String newText) { |
|
159 |
@Override |
|
160 |
public String isValid(String newText) { |
|
154 | 161 |
if(newText.length() < PW_MIN_LENGTH){ |
155 | 162 |
setPageComplete(false); |
156 | 163 |
return TO_SHORT; |
157 | 164 |
} |
158 |
|
|
165 |
|
|
159 | 166 |
setPageComplete(true); |
160 | 167 |
return null; |
161 | 168 |
} |
162 |
|
|
169 |
|
|
163 | 170 |
public String passwordsMatch(String password1, String password2){ |
164 | 171 |
|
165 | 172 |
if(! password1.equals(password2)){ |
166 | 173 |
setPageComplete(false); |
167 | 174 |
return NO_MATCH; |
168 | 175 |
} |
169 |
|
|
176 |
|
|
170 | 177 |
setPageComplete(true); |
171 | 178 |
return null; |
172 | 179 |
} |
173 |
|
|
180 |
|
|
174 | 181 |
} |
175 | 182 |
|
176 | 183 |
/** |
Also available in: Unified diff
taxeditor part of fix for #4121 (Changing password does not work)