Hi
can anyboby help me with hook to use customfield for example ID 1, customfield ID1- customfieldvalue like username to login
i found code to use phone number to login but how to get customfield ID1- customfieldvalue from database to login
add_hook('ClientLoginShare', 1, function ($vars) {
// Define username and password. Username is whatever the user enters in the 'email address' field.
$username = $vars['username'];
$password = $vars['password'];
// Let's see if the user is logging in using an email address. If not, let's see if we can find the user's phone number in the database and allow them to login this way.
if (!filter_var($username, FILTER_VALIDATE_EMAIL)) {
$users = Capsule::table('tblclients')
->select('email')
->where('phonenumber', $username)
->get();
// If there's multiple users with the same phone number, allow _none_ of them to login by using their phone numbers.
// They will only be able to login using email address in that case
if (sizeof($users) > 1) {
return false;
}
// Set the user's email address
foreach ($users as $user) {
$email = $user->email;
}
// Documentation: https://developers.whmcs.com/api-reference/validatelogin/
$command = 'ValidateLogin';
$postData = array(
'email' => $email,
'password2' => $password,
);
// Check if login is valid - if it is, log them in using email address
$isValid = localAPI($command, $postData);
if ($isValid['result'] == "success") {
return array(
'email' => $email,
);
}else{
return false;
}
}
$command = 'ValidateLogin';
$postData = array(
'email' => $username,
'password2' => $password,
);
// Check if login is valid - if it is, log them in using email address
$isValid = localAPI($command, $postData);
if ($isValid['result'] == "success") {
return array(
'email' => $username,
);
}
return false;
});
// Change login input field to allow any text
add_hook('ClientAreaFooterOutput', 1, function ($vars) {
$changeLoginInput = '<script>$( document ).ready(function() {
$("#inputEmail").prop({type:"text"});
});</script>';
return $changeLoginInput;
});
any help appreciated
Thanks