diff --git a/web/client/components/manager/users/GroupDialog.jsx b/web/client/components/manager/users/GroupDialog.jsx index 828018579a..844c4d0033 100644 --- a/web/client/components/manager/users/GroupDialog.jsx +++ b/web/client/components/manager/users/GroupDialog.jsx @@ -5,13 +5,6 @@ * This source code is licensed under the BSD-style license found in the * LICENSE file in the root directory of this source tree. */ - /** - * Copyright 2016, GeoSolutions Sas. - * All rights reserved. - * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. - */ const React = require('react'); const UsersTable = require('./UsersTable'); diff --git a/web/client/components/manager/users/UserDialog.jsx b/web/client/components/manager/users/UserDialog.jsx index 244678f17d..498213cf92 100644 --- a/web/client/components/manager/users/UserDialog.jsx +++ b/web/client/components/manager/users/UserDialog.jsx @@ -5,13 +5,6 @@ * This source code is licensed under the BSD-style license found in the * LICENSE file in the root directory of this source tree. */ - /** - * Copyright 2016, GeoSolutions Sas. - * All rights reserved. - * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. - */ const React = require('react'); @@ -43,7 +36,8 @@ const UserDialog = React.createClass({ style: React.PropTypes.object, buttonSize: React.PropTypes.string, inputStyle: React.PropTypes.object, - attributes: React.PropTypes.array + attributes: React.PropTypes.array, + minPasswordSize: React.PropTypes.number }, getDefaultProps() { return { @@ -71,7 +65,8 @@ const UserDialog = React.createClass({ marginBottom: "20px", padding: "5px", border: "1px solid #078AA3" - } + }, + minPasswordSize: 6 }; }, getAttributeValue(name) { @@ -89,7 +84,7 @@ const UserDialog = React.createClass({ if (pw.length === 0) { return null; } - return pw.length > 5 ? "success" : "warning"; + return this.isMainPasswordValid(pw) ? "success" : "warning"; }, renderGeneral() { @@ -103,7 +98,7 @@ const UserDialog = React.createClass({ readOnly={this.props.user && this.props.user.id} style={this.props.inputStyle} onChange={this.handleChange} - value={this.props.user && this.props.user.name}/> + value={this.props.user && this.props.user.name || ""}/> @@ -115,7 +110,7 @@ const UserDialog = React.createClass({ style={this.props.inputStyle} onChange={this.handleChange} /> - + - ); }, renderAttributes() { - return this.props.attributes.map((attr) => { - return ( + return this.props.attributes.map((attr, index) => { + return ( {attr.name} ); + value={this.getAttributeValue(attr.name) || ""} />); }); }, renderSaveButtonContent() { @@ -201,7 +196,7 @@ const UserDialog = React.createClass({
- + } > {this.renderGeneral()} @@ -219,6 +214,14 @@ const UserDialog = React.createClass({
); }, + isMainPasswordValid(password) { + let p = password || this.props.user.newPassword || ""; + // Empty password field will signal the GeoStoreDAO not to change the password + if (p === "") { + return true; + } + return (p.length >= this.props.minPasswordSize) && !(/[^a-zA-Z0-9\!\@\#\$\%\&\*]/.test(p)); + }, isSaving() { return this.props.user && this.props.user.status === "saving"; }, @@ -226,23 +229,12 @@ const UserDialog = React.createClass({ return this.props.user && (this.props.user.status === "saved" || this.props.user.status === "created"); }, isValid() { - let valid = true; let user = this.props.user; - if (!user) return false; - valid = valid && user.name && user.status === "modified" && this.isValidPassword(); - return valid; + return user && user.name && user.status === "modified" && this.isValidPassword(); }, isValidPassword() { - let valid = true; let user = this.props.user; - if (user && user.id) { - if (user.newPassword) { - valid = valid && (user.confirmPassword === user.newPassword); - } - } else { - valid = valid && user && user.newPassword && (user.confirmPassword === user.newPassword); - } - return valid; + return user && this.isMainPasswordValid(user.newPassword) && (user.confirmPassword === user.newPassword); }, handleChange(event) { this.props.onChange(event.target.name, event.target.value); diff --git a/web/client/components/manager/users/__tests__/UserDialog-test.jsx b/web/client/components/manager/users/__tests__/UserDialog-test.jsx index fe09cdcb90..15ba77f9c8 100644 --- a/web/client/components/manager/users/__tests__/UserDialog-test.jsx +++ b/web/client/components/manager/users/__tests__/UserDialog-test.jsx @@ -70,16 +70,24 @@ describe("Test UserDialog Component", () => { , document.getElementById("container")); expect(comp).toExist(); }); - it('Test isValidPAssword', () => { + it('Test isValidPassword', () => { let comp = ReactDOM.render( , document.getElementById("container")); expect(comp).toExist(); + // valid password, wrong confirm comp = ReactDOM.render( - , document.getElementById("container")); + , document.getElementById("container")); expect(comp).toExist(); expect(comp.isValidPassword()).toBe(false); + // Valid password comp = ReactDOM.render( - , document.getElementById("container")); + , document.getElementById("container")); expect(comp.isValidPassword()).toBe(true); + // Invalid password, correct confirm + comp = ReactDOM.render( + , document.getElementById("container")); + expect(comp).toExist(); + expect(comp.isValidPassword()).toBe(false); + }); }); diff --git a/web/client/components/maps/forms/Metadata.jsx b/web/client/components/maps/forms/Metadata.jsx index 208381320a..b6b330197b 100644 --- a/web/client/components/maps/forms/Metadata.jsx +++ b/web/client/components/maps/forms/Metadata.jsx @@ -5,13 +5,6 @@ * This source code is licensed under the BSD-style license found in the * LICENSE file in the root directory of this source tree. */ - /** - * Copyright 2016, GeoSolutions Sas. - * All rights reserved. - * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. - */ const React = require('react'); const {FormControl, FormGroup, ControlLabel} = require('react-bootstrap'); @@ -49,7 +42,6 @@ const Metadata = React.createClass({ {this.props.nameFieldText} {this.props.descriptionFieldText} = this.props.minPasswordSize ? "success" : "error"; - + return this.isMainPasswordValid() ? "success" : "error"; }, renderWarning() { if (!this.state.password) { @@ -66,6 +64,8 @@ const PasswordReset = React.createClass({ let pw = this.state.password; if (pw !== null && pw.length < this.props.minPasswordSize && pw.length > 0) { return ; + } else if (!this.isMainPasswordValid()) { + return ; } else if (pw !== null && pw !== this.state.passwordcheck ) { return ; } @@ -87,7 +87,6 @@ const PasswordReset = React.createClass({
@@ -95,7 +94,6 @@ const PasswordReset = React.createClass({ {this.props.passwordCheckText} ); }, + isMainPasswordValid(password) { + let p = password || this.state.password; + return (p.length >= this.props.minPasswordSize) && !(/[^a-zA-Z0-9\!\@\#\$\%\&\*]/.test(p)); + }, isValid(password, passwordcheck) { let p = password || this.state.password; let p2 = passwordcheck || this.state.passwordcheck; if (!p) { return false; } - return p !== null && p.length >= this.props.minPasswordSize && p === p2; + return p !== null && this.isMainPasswordValid(p) && p === p2; }, changePassword(e) { this.setState({ diff --git a/web/client/components/security/forms/__tests__/PasswordReset-test.jsx b/web/client/components/security/forms/__tests__/PasswordReset-test.jsx index b23f8bf370..327c90d1aa 100644 --- a/web/client/components/security/forms/__tests__/PasswordReset-test.jsx +++ b/web/client/components/security/forms/__tests__/PasswordReset-test.jsx @@ -57,14 +57,19 @@ describe("Test the password reset form component", () => { password2.value = "test2"; ReactTestUtils.Simulate.change(password2); expect(cmp.isValid()).toEqual(false); + // size is < then 6 password2.value = "test"; ReactTestUtils.Simulate.change(password2); - // size is < then 6 + expect(cmp.isValid()).toEqual(false); + // invalid characters + password.value = "testòàè+"; + password2.value = "testòàè+"; + ReactTestUtils.Simulate.change(password2); expect(cmp.isValid()).toEqual(false); // test valid - password.value = "password"; - password2.value = "password"; + password.value = "password123!$&#"; + password2.value = "password123!$&#"; ReactTestUtils.Simulate.change(password); ReactTestUtils.Simulate.change(password2); expect(cmp.isValid()).toEqual(true); diff --git a/web/client/translations/data.de-DE b/web/client/translations/data.de-DE index 41e9e67495..273861b1c1 100644 --- a/web/client/translations/data.de-DE +++ b/web/client/translations/data.de-DE @@ -507,6 +507,7 @@ "retypePwd": "Passwort wiederholen", "passwordMinlenght": "Dein Passwort muss aus mindestens {minSize} Zeichen bestehen", "passwordCheckFail": "Passwörter sind nicht identisch!", + "passwordInvalid": "Ungültiges Passwort", "username": "Benutzername", "password": "Passwort", "passwordChanged": "Passwort geändert", diff --git a/web/client/translations/data.en-US b/web/client/translations/data.en-US index 683f841def..89a9a9cb04 100644 --- a/web/client/translations/data.en-US +++ b/web/client/translations/data.en-US @@ -507,6 +507,7 @@ "retypePwd": "Retype Password", "passwordMinlenght": "Your password must be at least {minSize} character", "passwordCheckFail": "Passwords do not match!", + "passwordInvalid": "Invalid password", "username": "Username", "password": "Password", "passwordChanged": "Password changed", diff --git a/web/client/translations/data.fr-FR b/web/client/translations/data.fr-FR index 2dc03d882e..e4208001fd 100644 --- a/web/client/translations/data.fr-FR +++ b/web/client/translations/data.fr-FR @@ -509,6 +509,7 @@ "retypePwd": "Confirmer le mot de passe", "passwordMinlenght": "Votre mot de passe doit être d'au moins {minSize} caractères", "passwordCheckFail": "Les deux mots de passe ne correspondent pas!", + "passwordInvalid": "Mot de passe incorrect", "username": "Nom d'utilisateur", "password": "Mot de passe", "passwordChanged": "Mot de passe changé", diff --git a/web/client/translations/data.it-IT b/web/client/translations/data.it-IT index 98e8f65c62..8740999a45 100644 --- a/web/client/translations/data.it-IT +++ b/web/client/translations/data.it-IT @@ -507,6 +507,7 @@ "retypePwd": "Conferma Password", "passwordMinlenght": "La password deve essere lunga almeno {minSize} caratteri", "passwordCheckFail": "Le due password non corrispondono", + "passwordInvalid": "Password non valida", "username": "Username", "password": "Password", "passwordChanged": "La password è stata cambiata",