Example #1
0
 /**
  * displayRevokeGoogleAccess 
  * 
  * @return void
  */
 function displayRevokeGoogleAccess()
 {
     $config = getGoogleConfigData();
     if (isset($_SESSION['googleSessionToken'])) {
         $googleClient = new Google_Client();
         $googleClient->setClientId($config['google_client_id']);
         $googleClient->setClientSecret($config['google_client_secret']);
         $googleClient->setAccessType('offline');
         $googleClient->setScopes(array('https://www.googleapis.com/auth/youtube.force-ssl', 'https://www.googleapis.com/auth/userinfo.email', 'https://www.googleapis.com/auth/userinfo.profile', 'https://picasaweb.google.com/data/'));
         $googleClient->setRedirectUri($_SESSION['callback_url']);
         $googleClient->setAccessToken($_SESSION['googleSessionToken']);
         $googleClient->revokeToken();
         unset($_SESSION['googleSessionToken']);
     }
     $sql = "UPDATE `fcms_user_settings`\n                SET `google_session_token` = NULL\n                WHERE `user` = ?";
     if (!$this->fcmsDatabase->update($sql, $this->fcmsUser->id)) {
         $this->displayHeader();
         $this->fcmsError->displayError();
         $this->displayFooter();
         return;
     }
     header("Location: settings.php?view=google");
 }
Example #2
0
    /**
     * displayFormPage
     * 
     * Displays the form for configuring a google api.
     * 
     * @return void
     */
    function displayFormPage()
    {
        global $fcmsUser;
        $this->displayHeader();
        if (isset($_SESSION['success'])) {
            echo '
        <div class="alert-message success">
            <a class="close" href="#" onclick="$(this).up(\'div\').hide(); return false;">&times;</a>
            ' . T_('Changes Updated Successfully') . '
        </div>';
            unset($_SESSION['success']);
        }
        $r = getGoogleConfigData();
        $clientId = isset($r['google_client_id']) ? cleanOutput($r['google_client_id']) : '';
        $clientSecret = isset($r['google_client_secret']) ? cleanOutput($r['google_client_secret']) : '';
        echo '
        <div class="alert-message block-message info">
            <h1>' . T_('Google Integration') . '</h1>
            <p>
                ' . T_('In order to integrate Family Connections with Google, you must create a Google API Project.') . '
            </p>
        </div>';
        if (empty($clientId) || empty($clientSecret)) {
            echo '
        <div class="row">
            <div class="span4">
                <h2>' . T_('Step 1') . '</h2>
                <p>
                    ' . T_('Go to Google and create a new API Project.') . '
                </p>
            </div>
            <div class="span12">
                <ol>
                    <li>
                        ' . sprintf(T_('Open the %s.'), '<a href="http://console.developers.google.com/">' . T_('Google Developers Console') . '</a>') . '
                    </li>
                    <li>' . T_('Create a new Project.') . '</li>
                    <li>' . T_('Click APIs & auth.') . '</li>
                    <li>' . T_('Select Consent screen.') . '</li>
                    <li>' . T_('Fill out the Product name and any other optional information and Save.') . '
                    <li>' . T_('Select Credentials.') . '</li>
                    <li>' . T_('Click Create new Client ID.') . '</li>
                    <li>' . T_('Select Web application for the application type.') . '</li>
                    <li>' . T_('Fill out the Authorized redirct URIs, they need to end with "settings.php?view=google&oauth2callback".') . '</li>
                    <li>' . T_('Click Create Client ID.') . '</li>
                </ol>
            </div><!-- /span12 -->
        </div><!-- /row -->

        <p>&nbsp;</p>
        <p>&nbsp;</p>
        <p>&nbsp;</p>

        <div class="row">
            <div class="span4">
                <h2>' . T_('Step 2') . '</h2>
                <p>
                    ' . T_('Fill out the form below with the Client ID for web application detials you created in Step 1 above.') . '
                </p>
            </div>
            <div class="span12">';
        }
        echo '
                <form method="post" action="google.php">
                    <fieldset>
                        <legend>' . T_('Google') . '</legend>
                        <div class="clearfix">
                            <label for="client_id">' . T_('Client ID') . '</label>
                            <div class="input">
                                <input class="span6" type="text" name="client_id" id="client_id" value="' . $clientId . '"/>
                            </div>
                        </div>
                        <div class="clearfix">
                            <label for="client_secret">' . T_('Client secret') . '</label>
                            <div class="input">
                                <input class="span6" type="text" name="client_secret" id="client_secret" value="' . $clientSecret . '"/>
                            </div>
                        </div>
                        <div class="actions">
                            <input class="btn primary" type="submit" name="submit" value="' . T_('Save') . '"/>
                        </div>
                    </fieldset>
                </form>';
        if (empty($clientId) || empty($clientSecret)) {
            echo '
            </div><!-- /span12 -->
        </div><!-- /row -->';
        }
        $this->displayFooter();
    }
Example #3
0
/**
 * getAuthedGoogleClient
 *
 * Will return a Google_Client on success,
 * or false on failure.
 *
 * @return mixed
 */
function getAuthedGoogleClient($userId)
{
    $fcmsError = FCMS_Error::getInstance();
    $config = getGoogleConfigData();
    $user = getGoogleUserData($userId);
    if (empty($user['google_session_token'])) {
        return false;
    }
    if (empty($config['google_client_id']) || empty($config['google_client_secret'])) {
        return false;
    }
    // Setup url for callbacks
    $callbackUrl = getDomainAndDir();
    $callbackUrl .= 'settings.php?view=google&oauth2callback';
    $googleClient = new Google_Client();
    $googleClient->setClientId($config['google_client_id']);
    $googleClient->setClientSecret($config['google_client_secret']);
    $googleClient->setAccessType('offline');
    $googleClient->setScopes(array('https://www.googleapis.com/auth/youtube.force-ssl', 'https://www.googleapis.com/auth/userinfo.email', 'https://www.googleapis.com/auth/userinfo.profile', 'https://picasaweb.google.com/data/'));
    $googleClient->setRedirectUri($callbackUrl);
    // We still have a token saved
    if (isset($_SESSION['googleSessionToken'])) {
        try {
            $googleClient->setAccessToken($_SESSION['googleSessionToken']);
            // Make sure our access token is still good
            if ($googleClient->isAccessTokenExpired()) {
                $googleClient->refreshToken($user['google_session_token']);
            }
        } catch (Exception $e) {
            $fcmsError->add(array('type' => 'operation', 'message' => 'Could not get Google Session Token.', 'error' => $e, 'file' => __FILE__, 'line' => __LINE__));
            return false;
        }
    } elseif (!empty($user['google_session_token'])) {
        try {
            $googleClient->refreshToken($user['google_session_token']);
            $_SESSION['googleSessionToken'] = $googleClient->getAccessToken();
        } catch (Exception $e) {
            $fcmsError->add(array('type' => 'operation', 'message' => 'Could not get Google Session Token.', 'error' => $e, 'file' => __FILE__, 'line' => __LINE__));
            return false;
        }
    }
    return $googleClient;
}
Example #4
0
File: video.php Project: lmcro/fcms
 /**
  * checkUserAuthedYouTube 
  * 
  * Check to make sure the user is connected and authed at YouTube.
  * 
  * Assumed $this->displayHeader() already sent
  * 
  * @return void
  */
 function checkUserAuthedYouTube()
 {
     // Get session token
     $sql = "SELECT `google_session_token`\n                FROM `fcms_user_settings`\n                WHERE `user` = ?\n                AND `google_session_token` IS NOT NULL\n                AND `google_session_token` != ''";
     $row = $this->fcmsDatabase->getRow($sql, $this->fcmsUser->id);
     if ($row === false) {
         $this->fcmsError->displayError();
         $this->displayFooter();
         return;
     }
     if (empty($row)) {
         // TODO
         // Check that admin has setup google first.
         echo '
         <div class="info-alert">
             <h2>' . T_('Not connected to Google.') . '</h2>
             <p>' . T_('The video gallery relies on Gooble.  You must create a Google account and connect it with your Family Connections account.') . '</p>
             <p><a href="settings.php?view=google">' . T_('Connect to Google') . '</a></p>
         </div>';
         $this->displayFooter();
         die;
     }
     $_SESSION['google_session_token'] = $row['google_session_token'];
     $googleConfig = getGoogleConfigData();
 }