Facebook 使用 Sentry 登录,用户 [email] 需要密码,没有给出

2023-10-31php开发问题
2

本文介绍了Facebook 使用 Sentry 登录,用户 [email] 需要密码,没有给出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我正在尝试允许用户使用 facebook 登录,但我的用户管理基于哨兵如您所知,如果您从 facebook 连接,除非您正常创建帐户,否则您不需要密码.有没有办法告诉哨兵(http://docs.cartalyst.com/sentry-2/installation/laravel-4)这是一个 facebook 登录,它不需要密码"

I'm trying to allow users to login using facebook but my user management is based on sentry as you know if you connect from facebook, you wont need a password unless you are creating a account normally. Is there a way to tell sentry(http://docs.cartalyst.com/sentry-2/installation/laravel-4) that this is a facebook login and it doesnt require a "password"

我尝试给帐户一个临时密码,但我收到了没有为用户提供散列器,即使我散列它.

I tried giving the account a temp password but i receive A hasher has not been provided for the user , even when i hash it.

对此有何建议?

我也在使用 http://maxoffsky.com/code-blog/integrating-facebook-login-into-laravel-application/ 作为指南

I'm also using http://maxoffsky.com/code-blog/integrating-facebook-login-into-laravel-application/ as a guide

Route::get('login/fb/callback', function() {
$code = Input::get('code');
if (strlen($code) == 0) return Redirect::to('/')->with('message', 'There was an error communicating with Facebook');

$facebook = new Facebook(Config::get('facebook'));
$uid = $facebook->getUser();

if ($uid == 0) return Redirect::to('/')->with('message', 'There was an error');

$me = $facebook->api('/me');

$profile = Profile::whereUid($uid)->first();
if (empty($profile)) {

    $user = new User;
    $user->name = $me['first_name'].' '.$me['last_name'];
    $user->email = $me['email'];
    $user->photo = 'https://graph.facebook.com/'.$me['username'].'/picture?type=large';

    $user->save();

    $profile = new Profile();
    $profile->uid = $uid;
    $profile->username = $me['username'];
    $profile = $user->profiles()->save($profile);
}

$profile->access_token = $facebook->getAccessToken();
$profile->save();

$user = $profile->user;

Auth::login($user);

return Redirect::to('/')->with('message', 'Logged in with Facebook');

});

推荐答案

我正在考虑做类似的事情,并且正在考虑使用 facebook uid 作为密码.这不行吗?

I'm looking at doing something similar, and was thinking of using the facebook uid as the password. Would this not work?

我可以为我确认以下工作:

I can confirm the following works for me:

function callback()
{
    $code = Input::get('code');
    if (strlen($code) == 0) return Redirect::to('/')->with('message', 'There was an error communicating with Facebook');

    $facebook = new Facebook(Config::get('facebook'));
    $uid = $facebook->getUser();

    if ($uid == 0) return Redirect::to('/')->with('message', 'There was an error');

    $me = $facebook->api('/me');
    //dd($me);

    //Check if user profile exists
    $profile = Profile::whereUid($uid)->first();
    if (empty($profile)) {

        // Create the user
        $user = Sentry::createUser(array(
            'email'      => $me['email'],
            'password'   => $uid,
            'first_name' => $me['first_name'],
            'last_name'  => $me['last_name'],
            'photo'      =>  'https://graph.facebook.com/'.$me['username'].'/picture?type=large',
            'activated'  => 1
        ));

        // Find the group using the group id
        $registered = Sentry::findGroupById(2);
        // Assign the group to the user
        $user->addGroup($registered);

        $profile = new Profile();
        $profile->uid = $uid;
        $profile->username = $me['username'];
        $profile = $user->profiles()->save($profile);
    }

    $profile->access_token = $facebook->getAccessToken();
    $profile->save();

    $user = $profile->user;
    Sentry::login($user, false);
    $user = Sentry::getUser();

    echo $user->first_name . " logged in.";
    //return Redirect::to('/')->with('message', 'Logged in with Facebook');
}

另请注意,您需要使用此方法自定义哨兵使用的模型 (http://forums.laravel.io/viewtopic.php?pid=48274#p48274) 以指定与配置文件的关系

Also note that you'll need customize the model sentry uses using this method (http://forums.laravel.io/viewtopic.php?pid=48274#p48274) in order to specify the relationship with profiles

这篇关于Facebook 使用 Sentry 登录,用户 [email] 需要密码,没有给出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

PHP实现DeepL翻译API调用
DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以...
2025-08-20 php开发问题
168

PHP通过phpspreadsheet导入Excel日期数据处理方法
PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的...
2024-10-23 php开发问题
287

mediatemple - 无法使用 codeigniter 发送电子邮件
mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)...
2024-08-23 php开发问题
11

Laravel Gmail 配置错误
Laravel Gmail Configuration Error(Laravel Gmail 配置错误)...
2024-08-23 php开发问题
16

将 PHPMailer 用于 SMTP 的问题
Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)...
2024-08-23 php开发问题
4

关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题
Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)...
2024-08-23 php开发问题
17