Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
Total | |
0.00% |
0 / 1 |
|
0.00% |
0 / 4 |
CRAP | |
0.00% |
0 / 45 |
AuthenticationService | |
0.00% |
0 / 1 |
|
0.00% |
0 / 4 |
240.00 | |
0.00% |
0 / 45 |
__construct | |
0.00% |
0 / 1 |
2.00 | |
0.00% |
0 / 1 |
|||
__clone | |
0.00% |
0 / 1 |
2.00 | |
0.00% |
0 / 1 |
|||
getInstance | |
0.00% |
0 / 1 |
6.00 | |
0.00% |
0 / 5 |
|||
isOtpEnabledForUser | |
0.00% |
0 / 1 |
132.00 | |
0.00% |
0 / 38 |
<?php | |
namespace com\linways\core\ams\professional\service; | |
use com\linways\core\ams\professional\service\CommonService; | |
use com\linways\core\ams\professional\exception\ProfessionalException; | |
use com\linways\core\ams\professional\constant\UserType; | |
class AuthenticationService extends BaseService | |
{ | |
// /Condition 1 - Presence of a static member variable | |
private static $_instance = null; | |
// /Condition 2 - Locked down the constructor | |
private function __construct() | |
{} | |
// Prevent any oustide instantiation of this class | |
// /Condition 3 - Prevent any object or instance of that class to be cloned | |
private function __clone() | |
{} | |
// Prevent any copy of this object | |
// /Condition 4 - Have a single globally accessible static method | |
public static function getInstance() | |
{ | |
if (! is_object(self::$_instance)) // or if( is_null(self::$_instance) ) or if( self::$_instance == null ) | |
self::$_instance = new self(); | |
return self::$_instance; | |
} | |
public function isOtpEnabledForUser($userId, $userType){ | |
$userId = $this->realEscapeString($userId); | |
$userType = $this->realEscapeString($userType); | |
$otpSettings = CommonService::getInstance()->getSettings('AUTHENTICATION', 'OTP_AUTHENTICATION_SETTINGS'); | |
$otpSettings = json_decode($otpSettings); | |
if($userType == UserType::STAFF){ | |
$accessObjectUserType = 'staff'; | |
}elseif($userType == UserType::STUDENT){ | |
$accessObjectUserType = 'student'; | |
}elseif($userType == UserType::PARENT){ | |
$accessObjectUserType = 'parent'; | |
}elseif($userType == UserType::ADMIN){ | |
$accessObjectUserType = 'admin'; | |
} | |
$otpIsEnabled = false; | |
if($otpSettings->{$accessObjectUserType}->is_enabled){ | |
$otp_auth = (array)$otpSettings->{$accessObjectUserType}->otp_methods; | |
foreach ($otp_auth as $value) { | |
if($value) | |
{ | |
$otpIsEnabled = true; | |
break; | |
} | |
} | |
} | |
if(!$otpIsEnabled) | |
{ | |
return false; | |
} | |
$sql = "SELECT is_enabled as isEnabled FROM user_authentication WHERE user_id = $userId AND user_type = '$userType'"; | |
try{ | |
$otpEnabled = $this->executeQueryForObject($sql); | |
}catch(\Exception $e){ | |
} | |
if(empty($otpEnabled)){ | |
return true; | |
} | |
return $otpEnabled->isEnabled; | |
} | |
} |