[ Index ]

PHP Cross Reference of Joomla 1.5.26 DE

title

Body

[close]

/plugins/authentication/ -> gmail.php (source)

   1  <?php
   2  /**
   3   * @version        $Id: gmail.php 14401 2010-01-26 14:10:00Z louis $
   4   * @package        Joomla
   5   * @subpackage    JFramework
   6   * @copyright    Copyright (C) 2005 - 2010 Open Source Matters. All rights reserved.
   7   * @license        GNU/GPL, see LICENSE.php
   8   * Joomla! is free software. This version may have been modified pursuant
   9   * to the GNU General Public License, and as distributed it includes or
  10   * is derivative of works licensed under the GNU General Public License or
  11   * other free or open source software licenses.
  12   * See COPYRIGHT.php for copyright notices and details.
  13   */
  14  
  15  // Check to ensure this file is included in Joomla!
  16  defined('_JEXEC') or die( 'Restricted access' );
  17  
  18  jimport( 'joomla.plugin.plugin' );
  19  
  20  /**
  21   * GMail Authentication Plugin
  22   *
  23   * @package        Joomla
  24   * @subpackage    JFramework
  25   * @since 1.5
  26   */
  27  class plgAuthenticationGMail extends JPlugin
  28  {
  29      /**
  30       * Constructor
  31       *
  32       * For php4 compatability we must not use the __constructor as a constructor for plugins
  33       * because func_get_args ( void ) returns a copy of all passed arguments NOT references.
  34       * This causes problems with cross-referencing necessary for the observer design pattern.
  35       *
  36       * @param object $subject The object to observe
  37       * @param     array  $config  An array that holds the plugin configuration
  38       * @since 1.5
  39       */
  40  	function plgAuthenticationGMail(& $subject, $config) {
  41          parent::__construct($subject, $config);
  42      }
  43  
  44      /**
  45       * This method should handle any authentication and report back to the subject
  46       *
  47       * @access    public
  48       * @param   array     $credentials Array holding the user credentials
  49       * @param     array   $options     Array of extra options
  50       * @param    object    $response    Authentication response object
  51       * @return    boolean
  52       * @since 1.5
  53       */
  54  	function onAuthenticate( $credentials, $options, &$response )
  55      {
  56          $message = '';
  57          $success = 0;
  58          if(function_exists('curl_init'))
  59          {
  60              if(strlen($credentials['username']) && strlen($credentials['password']))
  61              {
  62                  $curl = curl_init('https://mail.google.com/mail/feed/atom');
  63                  curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
  64                  curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
  65                  //curl_setopt($curl, CURLOPT_HEADER, 1);
  66                  curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
  67                  curl_setopt($curl, CURLOPT_USERPWD, $credentials['username'].':'.$credentials['password']);
  68                  $result = curl_exec($curl);
  69                  $code = curl_getinfo ($curl, CURLINFO_HTTP_CODE);
  70  
  71                  switch($code)
  72                  {
  73                      case 200:
  74                           $message = 'Access Granted';
  75                           $success = 1;
  76                      break;
  77                      case 401:
  78                          $message = 'Access Denied';
  79                      break;
  80                      default:
  81                          $message = 'Result unknown, access denied.';
  82                          break;
  83                  }
  84              }
  85              else  {
  86                  $message = 'Username or password blank';
  87              }
  88          }
  89          else {
  90              $message = 'curl isn\'t installed';
  91          }
  92  
  93          if ($success)
  94          {
  95              $response->status          = JAUTHENTICATE_STATUS_SUCCESS;
  96              $response->error_message = '';
  97              $response->email     = $credentials['username'];
  98              $response->fullname = $credentials['username'];
  99          }
 100          else
 101          {
 102              $response->status         = JAUTHENTICATE_STATUS_FAILURE;
 103              $response->error_message    = 'Failed to authenticate: ' . $message;
 104          }
 105      }
 106  }


Generated: Wed Mar 28 15:54:07 2012 Cross-referenced by PHPXref 0.7.1