示例#1
0
 public function authenticate(CakeRequest $request, CakeResponse $response)
 {
     $req = $request->query;
     if (isset($req['openid_mode']) && $req['openid_mode'] != 'cancel') {
         $openid = new Lightopenid($_SERVER['SERVER_NAME']);
         $attr = $openid->getAttributes();
         $data = $openid->data;
         return $this->_findUser($attr['contact/email'], $data['openid_identity']);
     } else {
         return false;
     }
 }
示例#2
0
 function yahoo_openid_signin()
 {
     //$this->load->library('lightopenid'); // loaded in aotoload.php
     // these are some of the attributes we can get from open id
     // refer to
     // http://code.google.com/p/lightopenid/wiki/GettingMoreInformation
     // for more
     $required_attr = array('namePerson/friendly', 'contact/email', 'namePerson/first', 'namePerson/last', 'contact/country/home', 'contact/email', 'pref/language');
     try {
         if (!isset($_GET['openid_mode'])) {
             $lightopenid = new Lightopenid();
             $lightopenid->identity = 'http://me.yahoo.com';
             $lightopenid->required = $required_attr;
             redirect($lightopenid->authUrl(), 'refresh');
         } elseif ($_GET['openid_mode'] == 'cancel') {
             echo 'User has cancelled authentication!';
         } else {
             $lightopenid = new Lightopenid();
             $lightopenid->required = $required_attr;
             if ($lightopenid->validate()) {
                 #Here goes the code that gets interpreted after successful login!!!
                 //print_r($lightopenid);
                 //echo '<br/>';
                 //print_r($lightopenid->identity);
                 //print_r($lightopenid->getAttributes());
                 $yahoo_open_id = $lightopenid->identity;
                 $this->session->set_userdata('yahoo_open_id', $yahoo_open_id);
                 // does this user exist?
                 $user = $this->user_model->get_user_by_sm(array('yahoo_open_id' => $yahoo_open_id), 'yahoo_open_id');
                 if (sizeof($user) == 0) {
                     redirect('auth_other/fill_user_info', 'refresh');
                 } else {
                     // simulate what happens in the tank auth
                     $this->session->set_userdata(array('user_id' => $user[0]->id, 'username' => $user[0]->username, 'status' => $user[0]->activated == 1 ? STATUS_ACTIVATED : STATUS_NOT_ACTIVATED));
                     //$this->tank_auth->clear_login_attempts($user[0]->email); can't run this when doing twitter
                     redirect('auth', 'refresh');
                 }
             } else {
                 echo 'User has not logged in.';
             }
         }
     } catch (ErrorException $e) {
         echo $e->getMessage();
     }
 }
 /**
  *
  *
  * @return array
  */
 function yahoo()
 {
     App::import('Vendor', 'Users.openid/Lightopenid');
     $response = array();
     $openid = new Lightopenid($_SERVER['SERVER_NAME']);
     if ($openid->mode == 'cancel') {
         /* Do nothing user canceled authentication */
     } elseif (isset($_GET['openid_mode'])) {
         $ret = $openid->getAttributes();
         if (isset($ret['contact/email']) && $openid->validate()) {
             $response['email'] = $ret['contact/email'];
             $response['name'] = $ret['namePerson'];
             if ($ret['person/gender'] == "F") {
                 $response['gender'] = 'female';
             } else {
                 $response['gender'] = 'male';
             }
             $name = explode(' ', $ret['namePerson']);
             $response['first_name'] = $name[0];
             $last_name = '';
             if (isset($name[2])) {
                 unset($name[0]);
                 $last_name = implode(' ', $name);
             } else {
                 if (isset($name[1])) {
                     $last_name = $name[1];
                 }
             }
             $response['last_name'] = $last_name;
         }
     } else {
         $openid->identity = "http://me.yahoo.com/";
         $openid->required = array('contact/email', 'namePerson', 'person/gender');
         $openid->returnUrl = Router::url(array('plugin' => 'users', 'controller' => 'users', 'action' => 'login', 'yahoo'), true);
         $response['url'] = $openid->authUrl();
     }
     return $response;
 }
示例#4
0
    function openid()
    {
        //$this->load->library('openid');
        $this->load->library('Lightopenid');
        try {
            # Change 'localhost' to your domain name.
            $openid = new Lightopenid();
            if (!$openid->mode) {
                if (isset($_GET['login'])) {
                    if ($_GET['login'] == 'google') {
                        $openid->identity = 'https://www.google.com/accounts/o8/id';
                    } elseif ($_GET['login'] == 'yahoo') {
                        $openid->identity = 'http://me.yahoo.com';
                    }
                    $openid->required = array('namePerson/friendly', 'contact/email');
                    header('Location: ' . $openid->authUrl());
                }
                ?>
				<?php 
            } elseif ($openid->mode == 'cancel') {
                echo 'User has canceled authentication!';
            } else {
                //echo 'User ' . ($openid->validate() ? $openid->identity . ' has ' : 'has not ') . 'logged in.';
                if ($openid->validate()) {
                    //echo $openid->identity.'->';
                    $userdata = $openid->getAttributes();
                    //echo $userdata['contact/email'];
                    if ($user_info = $this->twfunctions->getOpenIDAuthenticateData($userdata['contact/email'])) {
                        $row = $user_info[0];
                        $access_token = random_string('alnum', 32);
                        if ($this->twfunctions->setAccessToken($row->id_users, $access_token)) {
                            $user_session = $row->session_id . '_' . $access_token;
                            if ($this->twfunctions->set_login_log($row->id_users)) {
                            }
                            $session_data = array('username' => $row->username, 'session_id' => $user_session, 'logged_in' => TRUE);
                            $this->session->set_userdata($session_data);
                            $redirect = $this->input->post('redirect', TRUE);
                            if ($redirect) {
                                redirect($redirect);
                            } else {
                                redirect('dashboard');
                            }
                        } else {
                            $this->session->set_flashdata('alert', 'Error');
                            redirect('login');
                        }
                    } else {
                        //signup form
                        $session_data = array('openid_identity' => $openid->identity, 'oiemail' => $userdata['contact/email'], 'logged_in' => FALSE);
                        $this->session->set_userdata($session_data);
                        redirect('landing/openidregister?openid=' . $_GET['login']);
                    }
                }
            }
        } catch (ErrorException $e) {
            //echo $e->getMessage();
        }
    }
示例#5
0
 public function openid()
 {
     if ($this->request->is('post')) {
         $openid = new Lightopenid($_SERVER['SERVER_NAME']);
         $openid->identity = $this->request->data['openid'];
         $openid->required = array('contact/email');
         if ($this->request->data['type'] == 'register') {
             $openid->returnUrl = 'http://' . $_SERVER['SERVER_NAME'] . Router::url(array('controller' => 'users', 'action' => 'register'));
         } else {
             $openid->returnUrl = 'http://' . $_SERVER['SERVER_NAME'] . Router::url(array('controller' => 'users', 'action' => 'login'));
         }
         $this->redirect($openid->authUrl());
     }
 }