所以我对laravel身份验证有问题。所以让我们解释一下
我的站点具有动态子域。主站点www.mydomain.com
进行了一次身份验证,其中包含用户名,电子邮件和密码。
子域{shop_slug}.mydomain.com
仅使用用户名进行身份验证,没有密码,电子邮件等。
所以我尝试使用Auth::login();
使用laravel的默认方式,但是不起作用。这是我的web.php路由
<?php
$mainRouter = function () {
Route::get('/', 'HomeController@index')->name('home');
Route::post('/gdpr', 'HomeController@gdpr');
Auth::routes();
// Main site cart
Route::group(['prefix' => 'cart'], function () {
Route::post('/checkout', 'CartController@page')->name('checkout');
Route::get('/success', 'CartController@success')- >name('purchaseSuccess');
Route::get('/failed', 'CartController@failed')->name('purchaseFailed');
Route::put('/proccess', 'CartController@proccess')->name('purchase');
Route::get('/check', 'CartController@check')->name('check');
});
};
Route::group(['domain' => env('PLAIN_URL')], $mainRouter);
Route::group(['domain' => 'www.'.env('PLAIN_URL')], $mainRouter);
// Shop things content
Route::group(['domain' => '{slug}.' . env('PLAIN_URL'), 'middleware' =>
'ShopExist'], function () {
Route::get('/', 'Shop\HomeController@page');
Route::get('/language/{lang}', 'Shop\LanguageController@changeLang');
Route::get('/currency/{currency}', 'Shop\CurrencyController@change');
Route::get('/category/{category}', 'Shop\CategoryController@page');
Route::group(['prefix' => 'auth'], function () {
Route::get('/login','Shop\AuthController@page')->middleware('guest');
Route::get('/logout','Shop\AuthController@logout')->middleware('auth');
Route::post('/login','Shop\AuthController@create')->middleware('guest');
});
});
我的Shop\AuthController.php
namespace App\Http\Controllers\Shop;
use App\Http\Controllers\Controller;
use App\Http\Requests\UserCreate;
use App\MCUser;
use App\Setting;
use App\Site;
use Auth;
use Illuminate\Http\Request;
class AuthController extends Controller
{
public $theme;
public $site_id;
/**
* CategoryController constructor.
*/
public function __construct(Request $request)
{
$site_id = Site::where('slug', $request->route()->parameter('slug'))->first()->id;
$theme = Setting::where('key', 'theme')->where('site_id', $site_id)->first()->value;
$this->theme = $theme;
$this->site_id = $site_id;
}
/**
* @param $user
*/
private function login($user)
{
Auth::login($user);
}
/**
* @param $slug
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
*/
public function page($slug = null)
{
return view('shop.themes.' . $this->theme . '.pages.login');
}
/**
* @param UserCreate $request
* @return \Illuminate\Http\RedirectResponse
*/
public function create($slug = null, UserCreate $request)
{
$createUser = MCUser::firstOrCreate(
['username' => $request->input('username'), 'site_id' => $this->site_id]
);
$this->login($createUser);
return redirect()->to('/');
}
/**
* @return \Illuminate\Http\RedirectResponse
*/
public function logout()
{
Auth::logout();
return redirect('/');
}
}
如果您再次不知道自己会做什么,我会尝试这样的尝试:
https://ultranetwork.buycraft.net Shop Site
https://buycraft.net Main Site
项目信息:
Laravel 5.6
PHP 7.2