Ejemplo n.º 1
0
 /**
  * Disconnect a socket connection when required, resource could be temp or verified
  * @param $resSocket
  * @param string $strErrorMessage
  * @param bool $blRebootAlert
  */
 protected function disconnect($resSocket, $strErrorMessage = "Unknown Reason for disconnect", $blRebootAlert = false)
 {
     if ($blRebootAlert == true) {
         $arrRebootData = array('instance' => '', 'system' => 'twist', 'action' => 'restart', 'message' => $strErrorMessage, 'data' => array('time' => 60 - date('s') + 5));
         Sockets::writeJSON($resSocket, $arrRebootData);
     }
     //Remove the socket from the list of connected sockets
     if (Sockets::isTemporary($resSocket)) {
         Sockets::removeTemporary($resSocket);
     } else {
         Sockets::remove($resSocket);
     }
     System::stats();
     System::log(sprintf("Disconnected from server: %s", $strErrorMessage));
 }
Ejemplo n.º 2
0
 /**
  * Validate the users login credentials, create their connection and user record or reject them from the system
  * @param $arrData
  * @param $resSocket
  */
 public static function login($arrData, $resSocket)
 {
     $arrResponse = array('instance' => array_key_exists('instance', $arrData) ? $arrData['instance'] : null, 'system' => 'twist', 'action' => 'login', 'message' => '', 'data' => array());
     //Detect the correct configuration of parameters provided
     $strUID = array_key_exists('uid', $arrData['data']) ? $arrData['data']['uid'] : 'guest';
     $strPassword = array_key_exists('password', $arrData['data']) ? $arrData['data']['password'] : null;
     //Get the users identification data
     $arrUserData = self::requestUserData($strUID, $strPassword);
     //If the user is valid then connect the user
     if ($arrUserData['status']) {
         if (Sockets::create($resSocket)) {
             Sockets::setData($resSocket, 'user_id', $arrUserData['data']['id']);
             $intUserID = self::createUser($arrUserData['data']);
             //Now send through the valid login details to the user when they login
             $arrResponse['message'] = $arrUserData['message'];
             $arrResponse['data'] = array('user_id' => $intUserID, 'valid' => !is_null($intUserID) ? true : false);
         } else {
             $arrResponse['action'] = 'login-failed';
             $arrResponse['message'] = 'Failed to login, unknown connection issue';
         }
         Sockets::writeJSON($resSocket, $arrResponse);
     } else {
         //Failed to login, tell the user and destroy the connection
         $arrResponse['action'] = 'login-failed';
         $arrResponse['message'] = $arrUserData['message'];
         Sockets::writeJSON($resSocket, $arrResponse);
         Sockets::removeTemporary($resSocket);
     }
     //Log user status to the admin users
     System::stats();
 }