Thanks for the pointers. I just moved a few methods here to make the domain validation work with tenant mgt ui. Just noticed these methods are written in C-Style code, with character codes and single letter variable names used. Will fix the issues in the next commit, with refactoring.
Regards, Pradeeban. On Sun, Jan 16, 2011 at 6:08 PM, Afkham Azeez <[email protected]> wrote: > > > On Sun, Jan 16, 2011 at 4:16 PM, <[email protected]> wrote: > >> Author: pradeeban >> Date: Sun Jan 16 02:46:02 2011 >> New Revision: 85379 >> URL: http://wso2.org/svn/browse/wso2?view=rev&revision=85379 >> >> Log: >> Check the validity of the domain when adding a new tenant by the >> super-admin. >> >> >> Modified: >> >> trunk/stratos/components/tenant-mgt/org.wso2.stratos.tenant.mgt.ui/src/main/resources/web/tenant-mgt/js/tenant_config.js >> >> Modified: >> trunk/stratos/components/tenant-mgt/org.wso2.stratos.tenant.mgt.ui/src/main/resources/web/tenant-mgt/js/tenant_config.js >> URL: >> http://wso2.org/svn/browse/wso2/trunk/stratos/components/tenant-mgt/org.wso2.stratos.tenant.mgt.ui/src/main/resources/web/tenant-mgt/js/tenant_config.js?rev=85379&r1=85378&r2=85379&view=diff >> >> ============================================================================== >> --- >> trunk/stratos/components/tenant-mgt/org.wso2.stratos.tenant.mgt.ui/src/main/resources/web/tenant-mgt/js/tenant_config.js >> (original) >> +++ >> trunk/stratos/components/tenant-mgt/org.wso2.stratos.tenant.mgt.ui/src/main/resources/web/tenant-mgt/js/tenant_config.js >> Sun Jan 16 02:46:02 2011 >> @@ -1,15 +1,33 @@ >> function addTenant(isUpdating) { >> var reason = ""; >> var addTenantForm = document.getElementById('addTenantForm'); >> - var adminPassword = ""; >> - var adminPasswordRepeat = ""; >> + var adminPassword = document.getElementById('admin-password'); >> + var adminPasswordRepeat = >> document.getElementById('admin-password-repeat'); >> + var email = document.getElementById('admin-email'); >> var firstname = document.getElementById('admin-firstname'); >> var lastname = document.getElementById('admin-lastname'); >> - adminPassword = document.getElementById('admin-password'); >> - adminPasswordRepeat = >> document.getElementById('admin-password-repeat'); >> - var email = document.getElementById('admin-email'); >> >> - if (!isUpdating) { >> + if (isUpdating) { >> + // only the given values will be updated, so no need to fill all >> the values. >> + if (reason == "") { >> + reason += validateEmpty(firstname, "First Name"); >> + } >> + if (reason == "") { >> + reason += validateIllegal(firstname, "First Name"); >> + } >> + if (reason == "") { >> + reason += validateEmpty(lastname, "Last Name"); >> + } >> + if (reason == "") { >> + reason += validateIllegal(lastname, "Last Name"); >> + } >> + if (adminPassword.value != null && adminPassword.value != "") { >> + if (adminPassword.value != adminPasswordRepeat.value) { >> + reason += jsi18n["password.mismatched"]; >> + } >> + } >> + } >> + else { >> var domain = document.getElementById('domain'); >> var adminName = document.getElementById('admin'); >> if (reason == "") { >> @@ -19,50 +37,52 @@ >> reason += validateDomain(domain); >> } >> if (reason == "") { >> - reason += validateEmpty(adminName, "AdminName"); >> + reason += checkDomain(domain); >> + } >> + if (reason == "") { >> + reason += validateEmpty(firstname, "First Name"); >> + } >> + if (reason == "") { >> + reason += validateIllegal(firstname, "First Name"); >> + } >> + if (reason == "") { >> + reason += validateEmpty(lastname, "Last Name"); >> + } >> + if (reason == "") { >> + reason += validateIllegal(lastname, "Last Name"); >> + } >> + if (reason == "") { >> + reason += validateEmpty(adminName, "Admin Name"); >> + } >> + if (reason == "") { >> + reason += validateIllegal(adminName, "Admin Name"); >> } >> if (reason == "") { >> reason += validateUsername(adminName); >> } >> - } >> - >> - if (reason == "") { >> - reason += validateEmpty(firstname, "First Name"); >> - } >> - if (reason == "") { >> - reason += validateIllegal(firstname, "First Name"); >> - } >> - if (reason == "") { >> - reason += validateEmpty(lastname, "Last Name"); >> - } >> - if (reason == "") { >> - reason += validateIllegal(lastname, "Last Name"); >> - } >> - if (reason == "") { >> - reason += validateIllegal(adminName, "AdminName"); >> - } >> - if (reason == "") { >> - reason += validateEmpty(adminPassword, "AdminPassword"); >> - } >> - if (reason == "") { >> - reason += validatePassword(adminPassword); >> - } >> - if (reason == "") { >> - reason += validateEmpty(adminPasswordRepeat, >> "AdminPasswordRepeat"); >> - } >> - if (reason == "") { >> - reason += validateEmpty(email, "Mail"); >> - } >> - if (reason == "") { >> - reason += validateEmail(email); >> - } >> - >> - if (reason == "") { >> - if (adminPassword.value != adminPasswordRepeat.value) { >> - reason += jsi18n["password.mismatched"]; >> + if (reason == "") { >> + reason += validateEmpty(adminPassword, "AdminPassword"); >> + } >> + if (reason == "") { >> + reason += validatePassword(adminPassword); >> } >> - if (adminPassword.value.length < 6) { >> - reason += jsi18n["password.length"]; >> + if (reason == "") { >> + reason += validateEmpty(adminPasswordRepeat, >> "AdminPasswordRepeat"); >> + } >> + if (reason == "") { >> + reason += validateEmpty(email, "Email"); >> + } >> + if (reason == "") { >> + reason += validateEmail(email); >> + } >> + >> + if (reason == "") { >> + if (adminPassword.value != adminPasswordRepeat.value) { >> + reason += jsi18n["password.mismatched"]; >> + } >> + if (adminPassword.value.length < 6) { >> + reason += jsi18n["password.length"]; >> + } >> } >> } >> if (reason != "") { >> @@ -75,10 +95,12 @@ >> function showsuccessregistermessage() { >> > > you should have proper camel casing in Javascript too. > > >> var message = "You have registered the Organization Successfully"; >> CARBON.showInfoDialog(message); >> + return; >> } >> function showsuccessupdatemessage() { >> var message = "Your changes saved Successfully!"; >> CARBON.showInfoDialog(message); >> + return; >> } >> function activationChanged(cbox, domain) { >> if (!cbox.checked) { >> @@ -129,4 +151,52 @@ >> } >> >> return error; >> +} >> + >> +function checkDomain(nname) { >> + >> + var error = ""; >> + var mai = nname.value; >> + >> + var val = true; >> + var dot = mai.lastIndexOf("."); >> + var dname = mai.substring(0, dot); >> + var ext = mai.substring(dot, mai.length); >> + >> + if (ext.indexOf("-trial") >= 0 || ext.indexOf("-unverified") >= 0) { >> + // we are not allowing to create a domain with -trial or >> -unverified is in the extension >> + return "The domain name you entered is not valid. Please enter a >> valid domain name."; >> + } >> + >> + if (ext.indexOf("/") >= 0 || ext.indexOf("\\") >= 0) { >> + return "The '/' and '\\' is not allowed in a domain name"; >> + } >> + >> + if (dot > 0 && dot < 57) { >> > > What is this 57? > > >> + if (!val) { >> + error = "Your domain extension " + ext + " is not correct"; >> + return error; >> + } >> + else { >> + for (var j = 0; j < dname.length; j++) { >> + var dh = dname.charAt(j); >> + var hh = dh.charCodeAt(0); >> + if ((hh > 47 && hh < 59) || (hh > 64 && hh < 91) || (hh > >> 96 && hh < 123) || >> + hh == 45 || hh == 46) { >> + if ((j == 0 || j == dname.length - 1) && hh == 45) { >> > > What are all these magic numbers? > > >> + error = "Domain name should not begin and end >> with '-'"; >> + return error; >> + } >> + } else { >> + error = "Your domain name should not have special >> characters"; >> + return error; >> + } >> + } >> + } >> + } >> + else { >> + error = "Your Domain name is too short/long or you should have an >> extension to your domain."; >> + return error; >> + } >> + return error; >> } >> \ No newline at end of file >> _______________________________________________ >> Carbon-commits mailing list >> [email protected] >> https://wso2.org/cgi-bin/mailman/listinfo/carbon-commits >> > > > > -- > *Afkham Azeez* > Senior Software Architect & Senior Manager; WSO2, Inc.; http://wso2.com, > * > * > *Member; Apache Software Foundation; > **http://www.apache.org/*<http://www.apache.org/> > * > email: **[email protected]* <[email protected]>* cell: +94 77 3320919 > blog: **http://blog.afkham.org* <http://blog.afkham.org>* > twitter: **http://twitter.com/afkham_azeez*<http://twitter.com/afkham_azeez> > * > linked-in: **http://lk.linkedin.com/in/afkhamazeez* > * > * > *Lean . Enterprise . Middleware* > > -- Kathiravelu Pradeeban. Software Engineer. WSO2 Inc. Blog: [Llovizna] http://kkpradeeban.blogspot.com/
_______________________________________________ Carbon-dev mailing list [email protected] https://wso2.org/cgi-bin/mailman/listinfo/carbon-dev
