source: extensions/oAuth/include/test/examples/social_hub/profile.php @ 20293

Last change on this file since 20293 was 20293, checked in by mistic100, 11 years ago

first commit of oAuth plugin, still in developpement

File size: 7.1 KB
Line 
1<?php
2        // config and whatnot
3    $config = dirname(__FILE__) . '/../../hybridauth/config.php';
4    require_once( "../../hybridauth/Hybrid/Auth.php" );
5
6        $user_data = NULL;
7
8        // try to get the user profile from an authenticated provider
9        try{
10                $hybridauth = new Hybrid_Auth( $config );
11
12                // selected provider name
13                $provider = @ trim( strip_tags( $_GET["provider"] ) );
14
15                // check if the user is currently connected to the selected provider
16                if( !  $hybridauth->isConnectedWith( $provider ) ){ 
17                        // redirect him back to login page
18                        header( "Location: login.php?error=Your are not connected to $provider or your session has expired" );
19                }
20
21                // call back the requested provider adapter instance (no need to use authenticate() as we already did on login page)
22                $adapter = $hybridauth->getAdapter( $provider );
23
24                // grab the user profile
25                $user_data = $adapter->getUserProfile();
26    }
27        catch( Exception $e ){ 
28                // In case we have errors 6 or 7, then we have to use Hybrid_Provider_Adapter::logout() to
29                // let hybridauth forget all about the user so we can try to authenticate again.
30
31                // Display the recived error,
32                // to know more please refer to Exceptions handling section on the userguide
33                switch( $e->getCode() ){ 
34                        case 0 : echo "Unspecified error."; break;
35                        case 1 : echo "Hybriauth configuration error."; break;
36                        case 2 : echo "Provider not properly configured."; break;
37                        case 3 : echo "Unknown or disabled provider."; break;
38                        case 4 : echo "Missing provider application credentials."; break;
39                        case 5 : echo "Authentication failed. " 
40                                          . "The user has canceled the authentication or the provider refused the connection."; 
41                        case 6 : echo "User profile request failed. Most likely the user is not connected "
42                                          . "to the provider and he should to authenticate again."; 
43                                   $adapter->logout(); 
44                                   break;
45                        case 7 : echo "User not connected to the provider."; 
46                                   $adapter->logout(); 
47                                   break;
48                } 
49
50                echo "<br /><br /><b>Original error message:</b> " . $e->getMessage();
51
52                echo "<hr /><h3>Trace</h3> <pre>" . $e->getTraceAsString() . "</pre>"; 
53        }
54?>
55<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
56<html lang="en">
57<head> 
58<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
59<link rel="stylesheet" href="public/css.css" type="text/css">
60</head>
61<body> 
62<?php
63        if( $user_data ){
64?> 
65<table width="90%" border="0" cellpadding="2" cellspacing="2">
66  <tr>
67    <td valign="top">
68                <?php
69                        include "includes/menu.php";
70                ?> 
71                <fieldset>
72        <legend>Profile information</legend>
73        <table width="100%">
74          <tr>
75            <td width="150" valign="top" align="center">
76                                <?php
77                                        if( $user_data->photoURL ){
78                                ?>
79                                        <a href="<?php echo $user_data->profileURL; ?>"><img src="<?php echo $user_data->photoURL; ?>" title="<?php echo $user_data->displayName; ?>" border="0" width="100" height="120"></a>
80                                <?php
81                                        }
82                                        else{
83                                ?> 
84                                <img src="public/avatar.png" title="<?php echo $user_data->displayName; ?>" border="0" >
85                                <?php
86                                        } 
87                                ?> 
88                        </td>
89            <td align="left"><table width="100%" cellspacing="0" cellpadding="3" border="0">
90                <tbody>
91                  <tr>
92                    <td width="10%">providerID</td>
93                    <td width="83%">&nbsp; <?php echo $adapter->id; ?></td>
94                  </tr>
95                  <tr>
96                    <td width="10%">identifier</td>
97                    <td width="83%">&nbsp; <?php echo $user_data->identifier; ?></td>
98                  </tr>
99                  <tr>
100                    <td>profileURL</td>
101                    <td>&nbsp; <a href="<?php echo $user_data->profileURL; ?>"><?php echo $user_data->profileURL; ?></a></td>
102                  </tr>
103                  <tr>
104                    <td>webSiteURL</td>
105                    <td>&nbsp; <?php echo $user_data->webSiteURL; ?></td>
106                  </tr>
107                  <tr>
108                    <td>photoURL</td>
109                    <td>&nbsp; <?php echo $user_data->photoURL; ?></td>
110                  </tr>
111                  <tr>
112                    <td>displayName</td>
113                    <td>&nbsp; <?php echo $user_data->displayName; ?></td>
114                  </tr>
115                  <tr>
116                    <td>description</td>
117                    <td>&nbsp; <?php echo $user_data->description; ?></td>
118                  </tr>
119                  <tr>
120                    <td>firstName</td>
121                    <td>&nbsp; <?php echo $user_data->firstName; ?></td>
122                  </tr>
123                  <tr>
124                    <td>lastName</td>
125                    <td>&nbsp; <?php echo $user_data->lastName; ?></td>
126                  </tr>
127                  <tr>
128                    <td>gender</td>
129                    <td>&nbsp; <?php echo $user_data->gender; ?></td>
130                  </tr>
131                  <tr>
132                    <td>language</td>
133                    <td>&nbsp; <?php echo $user_data->language; ?></td>
134                  </tr>
135                  <tr>
136                    <td>age</td>
137                    <td>&nbsp; <?php echo $user_data->age; ?></td>
138                  </tr>
139                  <tr>
140                    <td>birthDay</td>
141                    <td>&nbsp; <?php echo $user_data->birthDay; ?></td>
142                  </tr>
143                  <tr>
144                    <td>birthMonth</td>
145                    <td>&nbsp; <?php echo $user_data->birthMonth; ?></td>
146                  </tr>
147                  <tr>
148                    <td>birthYear</td>
149                    <td>&nbsp; <?php echo $user_data->birthYear; ?></td>
150                  </tr>
151                  <tr>
152                    <td>email</td>
153                    <td>&nbsp; <?php echo $user_data->email; ?></td>
154                  </tr>
155                  <tr>
156                    <td>phone</td>
157                    <td>&nbsp; <?php echo $user_data->phone; ?></td>
158                  </tr>
159                  <tr>
160                    <td>address</td>
161                    <td>&nbsp; <?php echo $user_data->address; ?></td>
162                  </tr>
163                  <tr>
164                    <td>country</td>
165                    <td>&nbsp; <?php echo $user_data->country; ?></td>
166                  </tr>
167                  <tr>
168                    <td>region</td>
169                    <td>&nbsp; <?php echo $user_data->region; ?></td>
170                  </tr>
171                  <tr>
172                    <td>city</td>
173                    <td>&nbsp; <?php echo $user_data->city; ?></td>
174                  </tr>
175                  <tr>
176                    <td>zip</td>
177                    <td>&nbsp; <?php echo $user_data->zip; ?></td>
178                  </tr>
179                </tbody>
180              </table>
181                          </td>
182          </tr> 
183        </table>
184                </fieldset>
185        </td>
186    <td valign="top" width="250" align="left">
187                <?php
188                        include "includes/sidebar.php";
189                ?>
190        </td>
191  </tr>
192</table> 
193<?php
194        } // if( $user_data )
195
196        include "includes/debugger.php";
197?> 
198</body>
199</html>
Note: See TracBrowser for help on using the repository browser.