mulja Posted October 23, 2023 Share Posted October 23, 2023 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 0 Quote Link to comment Share on other sites More sharing options...
mulja Posted October 25, 2023 Author Share Posted October 25, 2023 write this code, but still not work something i missing <?php use WHMCS\Database\Capsule; use App; add_hook('ClientLogin', 1, function($vars) { $email = $vars['email']; $password = $vars['password']; $client = Capsule::table('tblclients') ->where('email', $email) ->first(); if ($client) { $customFieldName = 'customfield6'; // Name of the custom field $customFieldValue = Capsule::table('tblcustomfieldsvalues') ->where('fieldid', 6) ->where('relid', $client->id) ->value('value'); if ($customFieldValue) { $username = ''; // The field to use for login if (/* Your condition here */) { $username = $email; // Use email } else { $username = $customFieldValue; // Use the custom field value } $_POST['username'] = $username; $_POST['password'] = $password; } } }); add_hook('ClientAreaFooterOutput', 1, function ($vars) { // Change login input field to allow any text $changeLoginInput = '<script>$( document ).ready(function() { $("#inputEmail").prop({type:"text"}); });</script>'; return $changeLoginInput; }); 0 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.