Exemplo n.º 1
0
 /**
  * Creates an instance of this class (only once) and returns it
  * @return GoogleAuth
  */
 public static function getInstance()
 {
     # Create the instance if it hasn't been created yet
     if (!isset(GoogleAuth::$instance)) {
         GoogleAuth::$instance = new GoogleAuth();
     }
     # Set auth access token
     # Access token is session is set when user successfully signs in
     # using Google and is returned back to the page (the method to catch the code
     # that is passed back is in index.php)
     GoogleAuth::$auth = HTTPSession::getInstance()->ACCESS_TOKEN;
     # If auth code is not empty, it means that user was successfully signed in
     # using Google sign in, therefore set the received access token for client
     # and authorise using HTTPSession
     if (!empty(GoogleAuth::$auth)) {
         GoogleAuth::$instance->setToken();
         # TODO: First we need to check if session is still valid
         # This implementation needs to be finished in the future version,
         # since it gets more complex and takes too much time
         if (GoogleAuth::$instance->checkIfExpired()) {
             echo "Google session expired";
             die;
         }
         # Login the user using provided email
         HTTPSession::getInstance()->LoginGoogle(GoogleAuth::$instance->getUserEmail());
     }
     # Return the new instance or already existing instance
     return GoogleAuth::$instance;
 }