コード例 #1
0
ファイル: login-controller.php プロジェクト: stas/bebuntu
 function login()
 {
     if ($_POST['openid_action'] == "login") {
         $openid = new OpenID();
         $openid->SetIdentity($_POST['openid_url']);
         $openid->SetTrustRoot('http://' . $_SERVER["HTTP_HOST"]);
         $openid->SetRequiredFields(array('nickname', 'email', 'fullname'));
         //$openid->SetOptionalFields(array('dob','gender','postcode','country','language','timezone'));
         if ($openid->GetOpenIDServer()) {
             $openid->SetApprovedURL('http://' . $_SERVER["HTTP_HOST"] . $_SERVER["PATH_INFO"]);
             $openid->Redirect();
         } else {
             $error = $openid->GetError();
             $this->message = "ERROR CODE: " . $error['code'] . "<br/>";
             $this->message .= "ERROR DESCRIPTION: " . $error['description'] . "<br/>";
         }
         exit;
     } else {
         if ($_GET['openid_mode'] == 'id_res') {
             $openid = new OpenID();
             $openid->SetIdentity($_GET['openid_identity']);
             $openid_validation_result = $openid->ValidateWithServer();
             if ($openid_validation_result == true) {
                 $this->user->set('nickname', $_GET['openid_sreg_nickname']);
                 $this->user->set('identity', $_GET['openid_identity']);
                 $this->message = "Welcome " . $this->user->get('nickname');
             } else {
                 if ($openid->IsError() == true) {
                     $error = $openid->GetError();
                     $this->message = "ERROR CODE: " . $error['code'] . "<br/>";
                     $this->message .= "ERROR DESCRIPTION: " . $error['description'] . "<br/>";
                 } else {
                     $this->message = "INVALID AUTHORIZATION";
                 }
             }
         } else {
             if ($_GET['openid_mode'] == 'cancel') {
                 $this->message = "USER CANCELED REQUEST";
             }
         }
     }
 }