Page 1 of 1
Problem with two factor authentication (via Custom SMS Class)
Posted: Sun May 19, 2024 5:03 pm
by mansour
Hi,
I activated two factor authentication (2FA) by sms, using my own class that I puted in global codes server event. I receive the following error when I try to login:
C:\xampp\htdocs\telehealth\src\SmsTwoFactorAuthentication.php(42): Call to undefined method PHPMaker2024\TELEHEALTH\PedraSMS::load()
what's the problem?
class PedraSMS extends Sms {
// Send SMS
public function send() {
$phoneNumber = $this->Recipient; // Get phone number
$message = $this->Content; // Get SMS content
try {
date_default_timezone_set("Asia/Tehran");
// your panel configuration
$conf = new Configuration;
$conf->setConfig("SMSAPI");
$APIKey = $conf->ConfigValue;
$conf->setConfig("SMSKEY");
$SecretKey = $conf->ConfigValue;
$conf->setConfig("LOGINSMS");
$templateID = $conf->ConfigValue;
// message data
$data = array(
"ParameterArray" => array(
array(
"Parameter" => "VerificationCode",
"ParameterValue" => $message
)
),
"Mobile" => $phoneNumber,
"TemplateId" => $templateID
);
$SmsIR_UltraFastSend = new SmsIR_UltraFastSend($APIKey,$SecretKey);
$UltraFastSend = $SmsIR_UltraFastSend->UltraFastSend($data);
} catch (Exeption $e) {
echo 'Error UltraFastSend : '.$e->getMessage();
}
return true; // Send successful
}
}
Config("SMS_CLASS", PROJECT_NAMESPACE . "PedraSMS"); // Replace the default Sms class by your own class
Config("SMS_REGION_CODE", "+98"); // Override default SMS region code to GB
thanks
mansour
Re: Problem with two factor authentication (via Custom SMS Class)
Posted: Sun May 19, 2024 8:42 pm
by arbei
Make sure you have not removed the load()
method in the original SMS class under src\Sms.php.
Re: Problem with two factor authentication (via Custom SMS Class)
Posted: Mon May 20, 2024 11:33 am
by mansour
Hi,
I have NOT make any changes other than adding this global code.
Thanks
Re: Problem with two factor authentication (via Custom SMS Class)
Posted: Mon May 20, 2024 11:44 am
by arbei
mansour wrote:
C:\xampp\htdocs\telehealth\src\SmsTwoFactorAuthentication.php(42): Call to undefined method PHPMaker2024\TELEHEALTH\PedraSMS::load()
But the error message said it cannot find Sms::load()
, you better open src\Sms.php in your project folder with a text editor and check the source code. In the template, the Sms.php does have public function load()
.
Make sure the namespaces of the src\Sms.php and the global code (i.e. src\userfn.php) are the same (i.e. PHPMaker2024\TELEHEALTH
).
Re: Problem with two factor authentication (via Custom SMS Class)
Posted: Mon May 20, 2024 12:04 pm
by mansour
Hi,
Yes, the code is correct. I have a language file for the project default language. (OneTimePasswordSms.fa-IR).
code for sms.php:
<?php
namespace PHPMaker2024\TELEHEALTH;
use Symfony\Component\Finder\Finder;
/**
* SMS class
*/
abstract class Sms
{
public $Recipient = ""; // Recipient
public $Content = ""; // Content
public $SendErrDescription; // Send error description
/**
* Load message from template name
*
* @param string $name Template name
* @param string $langId Language ID
* @param array $data Data for template
* @return void
*/
public function load($name, $langId = "", $data = [])
{
global $CurrentLanguage;
$langId = $langId ?: $CurrentLanguage;
$this->data = $data;
$parts = pathinfo($name);
$finder = Finder::create()->files()->in(Config("LANGUAGE_FOLDER"))->name($parts["filename"] . "." . $langId . "." . $parts["extension"]); // Template for the language ID
if (!$finder->hasResults()) {
$finder->files()->name($parts["filename"] . ".en-US." . $parts["extension"]); // Fallback to en-US
}
if ($finder->hasResults()) {
$wrk = "";
$view = Container("sms.view");
foreach ($finder as $file) {
$wrk = $view->fetchTemplate($file->getFileName(), $data);
}
$this->Content = $wrk;
} else {
throw new \Exception("Failed to load sms template '$name' for language '$langId'");
}
}
/**
* Replace content
*
* @param string $find String to find
* @param string $replaceWith String to replace
* @return void
*/
public function replaceContent($find, $replaceWith)
{
$this->Content = str_replace($find, $replaceWith, $this->Content);
}
/**
* Send SMS
*
* @return bool Whether SMS is sent successfully
*/
public function send()
{
//var_dump($this->Content, $this->Recipient);
return false; // Not implemented
}
}
Thanks
Re: Problem with two factor authentication (via Custom SMS Class)
Posted: Mon May 20, 2024 2:21 pm
by arbei
Then it is correct. You better turn on Debug and change the said php.ini settings, and try again. Then see the log file for more detailed error info.
Re: Problem with two factor authentication (via Custom SMS Class)
Posted: Mon May 20, 2024 3:43 pm
by mansour
Hi,
I found the problem. I had another class with the name of "sms", in my global codes. I renamed it and the problem is solved.
Thank you.
Mansour
Re: Problem with two factor authentication (via Custom SMS Class)
Posted: Mon May 20, 2024 3:56 pm
by mansour
Hi,
The sms/email OTP codes works fine but there is another problem with both email/sms OTP codes.
When I try to list the backup codes I receive the following error message:
SyntaxError: Unexpected token '<', ""... is not valid JSON
Thanks
Re: Problem with two factor authentication (via Custom SMS Class)
Posted: Mon May 20, 2024 9:04 pm
by arbei
The error means JSON is expected but you have server side error (in HTML format starting with '<'). You may Check HTTP Response.