Commit ff02b07a authored by nkoth's avatar nkoth

[ENH] Jquery validation to be used for email/pass/username in registration...

[ENH] Jquery validation to be used for email/pass/username in registration when user tracker is used
parent 743b12ae
......@@ -2865,7 +2865,9 @@ lib/userprefs/index.php -text
lib/userprefs/scrambleEmail.php -text
lib/userprefs/userprefslib.php -text
lib/userslib.php -text
lib/validators/validator_password.php -text
lib/validators/validator_regex.php -text
lib/validators/validator_username.php -text
lib/validatorslib.php -text
lib/videogals/KalturaClientBase_v3.php -text
lib/videogals/KalturaClientReadme.txt -text
......
<?php
function validator_password($input, $parameter = '', $message = '') {
global $userlib;
$errors = $userlib->check_password_policy($input);
if (!$errors) {
return true;
} else {
return $errors;
}
}
<?php
function validator_username($input, $parameter = '', $message = '') {
global $userlib, $prefs;
if ($userlib->user_exists($input)) {
return tra("User already exists");
}
if (!empty($prefs['username_pattern']) && !preg_match($prefs['username_pattern'], $input)) {
return tra("Invalid character combination for username");
}
if (strtolower($input) == 'anonymous' || strtolower($input) == 'registered') {
return tra("Invalid username");
}
if (strlen($input) > $prefs['max_username_length']) {
$error = tra("Username cannot contain more than") . ' ' . $prefs['max_username_length'] . ' ' . tra("characters");
return $error;
}
if (strlen($input) < $prefs['min_username_length']) {
$error = tra("Username must be at least") . ' ' . $prefs['min_username_length'] . ' ' . tra("characters long");
return $error;
}
return true;
}
......@@ -22,7 +22,7 @@ class Validators
}
}
function validateInput( $validator, $parameter, $message = '' ) {
function validateInput( $validator, $parameter = '', $message = '' ) {
include_once('lib/validators/validator_' . $validator . '.php');
if (!function_exists("validator_$validator") || !isset($this->input)) {
return false;
......@@ -42,7 +42,7 @@ class Validators
return $validators;
}
function generateTrackerValidateJS( $fields_data, $prefix = "ins_" ) {
function generateTrackerValidateJS( $fields_data, $prefix = "ins_", $custom_rules = '', $custom_messages = '' ) {
$validationjs = 'rules: { ';
foreach ($fields_data as $field_value) {
if ($field_value['validation'] || $field_value['isMandatory'] == 'y') {
......@@ -68,6 +68,7 @@ class Validators
$validationjs .= '}, ';
}
}
$validationjs .= $custom_rules;
// remove last comma (not supported in IE7)
$validationjs = rtrim($validationjs, " ,");
$validationjs .= '}, ';
......@@ -79,6 +80,7 @@ class Validators
$validationjs .= '}, ';
}
}
$validationjs .= $custom_messages;
// remove last comma (not supported in IE7)
$validationjs = rtrim($validationjs, " ,");
$validationjs .= '} ';
......
......@@ -763,7 +763,44 @@ function wikiplugin_tracker($data, $params)
if ($prefs['feature_jquery'] == 'y' && $prefs['feature_jquery_validation'] == 'y') {
global $validatorslib;
include_once('lib/validatorslib.php');
$validationjs = $validatorslib->generateTrackerValidateJS( $flds['data'], "track_" );
$customvalidation = '';
$customvalidation_m = '';
if ($registration == 'y') {
// email validation
$customvalidation .= 'email: { ';
$customvalidation .= 'required: true, ';
$customvalidation .= 'email: true }, ';
$customvalidation_m .= 'email: { email: "'. tra("Invalid email") . '"}, ';
// password validation
$customvalidation .= 'pass: { ';
$customvalidation .= 'required: true, ';
$customvalidation .= 'remote: { ';
$customvalidation .= 'url: "validate-ajax.php", ';
$customvalidation .= 'type: "post", ';
$customvalidation .= 'data: { ';
$customvalidation .= 'validator: "password", ';
$customvalidation .= 'input: function() { ';
$customvalidation .= 'return $jq("#pass1").val(); ';
$customvalidation .= '} } } ';
$customvalidation .= '}, ';
// password repeat validation
$customvalidation .= 'passAgain: { equalTo: "#pass1" }, ';
$customvalidation_m .= 'passAgain: { equalTo: "'. tra("Passwords do not match") . '"}, ';
// username validation
$customvalidation .= 'name: { ';
$customvalidation .= 'required: true, ';
$customvalidation .= 'remote: { ';
$customvalidation .= 'url: "validate-ajax.php", ';
$customvalidation .= 'type: "post", ';
$customvalidation .= 'data: { ';
$customvalidation .= 'validator: "username", ';
$customvalidation .= 'input: function() { ';
$customvalidation .= 'return $jq("#name").val(); ';
$customvalidation .= '} } } ';
$customvalidation .= '}, ';
}
$validationjs = $validatorslib->generateTrackerValidateJS( $flds['data'], "track_", $customvalidation, $customvalidation_m );
$smarty->assign('validationjs', $validationjs);
$back .= $smarty->fetch('wiki-plugins/tracker_validator.tpl');
}
......
......@@ -4,7 +4,7 @@
{if $prefs.login_is_email ne 'y'}
<tr>
<td class="formcolor"><label for="email">{tr}Email:{/tr}</label>{if $trackerEditFormId}&nbsp;<strong class='mandatory_star'>*</strong>&nbsp;{/if}</td>
<td class="formcolor"><input type="text" id="email" name="email" {if $prefs.feature_ajax eq 'y'}onkeyup="return check_mail()" onblur="return check_mail()"{/if}/>
<td class="formcolor"><input type="text" id="email" name="email" {if $prefs.feature_ajax eq 'y' && !$userTrackerData}onkeyup="return check_mail()" onblur="return check_mail()"{/if}/>
{if $prefs.feature_ajax eq 'y'}<span id="ajax_msg_mail" style="vertical-align: middle;"></span>{/if}
{if $prefs.validateUsers eq 'y' and $prefs.validateEmail ne 'y'}
<div class="highlight"><em class='mandatory_note'>{tr}A valid email is mandatory to register{/tr}</em></div>
......
......@@ -4,7 +4,7 @@
<tr>
<td class="formcolor"><label for="name">{if $prefs.login_is_email eq 'y'}{tr}Email{/tr}{else}{tr}Username{/tr}{/if}:</label>{if $trackerEditFormId}&nbsp;<strong class='mandatory_star'>*</strong>&nbsp;{/if}</td>
<td class="formcolor">
<input type="text" name="name" id="name" {if $prefs.feature_ajax eq 'y'} onkeyup="return check_name()" onblur="return check_name()"{/if} />
<input type="text" name="name" id="name" {if $prefs.feature_ajax eq 'y' && !$userTrackerData} onkeyup="return check_name()" onblur="return check_name()"{/if} />
{if $prefs.feature_ajax eq 'y'}<span id="ajax_msg_name" style="vertical-align: middle;"></span>{/if}
{if $prefs.login_is_email eq 'y'}
<em>{tr}Use your email as login{/tr}</em>.
......
......@@ -5,7 +5,7 @@
<tr>
<td class="formcolor"><label for="pass1">{tr}Password:{/tr}</label>{if $trackerEditFormId}&nbsp;<strong class='mandatory_star'>*</strong>&nbsp;{/if}</td>
<td class="formcolor">
<input id='pass1' type="password" name="pass" onkeypress="regCapsLock(event)" onkeyup="{if $prefs.feature_ajax neq 'y'}runPassword(this.value, 'mypassword');checkPasswordsMatch('#pass2', '#pass1', '#mypassword2_text');{else}check_pass();{/if}" />
<input id='pass1' type="password" name="pass" onkeypress="regCapsLock(event)" onkeyup="{if $prefs.feature_ajax neq 'y' && !$userTrackerData}runPassword(this.value, 'mypassword');checkPasswordsMatch('#pass2', '#pass1', '#mypassword2_text');{elseif !$userTrackerData}check_pass();{/if}" />
<div style="float:right;margin-left:5px;">
<div id="mypassword_text"></div>
<div id="mypassword_bar" style="font-size: 5px; height: 2px; width: 0px;"></div>
......
......@@ -5,7 +5,7 @@
<tr>
<td class="formcolor" style="vertical-align:top"><label for="pass2">{tr}Repeat password:{/tr}</label>{if $trackerEditFormId}&nbsp;<strong class='mandatory_star'>*</strong>&nbsp;{/if}</td>
<td class="formcolor">
<input id='pass2' type="password" name="passAgain" onkeypress="regCapsLock(event)" onkeyup="{if $prefs.feature_ajax neq 'y'}checkPasswordsMatch('#pass2', '#pass1', '#mypassword2_text');{else}check_pass();{/if}" />
<input id='pass2' type="password" name="passAgain" onkeypress="regCapsLock(event)" onkeyup="{if $prefs.feature_ajax neq 'y' && !$userTrackerData}checkPasswordsMatch('#pass2', '#pass1', '#mypassword2_text');{elseif !$userTrackerData}check_pass();{/if}" />
<div style="float:right;margin-left:5px;">
<div id="mypassword2_text"></div>
</div>
......
......@@ -12,11 +12,19 @@ if ($prefs['feature_jquery'] != 'y' || $prefs['feature_jquery_validation'] != 'y
exit;
}
if (empty($_REQUEST['validator']) || empty($_REQUEST["input"]) || empty($_REQUEST["parameter"])) {
if (empty($_REQUEST['validator']) || empty($_REQUEST["input"])) {
echo '{}';
exit;
}
if (empty($_REQUEST["parameter"])) {
$_REQUEST["parameter"] = '';
}
if (empty($_REQUEST["message"])) {
$_REQUEST["message"] = '';
}
global $validatorslib;
include_once('lib/validatorslib.php');
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment