我有一个自定义需求,我正在尝试将Laravel与Django应用程序连接起来。目前,我没有使用laravel的默认登录-发布方法来建立用户会话,而是尝试访问Auth::try($credentials);。通过这种方式,我可以在我的自定义登录控制器中建立用户会话,而在其他控制器中则不会建立会话。
登录控制器:
$credentials = array('email' => $userjson["email"],'password' => $password);
Auth::attempt($credentials);
if(Auth::guest())
echo "guest";
else
return redirect()->intended('/dashboard');
结果:重定向到仪表板页面(意味着会话已建立)
仪表板控制器
if(Auth::check())
echo "true";
else
echo "false";
结果:false(表示会话未建立)
有人能帮我解决这个问题吗?
使用此代码。我们需要确保在类的顶部导入Auth facade。有关更多帮助,请访问https://laravel.com/docs/5.2/authentication以及准备好的主题手动验证用户。感谢
namespace App'Http'Controllers;
use Auth;
class OtherController extends Controller
{
/**
* Handle an authentication attempt.
*
* @return Response
*/
public function authenticate()
{
if (Auth::attempt(['email' => $email, 'password' => $password])) {
// Authentication passed...
return redirect()->intended('dashboard');
}
}
}