首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >具有Laravel 5认证的Pusher

具有Laravel 5认证的Pusher
EN

Stack Overflow用户
提问于 2015-05-22 11:11:35
回答 1查看 5.4K关注 0票数 4

我正在用Laravel 5制作一个Live应用程序,我正在学习本教程,https://github.com/dazzz1er/confer/tree/master我已经跟踪了所有这些内容,但是我的网络控制台出现了一个错误:

它似乎是在我的url /public/index.php/auth上进行ajax调用,而且由于我没有处理该请求的路径,它说404。我不知道是否应该为它制定一条路线,但我应该在那里编码什么呢?我没有头绪。本教程甚至没有提到它。

谢谢

EN

回答 1

Stack Overflow用户

发布于 2015-05-22 12:36:06

每当您调用Auth::check()时,Laravel将通过检查其会话信息来验证用户是否经过身份验证。

Pusher呢?他们如何知道,哪些用户目前登录到您的laravel应用程序?

答案在于ajax调用http://localhost/joene_/public/index.php/auth

通过调用上面的URL,您的laravel安装将允许您的Pusher应用程序链接到您的用户的laravel会话。

让我们深入研究一些代码:

1)推土机Auth控制器

代码语言:javascript
复制
class PusherController extends Controller {

    //accessed through '/pusher/'
    //setup your routes.php accordingly

    public function __construct() {
        parent::__construct();
        //Let's register our pusher application with the server.
        //I have used my own config files. The config keys are self-explanatory.
        //You have received these config values from pusher itself, when you signed up for their service.
        $this->pusher = new Pusher(\Config::get('pusher.app_key'), \Config::get('pusher.app_secret'), \Config::get('pusher.app_id'));
    }

    /**
     * Authenticates logged-in user in the Pusher JS app
     * For presence channels
     */
    public function postAuth()
    {
        //We see if the user is logged in our laravel application.
        if(\Auth::check())
        {
            //Fetch User Object
            $user =  \Auth::user();
            //Presence Channel information. Usually contains personal user information.
            //See: https://pusher.com/docs/client_api_guide/client_presence_channels
            $presence_data = array('name' => $user->first_name." ".$user->last_name);
            //Registers users' presence channel.
            echo $this->pusher->presence_auth(Input::get('channel_name'), Input::get('socket_id'), $user->id, $presence_data);       
        }
        else
        {
            return Response::make('Forbidden',403);
        }
    }
}

2)与推土机配套使用的JS

代码语言:javascript
复制
//replace 'xxx' below with your app key
var pusher = new Pusher('xxx',{authEndpoint : '/pusher/auth'});
var presenceChannelCurrent = pusher.subscribe('presence-myapp');
presenceChannelCurrent.bind('pusher:subscription_succeeded', function() {
    alert(presenceChannelCurrent.members.me.info.name+' has successfully subscribed to the Pusher Presence Channel - My App');
});

希望它能帮到你。

票数 8
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/30395219

复制
相关文章

相似问题

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