我正在尝试创建一个社区网站,用户可以在其中注册自己的子域,以生成游戏论坛(公会/部族/等)。
我让系统根据需要创建和修改所有内容,但我现在正在运行的故障是添加身份验证。
目前,用户可以在主站点登录,但是当他们访问任何子域时,他们都不会被识别为已登录/验证。但是,如果我转到我的config / session.php并设置
'session' => '.localhost'
我最终在第67行遇到了TokenMismatch错误。我已经在GitHub here上启动了项目
这只是我的路线配置错误,还是我错过了更大的东西?
这是我的routes.php
<?php
/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| Here is where you can register all of the routes for an application.
| It's a breeze. Simply tell Laravel the URIs it should respond to
| and give it the controller to call when that URI is requested.
|
*/
Route::auth();
Route::group(['domain' => '{alias}.localhost'], function() {
Route::get('/', 'CommunitiesController@show');
Route::get('/categories/create', 'CategoriesController@create');
Route::get('/forums/create', 'ForumsController@create');
Route::get('/{forum_id}', 'ForumsController@show');
Route::get('/{forum_id}/post', 'PostsController@create');
Route::get('/{forum_id}/{post_id}', 'PostsController@show');
Route::group(['middleware' => 'auth'], function() {
Route::post('/categories/create', 'CategoriesController@store');
Route::post('/forums/create', 'ForumsController@store');
Route::post('/{forum_id}/post', 'PostsController@store');
Route::post('/{forum_id}/{post_id}', 'RepliesController@store');
});
});
Route::get('/', 'CommunitiesController@index');
Route::group(['middleware' => 'auth'], function() {
Route::get('/create', 'CommunitiesController@create');
Route::post('/create', 'CommunitiesController@store');
});
以下是登录视图:
@extends('layouts.app')
@section('content')
<div class="container">
<div class="row">
<div class="col-md-8 col-md-offset-2">
<div class="panel panel-default">
<div class="panel-heading">Login</div>
<div class="panel-body">
<form class="form-horizontal" role="form" method="POST" action="{{ url('/login') }}">
{{ csrf_field() }}
<div class="form-group{{ $errors->has('email') ? ' has-error' : '' }}">
<label for="email" class="col-md-4 control-label">E-Mail Address</label>
<div class="col-md-6">
<input id="email" type="email" class="form-control" name="email" value="{{ old('email') }}">
@if ($errors->has('email'))
<span class="help-block">
<strong>{{ $errors->first('email') }}</strong>
</span>
@endif
</div>
</div>
<div class="form-group{{ $errors->has('password') ? ' has-error' : '' }}">
<label for="password" class="col-md-4 control-label">Password</label>
<div class="col-md-6">
<input id="password" type="password" class="form-control" name="password">
@if ($errors->has('password'))
<span class="help-block">
<strong>{{ $errors->first('password') }}</strong>
</span>
@endif
</div>
</div>
<div class="form-group">
<div class="col-md-6 col-md-offset-4">
<div class="checkbox">
<label>
<input type="checkbox" name="remember"> Remember Me
</label>
</div>
</div>
</div>
<div class="form-group">
<div class="col-md-6 col-md-offset-4">
<button type="submit" class="btn btn-primary">
<i class="fa fa-btn fa-sign-in"></i> Login
</button>
<a class="btn btn-link" href="{{ url('/password/reset') }}">Forgot Your Password?</a>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
@endsection
验证控制器:
<?php
namespace App\Http\Controllers\Auth;
use App\User;
use Validator;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\ThrottlesLogins;
use Illuminate\Foundation\Auth\AuthenticatesAndRegistersUsers;
class AuthController extends Controller
{
/*
|--------------------------------------------------------------------------
| Registration & Login Controller
|--------------------------------------------------------------------------
|
| This controller handles the registration of new users, as well as the
| authentication of existing users. By default, this controller uses
| a simple trait to add these behaviors. Why don't you explore it?
|
*/
use AuthenticatesAndRegistersUsers, ThrottlesLogins;
/**
* Where to redirect users after login / registration.
*
* @var string
*/
protected $redirectTo = '/';
/**
* Create a new authentication controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware($this->guestMiddleware(), ['except' => 'logout']);
}
/**
* Get a validator for an incoming registration request.
*
* @param array $data
* @return \Illuminate\Contracts\Validation\Validator
*/
protected function validator(array $data)
{
return Validator::make($data, [
'name' => 'required|max:255',
'email' => 'required|email|max:255|unique:users',
'password' => 'required|min:6|confirmed',
]);
}
/**
* Create a new user instance after a valid registration.
*
* @param array $data
* @return User
*/
protected function create(array $data)
{
return User::create([
'name' => $data['name'],
'email' => $data['email'],
'password' => bcrypt($data['password']),
]);
}
}
两者均来自新的Laravel 5.2装置。