Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- defined('BASEPATH') OR exit('No direct script access allowed');
- class Register extends CI_Controller
- {
- public function index()
- {
- $data['login_url'] = $this->facebook->getLoginUrl(array(
- 'redirect_uri' => site_url('welcome'), //here is already defaine where url after success login in facebook
- 'scope' => array(
- "email, user_birthday, user_location, user_work_history, user_hometown, user_photos"
- )
- ));
- $this->admin->load('template1', 'index', $data);
- }
- /* action login facebook*/
- public function loginfacebook()
- {
- $user = $this->facebook->getUser();
- if ($user) {
- try {
- $userinformation = $this->facebook->api('/me?fields=id,name,link,email,gender');
- }
- catch (FacebookApiException $e) {
- $user = null;
- }
- } else {
- $this->facebook->destroySession();
- }
- if ($userinformation != '') {
- $email = $userinformation['email'];
- $q = $this->db->select('email')->from('li_user')->where(array(
- 'email' => $email
- ))->get();
- if ($q->num_rows() > 0) {
- $user_details = array(
- 'nama' => $userinformation['name'],
- 'email' => $userinformation['email'],
- 'user_status' => '1'
- );
- $condition['email'] = $userinformation['email'];
- $this->session->set_userdata('user', $userinformation);
- $this->model_register->updateuserbyfacebook($user_details,$condition);
- // echo "hello user you just update caus eyour email already here";
- } else {
- $user_details = array(
- 'nama' => $userinformation['name'],
- 'email' => $userinformation['email'],
- 'user_status' => '1'
- );
- $this->session->set_userdata('user', $userinformation);
- $this->model_register->adduserbyfacebook($user_details);
- // echo "hello user you just insert";
- }
- redirect(site_url('welcome')); //ini sudah kusaih redirect kok gak ke redirect ya mas
- } else {
- $this->facebook->destroySession();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement