2 +--------------------------------------------------------------------+
3 | CiviCRM version 4.7 |
4 +--------------------------------------------------------------------+
5 | Copyright CiviCRM LLC (c) 2004-2017 |
6 +--------------------------------------------------------------------+
7 | This file is a part of CiviCRM. |
9 | CiviCRM is free software; you can copy, modify, and distribute it |
10 | under the terms of the GNU Affero General Public License |
11 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
13 | CiviCRM is distributed in the hope that it will be useful, but |
14 | WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
16 | See the GNU Affero General Public License for more details. |
18 | You should have received a copy of the GNU Affero General Public |
19 | License and the CiviCRM Licensing Exception along |
20 | with this program; if not, contact CiviCRM LLC |
21 | at info[AT]civicrm[DOT]org. If you have questions about the |
22 | GNU Affero General Public License or the licensing of CiviCRM, |
23 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
24 +--------------------------------------------------------------------+
26 {* This included tpl checks if a given username is taken or available. *}
27 {crmSigner var=checkUserSig for=civicrm/ajax/cmsuser}
30 cj("#checkavailability").click(function() {
31 var cmsUserName = cj.trim(cj("#cms_name").val());
32 if ( lastName == cmsUserName) {
33 /*if user checking the same user name more than one times. avoid the ajax call*/
36 /*don't allow special character and for joomla minimum username length is two*/
38 var spchar = "\<|\>|\"|\'|\%|\;|\(|\)|\&|\\\\|\/";
40 {/literal}{if $config->userSystem->is_drupal == "1"}{literal}
41 spchar = spchar + "|\~|\`|\:|\!|\=|\#|\$|\^|\*|\{|\}|\\[|\\]|\+|\?|\,";
42 {/literal}{/if}{literal}
43 var r = new RegExp( "["+spchar+"]", "i");
44 /*regular expression \\ matches a single backslash. this becomes r = /\\/ or r = new RegExp("\\\\").*/
45 if ( r.exec(cmsUserName) ) {
46 alert('{/literal}{ts escape="js"}Your username contains invalid characters{/ts}{literal}');
49 {/literal}{if $config->userFramework == "Joomla"}{literal}
50 else if ( cmsUserName && cmsUserName.length < 2 ) {
51 alert('{/literal}{ts escape="js"}Your username is too short{/ts}{literal}');
54 {/literal}{/if}{literal}
56 /*take all messages in javascript variable*/
57 var check = "{/literal}{ts escape='js'}Checking...{/ts}{literal}";
58 var available = "{/literal}{ts escape='js'}This username is currently available.{/ts}{literal}";
59 var notavailable = "{/literal}{ts escape='js'}This username is taken.{/ts}{literal}";
60 var errorMsg = "{/literal}{ts escape='js'}Error checking username. Please reload the form and try again.{/ts}{literal}";
62 //remove all the class add the messagebox classes and start fading
63 cj("#msgbox").removeClass().addClass('cmsmessagebox').css({"color":"#000","backgroundColor":"#FFC","border":"1px solid #c93"}).text(check).fadeIn("slow");
65 //check the username exists or not from ajax
66 var contactUrl = {/literal}"{crmURL p='civicrm/ajax/cmsuser' h=0 }"{literal};
68 var checkUserParams = {
69 cms_name: cj("#cms_name").val(),
70 ts: {/literal}"{$checkUserSig.ts}"{literal},
71 sig: {/literal}"{$checkUserSig.signature}"{literal},
72 for: 'civicrm/ajax/cmsuser'
74 cj.post(contactUrl, checkUserParams ,function(data) {
75 if ( data.name == "no") {/*if username not avaiable*/
76 cj("#msgbox").fadeTo(200,0.1,function() {
77 cj(this).html(notavailable).addClass('cmsmessagebox').css({"color":"#CC0000","backgroundColor":"#F7CBCA","border":"1px solid #CC0000"}).fadeTo(900,1);
79 } else if ( data.name == "error") {/*if username not avaiable*/
80 cj("#msgbox").fadeTo(200,0.1,function() {
81 cj(this).html(errorMsg).addClass('cmsmessagebox').css({"color":"#CC0000","backgroundColor":"#F7CBCA","border":"1px solid #CC0000"}).fadeTo(900,1);
84 cj("#msgbox").fadeTo(200,0.1,function() {
85 cj(this).html(available).addClass('cmsmessagebox').css({"color":"#008000","backgroundColor":"#C9FFCA", "border": "1px solid #349534"}).fadeTo(900,1);
89 lastName = cmsUserName;
91 cj("#msgbox").removeClass().text('').css({"backgroundColor":"#FFFFFF", "border": "0px #FFFFFF"}).fadeIn("fast");