Problem with two factor authentication (via Custom SMS Class)

This public forum is for user-to-user discussions of PHPMaker. Note that this is not support forum.
Post Reply
mansour
User
Posts: 319

Problem with two factor authentication (via Custom SMS Class)

Post 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


arbei
User
Posts: 9616

Post by arbei »

Make sure you have not removed the load() method in the original SMS class under src\Sms.php.


mansour
User
Posts: 319

Post by mansour »

Hi,
I have NOT make any changes other than adding this global code.
Thanks


arbei
User
Posts: 9616

Post 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).


mansour
User
Posts: 319

Post 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


arbei
User
Posts: 9616

Post 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.


mansour
User
Posts: 319

Post 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


mansour
User
Posts: 319

Post 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


arbei
User
Posts: 9616

Post by arbei »

The error means JSON is expected but you have server side error (in HTML format starting with '<'). You may Check HTTP Response.


Post Reply