Advertisement
freddy0512

test

Nov 6th, 2015
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.46 KB | None | 0 0
  1. <?php
  2. defined('BASEPATH') OR exit('No direct script access allowed');
  3.  
  4. class Register extends CI_Controller
  5. {
  6.  
  7. public function index()
  8. {
  9.  
  10. $data['login_url'] = $this->facebook->getLoginUrl(array(
  11. 'redirect_uri' => site_url('welcome'), //here is already defaine where url after success login in facebook
  12. 'scope' => array(
  13. "email, user_birthday, user_location, user_work_history, user_hometown, user_photos"
  14. )
  15. ));
  16. $this->admin->load('template1', 'index', $data);
  17. }
  18.  
  19.  
  20.  
  21.  
  22. /* action login facebook*/
  23. public function loginfacebook()
  24. {
  25.  
  26. $user = $this->facebook->getUser();
  27. if ($user) {
  28.  
  29. try {
  30. $userinformation = $this->facebook->api('/me?fields=id,name,link,email,gender');
  31. }
  32. catch (FacebookApiException $e) {
  33. $user = null;
  34. }
  35. } else {
  36. $this->facebook->destroySession();
  37. }
  38.  
  39. if ($userinformation != '') {
  40. $email = $userinformation['email'];
  41. $q = $this->db->select('email')->from('li_user')->where(array(
  42. 'email' => $email
  43. ))->get();
  44.  
  45.  
  46. if ($q->num_rows() > 0) {
  47.  
  48. $user_details = array(
  49. 'nama' => $userinformation['name'],
  50. 'email' => $userinformation['email'],
  51. 'user_status' => '1'
  52. );
  53.  
  54. $condition['email'] = $userinformation['email'];
  55. $this->session->set_userdata('user', $userinformation);
  56. $this->model_register->updateuserbyfacebook($user_details,$condition);
  57.  
  58. // echo "hello user you just update caus eyour email already here";
  59.  
  60. } else {
  61.  
  62. $user_details = array(
  63. 'nama' => $userinformation['name'],
  64. 'email' => $userinformation['email'],
  65. 'user_status' => '1'
  66. );
  67.  
  68. $this->session->set_userdata('user', $userinformation);
  69. $this->model_register->adduserbyfacebook($user_details);
  70. // echo "hello user you just insert";
  71. }
  72. redirect(site_url('welcome')); //ini sudah kusaih redirect kok gak ke redirect ya mas
  73. } else {
  74. $this->facebook->destroySession();
  75. }
  76.  
  77.  
  78.  
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement