diff --git a/www/application/controllers/Home.php b/www/application/controllers/Home.php index 7321b4d9..223d64e6 100644 --- a/www/application/controllers/Home.php +++ b/www/application/controllers/Home.php @@ -23,12 +23,16 @@ class Home extends WRB_Controller { // Load Hybridauth's helper $this->load->helper('hybridauth'); + /* // Instantiate Hybridauth's classes $hybrid = new Hybridauth(get_hybridauth_config()); // Get login links $login_links = get_hybridauth_links($hybrid, $this->router); - + */ + $login_links = array( + 'Google' => get_google_login_link() + ); // Pass login links to html template $data['login_links'] = $login_links; diff --git a/www/application/controllers/Login.php b/www/application/controllers/Login.php index 8b91d60e..2866c93c 100644 --- a/www/application/controllers/Login.php +++ b/www/application/controllers/Login.php @@ -162,12 +162,16 @@ class Login extends WRB_Controller { // Load Hybridauth's helper $this->load->helper('hybridauth'); + /* // Instantiate Hybridauth's classes $hybrid = new Hybridauth(get_hybridauth_config()); // Get login links $login_links = get_hybridauth_links($hybrid, $this->router); - + */ + $login_links = array( + 'Google' => get_google_login_link() + ); // Pass login links to html template $data['login_links'] = $login_links; @@ -216,6 +220,82 @@ class Login extends WRB_Controller { //Processes social login function auth($provider = NULL) + { + // Load Hybridauth's helper + $this->load->helper('hybridauth'); + $code = $this->input->get('code'); + if ($code!='') { + $client = get_google_client(); + $token = $client->fetchAccessTokenWithAuthCode($code); + $client->setAccessToken($token['access_token']); + + // get profile info + $google_oauth = new Google_Service_Oauth2($client); + $google_account_info = $google_oauth->userinfo->get(); + $email = $google_account_info->email; + $name = $google_account_info->name; + + var_dump($google_account_info); + exit(); + + if ($email != '') { + /* + $user = array( + 'id' => '', + 'name' => '', + 'email' => '' + ); + list($proceed, $data) = $this->checkUserExists($user, $data); + + // TODO + if ($proceed) { + $name = (string) $user["name"]; + if (trim($name) == "") + $name = strtok($user["email"], "@"); + $data['fb_id'] = $user["id"]; + $data['firstname'] = strtok($name, " "); + $data['lastname'] = strtok(" "); + $data['email'] = $user["email"]; + $data['sessionid'] = rand(10000, 99999) . "A" . rand(10000, 99999); + $data['action'] = WRENCHBOARD_FACEBOOK_LOGIN; + $this->load->model('backend_model'); + $out = array(); + $res = $this->backend_model->wrenchboard_api($data, $out); + if ($res == PHP_LOGIN_OK) { + $this->load->model('account_model'); + $ret = $this->account_model->username_data($out); + if ($res !== false) { + $data["login_message"] = "Welcome..."; + // yes person has an account + $_SESSION['session_id'] = $out["session"]; + $_SESSION['username'] = $ret->username; + $_SESSION['name'] = $ret->username; + $_SESSION['firstname'] = $ret->firstname; + $_SESSION['lastname'] = $ret->lastname; + $_SESSION['email'] = $ret->email; + $_SESSION['member_id'] = $ret->id; + $_SESSION['log_count'] = 0; + $_SESSION['mesaage_count'] = 0; + $this->findOffers($_SESSION['email']); + $_SESSION['message_snapshot'] = $this->myMessagesSnapshot(); + + $this->logUser('Account login'); + $this->refreshAccountDetail($_SESSION['member_id']); + $this->getSessionArray(); + + $this->excudedEmails(); + + redirect('dash'); + } + } + } + // */ + } + } + } + + //Processes social login + function authh($provider = NULL) { // Load Hybridauth's helper $this->load->helper('hybridauth'); @@ -239,6 +319,8 @@ class Login extends WRB_Controller { if ($provider) { $service = $hybrid->authenticate($provider); + var_dump($service); + exit(); if ($service->isConnected()) { //Get user profile @@ -260,58 +342,6 @@ class Login extends WRB_Controller { echo 'Name: ' . $profile->displayName; print_r($profile); exit(); - - /* - $user = array( - 'id' => '', - 'name' => '', - 'email' => '' - ); - list($proceed, $data) = $this->checkUserExists($user, $data); - - // TODO - if ($proceed) { - $name = (string) $user["name"]; - if (trim($name) == "") - $name = strtok($user["email"], "@"); - $data['fb_id'] = $user["id"]; - $data['firstname'] = strtok($name, " "); - $data['lastname'] = strtok(" "); - $data['email'] = $user["email"]; - $data['sessionid'] = rand(10000, 99999) . "A" . rand(10000, 99999); - $data['action'] = WRENCHBOARD_FACEBOOK_LOGIN; - $this->load->model('backend_model'); - $out = array(); - $res = $this->backend_model->wrenchboard_api($data, $out); - if ($res == PHP_LOGIN_OK) { - $this->load->model('account_model'); - $ret = $this->account_model->username_data($out); - if ($res !== false) { - $data["login_message"] = "Welcome..."; - // yes person has an account - $_SESSION['session_id'] = $out["session"]; - $_SESSION['username'] = $ret->username; - $_SESSION['name'] = $ret->username; - $_SESSION['firstname'] = $ret->firstname; - $_SESSION['lastname'] = $ret->lastname; - $_SESSION['email'] = $ret->email; - $_SESSION['member_id'] = $ret->id; - $_SESSION['log_count'] = 0; - $_SESSION['mesaage_count'] = 0; - $this->findOffers($_SESSION['email']); - $_SESSION['message_snapshot'] = $this->myMessagesSnapshot(); - - $this->logUser('Account login'); - $this->refreshAccountDetail($_SESSION['member_id']); - $this->getSessionArray(); - - $this->excudedEmails(); - - redirect('dash'); - } - } - } - // */ } else { diff --git a/www/application/controllers/Site.php b/www/application/controllers/Site.php index f9226a8c..ad9e2eee 100644 --- a/www/application/controllers/Site.php +++ b/www/application/controllers/Site.php @@ -17,12 +17,16 @@ class Site extends WRB_Controller { // Load Hybridauth's helper $this->load->helper('hybridauth'); + /* // Instantiate Hybridauth's classes $hybrid = new Hybridauth(get_hybridauth_config()); // Get login links $login_links = get_hybridauth_links($hybrid, $this->router); - + */ + $login_links = array( + 'Google' => get_google_login_link() + ); // Pass login links to html template $data['login_links'] = $login_links; diff --git a/www/application/helpers/hybridauth_helper.php b/www/application/helpers/hybridauth_helper.php index 40c669ce..5e35f080 100644 --- a/www/application/helpers/hybridauth_helper.php +++ b/www/application/helpers/hybridauth_helper.php @@ -1,5 +1,60 @@ setClientId($clientID); + $client->setClientSecret($clientSecret); + $client->setRedirectUri($redirectUri); + $client->addScope("email"); + $client->addScope("profile"); + + return $client; + } +} + +if ( ! function_exists('get_google_login_link')) +{ + // Get Google login link + function get_google_login_link() + { + $client = get_google_client(); + return $client->createAuthUrl(); + } +} + if ( ! function_exists('get_hybridauth_config')) { //Hybridauth configuration @@ -17,7 +72,6 @@ if ( ! function_exists('get_hybridauth_config')) 'secret' => 'aozK_2G8UjaCmLgPPkv9abIm' ) , 'scope' => 'https://www.googleapis.com/auth/plus.login https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/userinfo.profile', - 'redirect_uri' => site_url('login/auth/') . '?hauth.done=google' ) , 'Facebook' => array( diff --git a/www/composer.json b/www/composer.json index ca90d080..9c9ac042 100644 --- a/www/composer.json +++ b/www/composer.json @@ -13,9 +13,10 @@ "require": { "php": ">=5.3.7", "facebook/php-sdk-v4" : "~5.0", - "firebase/php-jwt": "^6.0", + "firebase/php-jwt": "^5.5.1", "phpseclib/phpseclib": "^3.0", - "hybridauth/hybridauth" : "~3.7.1" + "hybridauth/hybridauth" : "~3.7.1", + "google/apiclient":"^2.12.1" }, "suggest": { "paragonie/random_compat": "Provides better randomness in PHP 5.x"