我正在使用Laravel 5.2 Auth系统提供此命令:
php artisan make:auth
虽然这样可以完全正常,但我的目标是使用外部API来执行登录,注册和更改密码,同时仍然可以使用Auth类的核心功能。
所以以登录为例,我想使用像
这样的东西function login(ApiController $api) {
// This function return data or error code and message in JSON
$login = $api->login([ $credentials['email'], $credentials['password']]);
if($login->success)
// login successfully like normal Auth would do
else
// redirect to main page with $login->message
}
顺便说一句,我想将$ login中的字段传递给Auth类,就像我们实际上可以做Auth :: user() - >电子邮件给我们发电子邮件一样,我想设置像“数据库字段”,但我的API JSON字段在后面
我在互联网上查看了AuthController内部的一些事情以及与ServiceProvider相关的内容,但我不知道如何遵循我的确切需求
答案 0 :(得分:2)
在这种情况下,添加自定义用户提供程序会有所帮助。这里不需要使用AuthController。检查this Laravel Docs page。
您需要创建一个实现Illuminate\Contracts\Auth\UserProvider的新用户提供程序,在 AuthServiceProvider 中指定它并相应地更新 auth config 文件。
以下是框架默认用户提供商的链接供参考:
答案 1 :(得分:0)
我最终编写了自己的Auth系统...
使用session()和Input()