source: extensions/oAuth/auth.php @ 23349

Last change on this file since 23349 was 21296, checked in by mistic100, 12 years ago

undefined variable $params

File size: 3.4 KB
Line 
1<?php
2define('PHPWG_ROOT_PATH', '../../');
3include_once(PHPWG_ROOT_PATH.'include/common.inc.php');
4
5global $hybridauth_conf;
6require_once(OAUTH_PATH . 'include/hybridauth/Hybrid/Auth.php');
7
8$provider = @$_GET['provider'];
9
10try {
11  // inputs
12  if ( $provider == 'OpenID' and !isset($_GET['openid_identifier']) )
13  {
14    throw new Exception('Invalid OpenID!', 1003);
15  }
16 
17  if (
18    !array_key_exists($provider, $hybridauth_conf['providers'])
19    or !$hybridauth_conf['providers'][$provider]['enabled']
20  ) {
21    throw new Exception('Hacking attempt!', 1002);
22  }
23 
24  $hybridauth = new Hybrid_Auth($hybridauth_conf);
25 
26  // connected
27  if ($hybridauth->isConnectedWith($provider))
28  {
29    $adapter = $hybridauth->getAdapter($provider);
30    $remote_user = $adapter->getUserProfile();
31   
32    $oauth_id = $provider.'---'.$remote_user->identifier;
33   
34    // check is already registered
35    $query = '
36SELECT id FROM '.USERS_TABLE.'
37  WHERE oauth_id = "'.$oauth_id.'"
38;';
39    $result = pwg_query($query);
40    // registered : log_user and redirect
41    if (pwg_db_num_rows($result))
42    {
43      list($user_id) = pwg_db_fetch_row($result);
44      log_user($user_id, false);
45     
46      $template->assign('REDIRECT_TO', 'default');
47    }
48    // not registered : redirect to register page
49    else
50    {
51      if ($conf['allow_user_registration'])
52      {
53        pwg_set_session_var('oauth_new_user', array($provider,$remote_user->identifier));
54        $template->assign('REDIRECT_TO', 'register');
55      }
56      else
57      {
58        $_SESSION['page_errors'][] = l10n('Sorry, new registrations are blocked on this gallery.');
59        $adapter->logout();
60        $template->assign('REDIRECT_TO', 'identification');
61      }
62    }
63  }
64  // init connect
65  else if (isset($_GET['init_auth']))
66  {
67    $params = array();
68    if ($provider == 'OpenID')
69    {
70      $params['openid_identifier'] = $_GET['openid_identifier'];
71    }
72     
73    // try to authenticate
74    $adapter = $hybridauth->authenticate($provider, $params);
75  }
76  // display loader
77  else
78  {
79    $template->assign('LOADING', '&openid_identifier='.@$_GET['openid_identifier'].'&init_auth=1');
80  }
81}
82/*
83 library errors :
84     0 : Unspecified error
85     1 : Hybriauth configuration error
86     2 : Provider not properly configured
87     3 : Unknown or disabled provider
88     4 : Missing provider application credentials
89     5 : Authentication aborded
90     6 : User profile request failed
91 other errors :
92  1002 : Invalid provider
93  1003 : Missing openid_identifier
94*/
95catch (Exception $e) {
96  switch ($e->getCode()) {
97    case 5:
98      $template->assign('ERROR', l10n('Authentication canceled')); break;
99    case 404:
100      $template->assign('ERROR', l10n('User not found')); break;
101    default:
102      $template->assign('ERROR', sprintf(l10n('An error occured, please contact the gallery owner. <i>Error code : %s</i>'), '<span title="'.$e->getMessage().'">'.$e->getCode().'</span>'));
103  }
104}
105
106
107$template->assign(array(
108  'GALLERY_TITLE' => $conf['gallery_title'],
109  'CONTENT_ENCODING' => get_pwg_charset(),
110  'U_HOME' => get_gallery_home_url(),
111 
112  'OAUTH_PATH' => OAUTH_PATH,
113  'PROVIDER' => $provider,
114  'SELF_URL' => OAUTH_PATH . 'auth.php?provider='.$provider,
115  ));
116
117$template->set_filename('index', realpath(OAUTH_PATH . 'template/auth.tpl'));
118$template->pparse('index');
119?>
Note: See TracBrowser for help on using the repository browser.