简体   繁体   English

Laravel Auth外部数据用于登录和注册

[英]Laravel Auth external data for login and register

I am using the Laravel 5.2 Auth system coming up with this command : 我正在使用带有以下命令的Laravel 5.2 Auth系统:

php artisan make:auth

Although this works totally fine as is, my goal is to use an external API to perform login, registering and changing password while still being able to use the core function of the Auth class. 尽管这完全可以正常工作,但是我的目标是使用外部API执行登录,注册和更改密码,同时仍然能够使用Auth类的核心功能。

So taking the login for example, I want to use something like 以登录为例,我想使用类似

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
}

By the way, I want to pass fields coming up from $login to the Auth class, like we can actually do Auth::user()->email giving us the email, I'd want to set value like "database field" but with my API JSON fields behind 顺便说一句,我想将来自$ login的字段传递给Auth类,就像我们可以实际执行Auth :: user()-> email给我们发送电子邮件一样,我想设置“ database field”之类的值但是后面有我的API JSON字段

I looked on the Internet and found something to do inside AuthController and something related to ServiceProvider, but I don't know how to follow my exact needs 我在互联网上看了看,发现在AuthController内可以做的事情以及与ServiceProvider有关的事情,但是我不知道如何满足我的确切需求

Adding a custom user provider would help in this case. 在这种情况下,添加自定义用户提供程序会有所帮助。 There is no need to play with AuthController here. 此处无需使用AuthController。 Check this Laravel Docs page . 检查此Laravel文档页面

You will need to create a new User Provider which implements Illuminate\\Contracts\\Auth\\UserProvider , specify it in AuthServiceProvider and update your auth config file accordingly. 您将需要创建一个实现Illuminate \\ Contracts \\ Auth \\ UserProvider的新用户提供程序,在AuthServiceProvider中指定它,并相应地更新您的身份验证配置文件。

Here are the links to the framework's default User Providers for reference : 以下是指向框架默认用户提供程序的链接,以供参考:

1) DatabaseUserProvider 1) DatabaseUserProvider

2) EloquentUserProvider 2) EloquentUserProvider

I ended up coding my own Auth system... 我最终编写了自己的Auth系统...

Using session() and Input() 使用session()和Input()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM