Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
| Total | |
0.00% |
0 / 1 |
|
0.00% |
0 / 14 |
CRAP | |
0.00% |
0 / 86 |
| LoginService | |
0.00% |
0 / 1 |
|
0.00% |
0 / 14 |
462.00 | |
0.00% |
0 / 86 |
| __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 / 4 |
|||
| login | |
0.00% |
0 / 1 |
2.00 | |
0.00% |
0 / 3 |
|||
| logout | |
0.00% |
0 / 1 |
2.00 | |
0.00% |
0 / 5 |
|||
| logoutFromMobileApp | |
0.00% |
0 / 1 |
6.00 | |
0.00% |
0 / 11 |
|||
| getSessionExpirationTime | |
0.00% |
0 / 1 |
12.00 | |
0.00% |
0 / 9 |
|||
| getOauth2LoginUrl | |
0.00% |
0 / 1 |
2.00 | |
0.00% |
0 / 4 |
|||
| createStateJwtForOauth2 | |
0.00% |
0 / 1 |
6.00 | |
0.00% |
0 / 10 |
|||
| decodeStateJwtForOauth2 | |
0.00% |
0 / 1 |
2.00 | |
0.00% |
0 / 3 |
|||
| saveKioskPassword | |
0.00% |
0 / 1 |
6.00 | |
0.00% |
0 / 12 |
|||
| checkKioskPassword | |
0.00% |
0 / 1 |
6.00 | |
0.00% |
0 / 8 |
|||
| generateKioskAccessToken | |
0.00% |
0 / 1 |
2.00 | |
0.00% |
0 / 11 |
|||
| validateKioskAccessToken | |
0.00% |
0 / 1 |
2.00 | |
0.00% |
0 / 4 |
|||
| <?php | |
| namespace com\linways\core\ams\professional\service; | |
| use com\linways\core\ams\professional\exception\ProfessionalException; | |
| use Exception; | |
| use Firebase\JWT\JWT; | |
| use com\linways\core\ams\professional\dto\SettingsConstents; | |
| class LoginService extends BaseService { | |
| 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; | |
| } | |
| /** | |
| * | |
| * @param unknown $username | |
| * @param unknown $password | |
| * @throws FeeException | |
| * @return boolean | |
| */ | |
| public function login($username, $password) { | |
| $user = null; | |
| //TODO | |
| return $user; | |
| } | |
| /** | |
| * Method for logout the user | |
| * @return boolean true if logged out successfully else false | |
| */ | |
| public function logout() | |
| { | |
| session_unset(); | |
| $_SESSION = array(); | |
| return session_destroy(); | |
| } | |
| /** | |
| * Clear mobile login token and its details from mobile_login_tokens | |
| * @param $loginTokenId | |
| * @return bool|\com\linways\base\dto\MySqlResult|null | |
| * @throws ProfessionalException | |
| */ | |
| public function logoutFromMobileApp($loginTokenId){ | |
| $loginTokenId = $this->realEscapeString($loginTokenId); | |
| $status= false; | |
| $sql = "DELETE FROM mobile_login_tokens WHERE id=$loginTokenId"; | |
| try{ | |
| $status = $this->executeQuery($sql); | |
| $status = true; | |
| }catch (Exception $e){ | |
| throw new ProfessionalException($e->getCode(), $e->getMessage()); | |
| } | |
| return $status; | |
| } | |
| public function getSessionExpirationTime() | |
| { | |
| $currentTimeoutInSecs = ini_get(’session.gc_maxlifetime’); | |
| $now = time(); | |
| if (isset($_SESSION['discard_after']) && $now > $_SESSION['discard_after']) { | |
| // this session has worn out its welcome; kill it and start a brand new one | |
| session_unset(); | |
| session_destroy(); | |
| session_start(); | |
| } | |
| } | |
| /** | |
| * create oauth url with current state object. This state is used to redirect back from accounts.linways.com | |
| * @param string $userType STAFF/STUDENT | |
| * @param Booolean $isMobile | |
| * @return string | |
| */ | |
| public function getOauth2LoginUrl($userType, $isMobile){ | |
| require_once getenv('NUCLEUS_CONF'); | |
| global $AUTHENTICATION_DOMAIN; | |
| return "$AUTHENTICATION_DOMAIN/oauth?state=". $this->createStateJwtForOauth2($userType, $GLOBALS['COLLEGE_CODE'], $isMobile); | |
| } | |
| public function createStateJwtForOauth2($userType, $collgeCode, $isMobile){ | |
| require_once getenv('NUCLEUS_CONF'); | |
| $state = [ | |
| "dom"=> $_SERVER['HTTP_HOST'], // Redirect Domain name, This is to support custom domain name | |
| "cc" => $collgeCode, // College code | |
| "ut" => $userType, // User Type | |
| "failure_redir" => urlencode($_SERVER["REQUEST_URI"]) // redirect url in case of failure | |
| ]; | |
| $state['mob'] = $isMobile? 1: 0; // is mobile | |
| return JWT::encode($state, $GLOBALS['OAUTH_JWT_SECRET']); | |
| } | |
| public function decodeStateJwtForOauth2($jwt){ | |
| require_once getenv('NUCLEUS_CONF'); | |
| return (array)JWT::decode($jwt, $GLOBALS['OAUTH_JWT_SECRET'], array('HS256')); | |
| } | |
| public function saveKioskPassword($password){ | |
| require_once getenv('NUCLEUS_CONF'); | |
| $salt = $GLOBALS['GENERAL_SALT']; //From nucleus conf | |
| $oldPassword = CommonService::getInstance()->getSettings(SettingsConstents::STUDENT_PROFILE, SettingsConstents::STUDENT_PROFILE_KIOSK_PASSWORD); | |
| if(empty($oldPassword)) | |
| { | |
| CommonService::getInstance()->createSettings(SettingsConstents::STUDENT_PROFILE, SettingsConstents::STUDENT_PROFILE_KIOSK_PASSWORD, md5($password.$salt)); | |
| } | |
| else | |
| { | |
| CommonService::getInstance()->updateSettings(SettingsConstents::STUDENT_PROFILE,SettingsConstents::STUDENT_PROFILE_KIOSK_PASSWORD, md5($password.$salt)); | |
| } | |
| } | |
| public function checkKioskPassword($password){ | |
| require_once getenv('NUCLEUS_CONF'); | |
| $salt = $GLOBALS['GENERAL_SALT']; //From nucleus conf | |
| $calculatedPassword = md5($password.$salt); | |
| $originalPassword = CommonService::getInstance()->getSettings('STUDENT_PROFILE', 'STUDENT_PROFILE_KIOSK_PASSWORD'); | |
| if($originalPassword === $calculatedPassword) | |
| return true; | |
| else return false; | |
| } | |
| public function generateKioskAccessToken(){ | |
| // Create constants if necessary | |
| $password = CommonService::getInstance()->getSettings('STUDENT_PROFILE', 'STUDENT_PROFILE_KIOSK_PASSWORD'); | |
| global $COLLEGE_CODE; | |
| $payload = array( | |
| "col" => $COLLEGE_CODE, | |
| "rand" => bin2hex(openssl_random_pseudo_bytes(16)), | |
| "iss" => "https://linways.com", | |
| "exp" => time() + (30 * 24 * 60 * 60), // expires in 30 days | |
| "iat" => time() | |
| ); | |
| return JWT::encode($payload, $password ); | |
| } | |
| public function validateKioskAccessToken($token){ | |
| $password = CommonService::getInstance()->getSettings('STUDENT_PROFILE', 'STUDENT_PROFILE_KIOSK_PASSWORD'); | |
| JWT::$leeway = 60; // $leeway in seconds, This is optional | |
| return (array)JWT::decode($token, $password, array('HS256')); | |
| } | |
| } |