首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >CodeIgniter注册

CodeIgniter注册
EN

Stack Overflow用户
提问于 2016-04-10 16:41:52
回答 1查看 784关注 0票数 0

我正在尝试在Facebook注册,我正在使用插件。它将我重定向到facebook登录页面,但当我登录到facebook时,它不会将我返回到我的网站。

控制器

代码语言:javascript
复制
class UserController extends CI_Controller { 
    public function fbSignup() {
    $this->load->library('fb');
    if (!$this->fb->is_connected()) {

        redirect($this->fb->login_url(current_url()));
    }

    $fb_user = $this->fb->client->api('/me');
    echo "<pre>";
    print_r($fb_user); exit;
    if (empty($fb_user)) {
        $error = "FACEBOOK LOGIN FAILED - USER US EMPTY. FILE: " . __FILE__ . " LINE: " . __LINE__;
        $this->session->set_flashdata('register_error', $error);
    } else {
        $this->user->set_facebook_id($fb_user['id']);
        $user = $this->user->get_by_facebook();
        if (!empty($user) && !empty($user->id) && is_numeric($user->id)) {
            //TODO: Make things a bit more secure here
            //Login & Redirect home
            $this->_login($user->id, 'facebook');
            $this->load->view('users/redirect_home');
            return;
        }
    }
}

}

所有的应用服务器和API键都设置好了。

EN

回答 1

Stack Overflow用户

发布于 2016-04-10 18:43:51

您不需要使用任何CodeIgniter插件,您可以简单地使用Javascript库,使用JS库有两个优点--

01)您可以使用这个脚本--任何框架,如CodeIgniter、CakePHP、Laravel等等--我的意思是,当您开始开发新框架时,您就不需要浪费时间,只需使用这个脚本即可。

02)使用JS,您可以在弹出窗口打开网站上的facecbook登录表单,它不会重定向到facebook.com页面。

剧本--

代码语言:javascript
复制
<html>
<body>
<div id="fb-root"></div>
<script>
  window.fbAsyncInit = function() {
    FB.init({
      appId      : '717505658366417', // Set YOUR APP ID
      status     : true, // check login status
      cookie     : true, // enable cookies to allow the server to access the session
      xfbml      : true  // parse XFBML
    });

  };

    function Login()
    {

        FB.login(function(response) {
           if (response.authResponse) 
           {
                getUserInfo();
            } else 
            {
             console.log('User cancelled login or did not fully authorize.');
            }
         },{scope: 'email,user_photos,user_videos'});

    }

  function getUserInfo() {
        FB.api('/me', function(response) {
      var str="<b>Name</b> : "+response.name+"<br>";
          str +="<b>Link: </b>"+response.link+"<br>";
          str +="<b>Gender:</b> "+response.gender+"<br>";
          str +="<b>id: </b>"+response.id+"<br>";
          str +="<b>Email:</b> "+response.email+"<br>";
          str +="<input type='button' value='Get Photo' onclick='getPhoto();'/>";
          str +="<input type='button' value='Logout' onclick='Logout();'/>";
          document.getElementById("status").innerHTML=str;

    });
    }
    function getPhoto()
    {
      FB.api('/me/picture?type=normal', function(response) {

          var str="<br/><b>Pic</b> : <img src='"+response.data.url+"'/>";
          document.getElementById("status").innerHTML+=str;

    });

    }
    function Logout()
    {
        FB.logout(function(){document.location.reload();});
    }

  // Load the SDK asynchronously
  (function(d){
     var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
     if (d.getElementById(id)) {return;}
     js = d.createElement('script'); js.id = id; js.async = true;
     js.src = "//connect.facebook.net/en_US/all.js";
     ref.parentNode.insertBefore(js, ref);
   }(document));

</script>
<div align="center">
<h2>Facebook OAuth Javascript Demo</h2>

<div id="message">
Logs:<br/>
</div>
</div>
</body>
</html>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/36532533

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档