From 91d1afb845644334bb1c1cf7871c94f3a5406bbb Mon Sep 17 00:00:00 2001 From: Sebastian Sdorra Date: Sat, 6 Aug 2011 14:26:50 +0200 Subject: [PATCH] added field validation for repository, user and group names --- scm-webapp/src/main/webapp/index.html | 1 + .../group/sonia.group.propertiesformpanel.js | 3 +- .../src/main/webapp/resources/js/i18n/de.js | 5 +- .../resources/js/override/ext.form.vtypes.js | 63 +++++++++++++++++++ .../sonia.repository.propertiesformpanel.js | 3 +- .../resources/js/user/sonia.user.formpanel.js | 3 +- .../webapp/resources/js/user/sonia.user.js | 12 ---- 7 files changed, 73 insertions(+), 17 deletions(-) create mode 100644 scm-webapp/src/main/webapp/resources/js/override/ext.form.vtypes.js diff --git a/scm-webapp/src/main/webapp/index.html b/scm-webapp/src/main/webapp/index.html index f653c0e880..841c9b3960 100644 --- a/scm-webapp/src/main/webapp/index.html +++ b/scm-webapp/src/main/webapp/index.html @@ -68,6 +68,7 @@ + diff --git a/scm-webapp/src/main/webapp/resources/js/group/sonia.group.propertiesformpanel.js b/scm-webapp/src/main/webapp/resources/js/group/sonia.group.propertiesformpanel.js index 9165bf8b00..c4c006baa1 100644 --- a/scm-webapp/src/main/webapp/resources/js/group/sonia.group.propertiesformpanel.js +++ b/scm-webapp/src/main/webapp/resources/js/group/sonia.group.propertiesformpanel.js @@ -40,7 +40,8 @@ Sonia.group.PropertiesFormPanel = Ext.extend(Sonia.group.FormPanel, { name: 'name', allowBlank: false, readOnly: this.item != null, - helpText: this.nameHelpText + helpText: this.nameHelpText, + vtype: 'name' },{ fieldLabel: this.descriptionText, name: 'description', diff --git a/scm-webapp/src/main/webapp/resources/js/i18n/de.js b/scm-webapp/src/main/webapp/resources/js/i18n/de.js index 6895fe5259..6d1a1c2660 100644 --- a/scm-webapp/src/main/webapp/resources/js/i18n/de.js +++ b/scm-webapp/src/main/webapp/resources/js/i18n/de.js @@ -38,8 +38,9 @@ if (Ext.form.VTypes){ pluginurlText: 'Dieses Feld sollte eine URL enthalten. Format: \n\ "http://plugins.scm-manager.org/scm-plugin-backend/api/{version}/plugins?os={os}&arch={arch}&snapshot=false"', - // sonia.user.js - passwordText: 'Die Passwörter stimmen nicht überein!' + passwordText: 'Die Passwörter stimmen nicht überein!', + nameTest: 'Der Name ist invalid.', + usernameText: 'Der Benutzername ist invalid.' }); } diff --git a/scm-webapp/src/main/webapp/resources/js/override/ext.form.vtypes.js b/scm-webapp/src/main/webapp/resources/js/override/ext.form.vtypes.js new file mode 100644 index 0000000000..93e78950cd --- /dev/null +++ b/scm-webapp/src/main/webapp/resources/js/override/ext.form.vtypes.js @@ -0,0 +1,63 @@ +/* * + * Copyright (c) 2010, Sebastian Sdorra + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of SCM-Manager; nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * http://bitbucket.org/sdorra/scm-manager + * + */ + + +Ext.apply(Ext.form.VTypes, { + + // passord validator + + password: function(val, field) { + if (field.initialPassField) { + var pwd = Ext.getCmp(field.initialPassField); + return (val == pwd.getValue()); + } + return true; + }, + + passwordText: 'The passwords entered do not match!', + + // name validator + + name: function(val){ + return /^[A-z0-9\.\-_]+$/.test(val); + }, + + nameText: 'The name is invalid.', + + // username validator + + username: function(val){ + return val.match(/^[A-z0-9\.\-_@]+$/); + }, + + usernameText: 'The username is invalid.' + +}); \ No newline at end of file diff --git a/scm-webapp/src/main/webapp/resources/js/repository/sonia.repository.propertiesformpanel.js b/scm-webapp/src/main/webapp/resources/js/repository/sonia.repository.propertiesformpanel.js index 6c4a299f78..8fe0ed419f 100644 --- a/scm-webapp/src/main/webapp/resources/js/repository/sonia.repository.propertiesformpanel.js +++ b/scm-webapp/src/main/webapp/resources/js/repository/sonia.repository.propertiesformpanel.js @@ -43,7 +43,8 @@ Sonia.repository.PropertiesFormPanel = Ext.extend(Sonia.repository.FormPanel, { name: 'name', readOnly: update, allowBlank: false, - helpText: this.nameHelpText + helpText: this.nameHelpText, + vtype: 'name' },{ fieldLabel: this.typeText, name: 'type', diff --git a/scm-webapp/src/main/webapp/resources/js/user/sonia.user.formpanel.js b/scm-webapp/src/main/webapp/resources/js/user/sonia.user.formpanel.js index d41c8e7853..a5b5bc3196 100644 --- a/scm-webapp/src/main/webapp/resources/js/user/sonia.user.formpanel.js +++ b/scm-webapp/src/main/webapp/resources/js/user/sonia.user.formpanel.js @@ -57,7 +57,8 @@ Sonia.user.FormPanel = Ext.extend(Sonia.rest.FormPanel,{ name: 'name', allowBlank: false, readOnly: this.item != null, - helpText: this.usernameHelpText + helpText: this.usernameHelpText, + vtype: 'username' },{ fieldLabel: this.displayNameText, name: 'displayName', diff --git a/scm-webapp/src/main/webapp/resources/js/user/sonia.user.js b/scm-webapp/src/main/webapp/resources/js/user/sonia.user.js index 95ab1575f9..2a0633b914 100644 --- a/scm-webapp/src/main/webapp/resources/js/user/sonia.user.js +++ b/scm-webapp/src/main/webapp/resources/js/user/sonia.user.js @@ -53,15 +53,3 @@ Sonia.user.DefaultPanel = { html: 'Add or select an User' }; - -// passord validator -Ext.apply(Ext.form.VTypes, { - password: function(val, field) { - if (field.initialPassField) { - var pwd = Ext.getCmp(field.initialPassField); - return (val == pwd.getValue()); - } - return true; - }, - passwordText: 'The passwords entered do not match!' -});