001/* 002 * This library is part of OpenCms - 003 * the Open Source Content Management System 004 * 005 * Copyright (c) Alkacon Software GmbH & Co. KG (http://www.alkacon.com) 006 * 007 * This library is free software; you can redistribute it and/or 008 * modify it under the terms of the GNU Lesser General Public 009 * License as published by the Free Software Foundation; either 010 * version 2.1 of the License, or (at your option) any later version. 011 * 012 * This library is distributed in the hope that it will be useful, 013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 015 * Lesser General Public License for more details. 016 * 017 * For further information about Alkacon Software, please see the 018 * company website: http://www.alkacon.com 019 * 020 * For further information about OpenCms, please see the 021 * project website: http://www.opencms.org 022 * 023 * You should have received a copy of the GNU Lesser General Public 024 * License along with this library; if not, write to the Free Software 025 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 026 */ 027 028package org.opencms.ui.login; 029 030import org.opencms.main.OpenCms; 031import org.opencms.ui.A_CmsUI; 032import org.opencms.ui.CmsVaadinUtils; 033import org.opencms.ui.components.CmsNewPasswordField; 034import org.opencms.ui.util.CmsStyleVariable; 035import org.opencms.util.CmsStringUtil; 036 037import java.util.Locale; 038 039import com.vaadin.server.UserError; 040import com.vaadin.ui.CssLayout; 041import com.vaadin.v7.ui.Label; 042import com.vaadin.v7.ui.PasswordField; 043import com.vaadin.v7.ui.VerticalLayout; 044 045/** 046 * The change password form.<p> 047 */ 048public class CmsPasswordForm extends VerticalLayout { 049 050 /** The serial version id. */ 051 private static final long serialVersionUID = 773244283339376105L; 052 053 /** Label with additional text. */ 054 private Label m_additionalText; 055 056 /**Label for the head message.*/ 057 private Label m_headMessage; 058 059 /** Field for the old password. */ 060 private PasswordField m_oldPasswordField; 061 062 /** Old password style variable. */ 063 private CmsStyleVariable m_oldPasswordStyle; 064 065 /** Layout wrapping the old password field. */ 066 private CssLayout m_oldPasswordWrapper; 067 068 /** Password 1 style variable. */ 069 private CmsStyleVariable m_password1Style; 070 071 /** Layout wrapping the password 1 field. */ 072 private CssLayout m_password1Wrapper; 073 074 /** Password 2 style variable. */ 075 private CmsStyleVariable m_password2Style; 076 077 /** Layout wrapping the password 2 field. */ 078 private CssLayout m_password2Wrapper; 079 080 /** First password field. */ 081 private CmsNewPasswordField m_passwordField1; 082 083 /** Second password field. */ 084 private CmsNewPasswordField m_passwordField2; 085 086 /** Label to display the security hint. */ 087 private Label m_securityHint; 088 089 /** 090 * Constructor.<p> 091 */ 092 public CmsPasswordForm() { 093 094 this(A_CmsUI.get().getLocale()); 095 } 096 097 /** 098 * Constructor.<p> 099 * 100 * @param locale the user locale 101 */ 102 public CmsPasswordForm(Locale locale) { 103 104 CmsVaadinUtils.readAndLocalizeDesign(this, OpenCms.getWorkplaceManager().getMessages(locale), null); 105 m_securityHint.setVisible(false); 106 m_password1Style = new CmsStyleVariable(m_password1Wrapper); 107 m_password2Style = new CmsStyleVariable(m_password2Wrapper); 108 m_oldPasswordStyle = new CmsStyleVariable(m_oldPasswordWrapper); 109 } 110 111 /** 112 * Returns the old password value.<p> 113 * 114 * @return the old password 115 */ 116 public String getOldPassword() { 117 118 return m_oldPasswordField.getValue(); 119 } 120 121 /** 122 * Returns the old password field.<p> 123 * 124 * @return the old password field 125 */ 126 public PasswordField getOldPasswordField() { 127 128 return m_oldPasswordField; 129 } 130 131 /** 132 * Returns the password 1 value.<p> 133 * 134 * @return the password 1 135 */ 136 public String getPassword1() { 137 138 return m_passwordField1.getValue(); 139 } 140 141 /** 142 * Returns the password 1 field.<p> 143 * 144 * @return the password 1 field 145 */ 146 public CmsNewPasswordField getPassword1Field() { 147 148 return m_passwordField1; 149 } 150 151 /** 152 * Returns the password 2 value.<p> 153 * 154 * @return the password 2 155 */ 156 public String getPassword2() { 157 158 return m_passwordField2.getValue(); 159 } 160 161 /** 162 * Returns the password 2 field.<p> 163 * 164 * @return the password 2 field 165 */ 166 public CmsNewPasswordField getPassword2Field() { 167 168 return m_passwordField2; 169 } 170 171 /** 172 * Hides the old password field. 173 */ 174 public void hideOldPassword() { 175 176 m_oldPasswordWrapper.setVisible(false); 177 } 178 179 /** 180 * Displays an additional message.<p> 181 * 182 * @param text the message 183 */ 184 public void setAdditionalText(String text) { 185 186 if (CmsStringUtil.isEmpty(text)) { 187 m_additionalText.setVisible(false); 188 } else { 189 m_additionalText.setValue(text); 190 m_additionalText.setVisible(true); 191 } 192 } 193 194 public void setEnabled(boolean enabled) { 195 196 m_passwordField1.setEnabled(enabled); 197 m_passwordField2.setEnabled(enabled); 198 m_oldPasswordField.setEnabled(enabled); 199 } 200 201 /** 202 * Sets the old password error.<p> 203 * 204 * @param error the error 205 * @param style the style class 206 */ 207 public void setErrorOldPassword(UserError error, String style) { 208 209 m_oldPasswordField.setComponentError(error); 210 m_oldPasswordStyle.setStyle(style); 211 } 212 213 /** 214 * Sets the password 1 error.<p> 215 * 216 * @param error the error 217 * @param style the style class 218 */ 219 public void setErrorPassword1(UserError error, String style) { 220 221 m_passwordField1.setComponentError(error); 222 m_password1Style.setStyle(style); 223 } 224 225 /** 226 * Sets the password 2 error.<p> 227 * 228 * @param error the error 229 * @param style the style class 230 */ 231 public void setErrorPassword2(UserError error, String style) { 232 233 m_passwordField2.setComponentError(error); 234 m_password2Style.setStyle(style); 235 } 236 237 /** 238 * Sets the visibility of the head message.<p> 239 * 240 * @param visible true -> head is visible, false not 241 */ 242 public void setHeaderVisible(boolean visible) { 243 244 m_headMessage.setVisible(false); 245 } 246 247 /** 248 * Sets the security hint.<p> 249 * 250 * @param hint the hint to display 251 */ 252 public void setSecurityHint(String hint) { 253 254 if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(hint)) { 255 m_securityHint.setValue(hint); 256 m_securityHint.setVisible(true); 257 } else { 258 m_securityHint.setVisible(false); 259 } 260 } 261}