File manager - Edit - /home/wwwroot/camplus.hk/master.camplus.hk/public_html/application/modules/core/controllers/User_Authentication.php
Back
<?php defined('BASEPATH') OR exit('No direct script access allowed'); class User_Authentication extends MY_Controller { function __construct() { parent::__construct(); // Load user model $this->load->model('User_model'); } public function index(){ // Include the google api php libraries include_once APPPATH."libraries/google-api-php-client/Google_Client.php"; include_once APPPATH."libraries/google-api-php-client/contrib/Google_Oauth2Service.php"; // Google Project API Credentials $settings = $this->User_model->get_site_settings(); //$settings['google-redirect']; $clientId = $settings['google-client-id']; $clientSecret = $settings['google-client-secret']; $redirectUrl = base_url() . 'core/User_Authentication'; // Google Client Configuration $gClient = new Google_Client(); $gClient->setApplicationName('Login to camplus.hk'); $gClient->setClientId($clientId); $gClient->setClientSecret($clientSecret); $gClient->setRedirectUri($redirectUrl); $google_oauthV2 = new Google_Oauth2Service($gClient); $code = $this->input->get(); if (!empty($code)) { $gClient->authenticate(); } $token = $this->session->userdata('token'); if (!empty($token)) { $gClient->setAccessToken($token); } if ($gClient->getAccessToken()) { $userProfile = $google_oauthV2->userinfo->get(); // Preparing data for database insertion $userData['oauth_provider'] = 'google'; $userData['oauth_uid'] = $userProfile['id']; $userData['first_name'] = $userProfile['given_name']; $userData['last_name'] = $userProfile['family_name']; $userData['email'] = $userProfile['email']; $userData['gender'] = $userProfile['gender']; $userData['locale'] = $userProfile['locale']; $userData['profile_url'] = $userProfile['link']; $userData['picture_url'] = $userProfile['picture']; // Insert or update user data $userID = $this->User_model->checkUser($userData); if(!empty($userID)){ $this->db->select('users.*'); $this->db->from('users'); $this->db->where(array('id' => $userID)); $redirectURL = $this->db->get()->row_array(); $this->db->select('value'); $this->db->from('site_settings'); $this->db->where(array('setting' => 'default_front_page')); $defaultRedirectURL = $this->db->get()->row_array(); if(empty($redirectURL['front_page'])) { if (empty($defaultRedirectURL['value'])) { $redirectURL['front_page'] = 'event_booking/events/listing'; } else { $redirectURL['front_page'] = $defaultRedirectURL['value']; } } $userData['id'] = $userID; $userData['name_english'] = $redirectURL['name_english']; $userData['name_chinese'] = $redirectURL['name_chinese']; $data['userData'] = $userData; $this->session->set_userdata($userData); $this->session->set_userdata('user_id', '1'); redirect($redirectURL['front_page']); } else { $data['userData'] = array(); $this->session->set_flashdata('error','User not authorized'); redirect('login'); } } else { $data['authUrl'] = $gClient->createAuthUrl(); redirect('login'); } } public function logout() { include_once APPPATH."libraries/google-api-php-client/Google_Client.php"; include_once APPPATH."libraries/google-api-php-client/contrib/Google_Oauth2Service.php"; $token = $this->session->userdata('token'); // Google Client Configuration $gClient = new Google_Client(); $token = $gClient->getAccessToken(); $gClient->revokeToken($token); $this->session->unset_userdata('token'); $this->session->unset_userdata('userData'); $this->session->sess_destroy(); echo "Logout"; redirect('/core/User_Authentication'); } }
| ver. 1.4 |
Github
|
.
| PHP 7.2.34 | Generation time: 0.14 |
proxy
|
phpinfo
|
Settings