当前位置: 首页>>代码示例>>PHP>>正文


PHP UserIdentity::authenticateOutside方法代码示例

本文整理汇总了PHP中UserIdentity::authenticateOutside方法的典型用法代码示例。如果您正苦于以下问题:PHP UserIdentity::authenticateOutside方法的具体用法?PHP UserIdentity::authenticateOutside怎么用?PHP UserIdentity::authenticateOutside使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在UserIdentity的用法示例。


在下文中一共展示了UserIdentity::authenticateOutside方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: actionRegisterLinkedIn

 public function actionRegisterLinkedIn()
 {
     // if user canceled, redirect to home page
     if (isset($_GET['oauth_problem'])) {
         $problem = $_GET['oauth_problem'];
         if ($problem == 'user_refused') {
             $this->redirect('/JobFair/index.php');
         }
     }
     if (!isset($_SESSION)) {
         session_start();
     }
     //edit by Manuel making the link dynamic, using Yii
     $config['base_url'] = 'http://' . Yii::app()->request->getServerName() . '/JobFair/index.php/user/auth1.php';
     $config['callback_url'] = 'http://' . Yii::app()->request->getServerName() . '/JobFair/index.php/user/RegisterLinkedIn';
     $config['linkedin_access'] = '2rtmn93gu2m4';
     $config['linkedin_secret'] = 'JV0fYG9ls3rclP8v';
     include_once Yii::app()->basePath . "/views/user/linkedin.php";
     # First step is to initialize with your consumer key and secret. We'll use an out-of-band oauth_callback
     $linkedin = new LinkedIn($config['linkedin_access'], $config['linkedin_secret'], $config['callback_url']);
     //$linkedin->debug = true;
     if (isset($_REQUEST['oauth_verifier'])) {
         $_SESSION['oauth_verifier'] = $_REQUEST['oauth_verifier'];
         $linkedin->request_token = unserialize($_SESSION['requestToken']);
         $linkedin->oauth_verifier = $_SESSION['oauth_verifier'];
         $linkedin->getAccessToken($_REQUEST['oauth_verifier']);
         $_SESSION['oauth_access_token'] = serialize($linkedin->access_token);
         header("Location: " . $config['callback_url']);
         exit;
     } else {
         $linkedin->request_token = unserialize($_SESSION['requestToken']);
         $linkedin->oauth_verifier = $_SESSION['oauth_verifier'];
         $linkedin->access_token = unserialize($_SESSION['oauth_access_token']);
     }
     # You now have a $linkedin->access_token and can make calls on behalf of the current member
     $xml_response = $linkedin->getProfile("~:(id,first-name,last-name,headline,picture-url,industry,email-address,languages,phone-numbers,skills,educations,location:(name),positions,picture-urls::(original))");
     $data = simplexml_load_string($xml_response);
     // get user by linkedinid
     $model = new User();
     $user = User::model()->findByAttributes(array('linkedinid' => $data->id));
     // check if user exits in database, if so login
     if ($user != null) {
         if ($user->disable != 1) {
             $identity = new UserIdentity($user->username, '');
             if ($identity->authenticateOutside()) {
                 Yii::app()->user->login($identity);
             }
             $this->redirect("/JobFair/index.php/home/studenthome");
             return;
         } else {
             $this->redirect("/JobFair/index.php/site/page?view=disableUser");
             return;
         }
         // register
     } else {
         // 			print "<pre>"; print_r('user is null');print "</pre>";
         // check that there is no duplicate user if so link to that account
         $duplicateUser = User::model()->findByAttributes(array('email' => $data->{'email-address'}));
         if ($duplicateUser != null) {
             // get username and link the accounts
             $username = $duplicateUser->username;
             $user = User::model()->find("username=:username", array(':username' => $username));
             $user->linkedinid = $data->{'id'};
             $user->save(false);
             $user_id = $user->id;
             // ------------------BASIC INFO---------------
             $basic_info = null;
             $basic_info = BasicInfo::model()->findByAttributes(array('userid' => $user_id));
             if ($basic_info == null) {
                 $basic_info = new BasicInfo();
             }
             $basic_info->userid = $user_id;
             $basic_info->save(false);
             // ------------------BASIC INFO -----------------
             // -----------------EDUCATION ----------------------
             // get number of educations to add
             $educ_count = $data->educations['total'];
             // delete current educations
             $delete_educs = Education::model()->findAllByAttributes(array('FK_user_id' => $user_id));
             foreach ($delete_educs as $de) {
                 $de->delete();
             }
             // add educations
             for ($i = 0; $i < $educ_count; $i++) {
                 // first check if current education is in school table. if not, add it
                 $current_school_name = $data->educations->education[$i]->{'school-name'};
                 $school_exists = School::model()->findByAttributes(array('name' => $current_school_name));
                 if ($school_exists == null) {
                     $new_school = new School();
                     $new_school->name = $current_school_name;
                     $new_school->save();
                     $school_id = School::model()->findByAttributes(array('name' => $current_school_name))->id;
                 } else {
                     $school_id = $school_exists->id;
                 }
                 // now ready to add new education
                 $new_educ = new Education();
                 $new_educ->degree = $data->educations->education[$i]->degree;
                 $new_educ->major = $data->educations->education[$i]->{'field-of-study'};
                 // 	   	$model->admission_date=date('Y-m-d',strtotime($model->admission_date));
//.........这里部分代码省略.........
开发者ID:erick305,项目名称:testing,代码行数:101,代码来源:UserController.php

示例2: actionFiuAuth

 public function actionFiuAuth()
 {
     ########## Google Settings.. Client ID, Client Secret #############
     //edit by Manuel, making the links dynamic, using Yii
     //To access the google API console to be able to change the setting
     //go to https://code.google.com/apis/console/?noredirect#project:44822970295:access
     //E-mail: virtualjobfairfiu@gmail.com
     //PASS: cis49112014
     $google_client_id = '44822970295-ub8arp3hk5as3s549jdmgl497rahs6jl.apps.googleusercontent.com';
     $google_client_secret = 'RsCRTYbGC4VZc40ppLR-4L5h';
     $google_redirect_url = 'http://' . Yii::app()->request->getServerName() . '/JobFair/index.php/profile/fiuAuth/oauth2callback';
     $google_developer_key = 'AIzaSyBRvfT7Djj4LZUrHqLdZfJRWBLubk51ARA';
     //include google api files
     require_once Yii::app()->basePath . "/fiu/Google_Client.php";
     require_once Yii::app()->basePath . "/fiu/contrib/Google_Oauth2Service.php";
     $gClient = new Google_Client();
     $gClient->setApplicationName('Login to JobFair');
     $gClient->setClientId($google_client_id);
     $gClient->setClientSecret($google_client_secret);
     $gClient->setRedirectUri($google_redirect_url);
     $gClient->setDeveloperKey($google_developer_key);
     $google_oauthV2 = new Google_Oauth2Service($gClient);
     //If user wish to log out, we just unset Session variable
     if (isset($_REQUEST['reset'])) {
         unset($_SESSION['token']);
         $gClient->revokeToken();
         header('Location: ' . filter_var($google_redirect_url, FILTER_SANITIZE_URL));
     }
     if (isset($_GET['code'])) {
         $gClient->authenticate($_GET['code']);
         $_SESSION['token'] = $gClient->getAccessToken();
         header('Location: ' . filter_var($google_redirect_url, FILTER_SANITIZE_URL));
         return;
     }
     // if user canceled, redirect to home page
     if (isset($_GET['error'])) {
         $problem = $_GET['error'];
         $this->redirect('/JobFair/index.php');
     }
     if (isset($_SESSION['token'])) {
         $gClient->setAccessToken($_SESSION['token']);
     }
     if ($gClient->getAccessToken()) {
         //Get user details if user is logged in
         $user = $google_oauthV2->userinfo->get();
         $user_id = $user['id'];
         $user_name = filter_var($user['name'], FILTER_SANITIZE_SPECIAL_CHARS);
         $email = filter_var($user['email'], FILTER_SANITIZE_EMAIL);
         $_SESSION['token'] = $gClient->getAccessToken();
     } else {
         //get google login url
         $authUrl = $gClient->createAuthUrl();
     }
     if (isset($authUrl)) {
         $this->redirect($authUrl);
     }
     //link Fiu Account account to the current one
     $currentUser = User::getCurrentUser();
     if ($currentUser != null && $currentUser->FK_usertype == 1) {
         // check that there is no duplicate id
         $duplicateUser = User::model()->findByAttributes(array('fiu_account_id' => $user_id));
         if ($duplicateUser != null) {
             $this->actionDuplicationError();
             return;
         }
         $username = Yii::app()->user->name;
         $userLink = User::model()->find("username=:username", array(':username' => $username));
         $userLink->fiu_account_id = $user_id;
         $userLink->save(false);
         //get variables
         $mesg = "FIU Email";
         $phone = null;
         $city = null;
         $state = null;
         $about_me = null;
         $this->actionLinkToo($email, $user['given_name'], $user['family_name'], $user['picture'], $mesg, $phone, $city, $state, $about_me);
         return;
     } else {
         $userExists = User::model()->findByAttributes(array('fiu_account_id' => $user["id"]));
         // if user exists with fiu_account_id, login
         if ($userExists != null) {
             if ($userExists->disable != 1) {
                 $identity = new UserIdentity($userExists->username, '');
                 if ($identity->authenticateOutside()) {
                     Yii::app()->user->login($identity);
                 }
                 $this->redirect("/JobFair/index.php/home/studenthome");
                 return;
             } else {
                 $this->redirect("/JobFair/index.php/site/page?view=disableUser");
                 return;
             }
         } else {
             // check that there is no duplicate user
             $duplicateUser = User::model()->findByAttributes(array('email' => $user['email']));
             if ($duplicateUser != null) {
                 //populate db
                 $duplicateUser->fiu_account_id = $user_id;
                 $duplicateUser->save(false);
                 if ($duplicateUser->disable != 1) {
//.........这里部分代码省略.........
开发者ID:erick305,项目名称:testing,代码行数:101,代码来源:ProfileController.php


注:本文中的UserIdentity::authenticateOutside方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。