mirror of
https://github.com/alextselegidis/easyappointments.git
synced 2024-11-28 10:53:40 +03:00
Added new callback to the account controller to validate usernames
This commit is contained in:
parent
f58d3b142b
commit
a3282febc9
2 changed files with 43 additions and 1 deletions
|
@ -102,4 +102,27 @@ class Account extends EA_Controller {
|
|||
json_exception($e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Make sure the username is valid and unique in the database.
|
||||
*/
|
||||
public function validate_username()
|
||||
{
|
||||
try
|
||||
{
|
||||
$username = request('username');
|
||||
|
||||
$user_id = request('user_id');
|
||||
|
||||
$is_valid = $this->users_model->validate_username($username, $user_id);
|
||||
|
||||
json_response([
|
||||
'is_valid' => $is_valid,
|
||||
]);
|
||||
}
|
||||
catch (Throwable $e)
|
||||
{
|
||||
json_exception($e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,7 +28,26 @@ App.Http.Account = (function () {
|
|||
return $.post(url, data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate username.
|
||||
*
|
||||
* @param {String} username
|
||||
*
|
||||
* @return {Object}
|
||||
*/
|
||||
function validateUsername(username) {
|
||||
const url = App.Utils.Url.siteUrl('account/validate_username');
|
||||
|
||||
const data = {
|
||||
csrf_token: App.Vars.csrf_token,
|
||||
username
|
||||
};
|
||||
|
||||
return $.post(url, data);
|
||||
}
|
||||
|
||||
return {
|
||||
save
|
||||
save,
|
||||
validateUsername
|
||||
};
|
||||
})();
|
||||
|
|
Loading…
Reference in a new issue