Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | {* |
2 | +--------------------------------------------------------------------+ | |
fee14197 | 3 | | CiviCRM version 5 | |
6a488035 | 4 | +--------------------------------------------------------------------+ |
8c9251b3 | 5 | | Copyright CiviCRM LLC (c) 2004-2018 | |
6a488035 TO |
6 | +--------------------------------------------------------------------+ |
7 | | This file is a part of CiviCRM. | | |
8 | | | | |
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. | | |
12 | | | | |
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. | | |
17 | | | | |
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 | +--------------------------------------------------------------------+ | |
25 | *} | |
26 | {* This included tpl checks if a given username is taken or available. *} | |
272081ca | 27 | {crmSigner var=checkUserSig for=civicrm/ajax/cmsuser} |
6a488035 TO |
28 | {literal} |
29 | var lastName = null; | |
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*/ | |
34 | return; | |
35 | } | |
36 | /*don't allow special character and for joomla minimum username length is two*/ | |
37 | ||
38 | var spchar = "\<|\>|\"|\'|\%|\;|\(|\)|\&|\\\\|\/"; | |
39 | ||
40 | {/literal}{if $config->userSystem->is_drupal == "1"}{literal} | |
84016250 | 41 | spchar = spchar + "|\~|\`|\:|\!|\=|\#|\$|\^|\*|\{|\}|\\[|\\]|\+|\?|\,"; |
6a488035 TO |
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}'); | |
47 | return; | |
48 | } | |
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}'); | |
52 | return; | |
53 | } | |
54 | {/literal}{/if}{literal} | |
55 | if (cmsUserName) { | |
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}"; | |
272081ca | 60 | var errorMsg = "{/literal}{ts escape='js'}Error checking username. Please reload the form and try again.{/ts}{literal}"; |
6a488035 TO |
61 | |
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"); | |
64 | ||
65 | //check the username exists or not from ajax | |
66 | var contactUrl = {/literal}"{crmURL p='civicrm/ajax/cmsuser' h=0 }"{literal}; | |
67 | ||
272081ca TO |
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' | |
73 | }; | |
74 | cj.post(contactUrl, checkUserParams ,function(data) { | |
6a488035 TO |
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); | |
78 | }); | |
272081ca TO |
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); | |
82 | }); | |
6a488035 TO |
83 | } else { |
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); | |
86 | }); | |
87 | } | |
88 | }, "json"); | |
89 | lastName = cmsUserName; | |
90 | } else { | |
91 | cj("#msgbox").removeClass().text('').css({"backgroundColor":"#FFFFFF", "border": "0px #FFFFFF"}).fadeIn("fast"); | |
92 | } | |
93 | }); | |
94 | {/literal} |