2015-10-02 30 views
1

我實現了一個電子郵件激活功能,並且我遇到了一些問題。如果我在註冊後打開激活鏈接,localhost:8000/activate/tokenvariable,它會將我重定向到/ home url並提供錯誤。但是,如果我刪除了cookies並訪問了它,帳戶正在被激活而沒有問題。Laravel更改/註冊之後的回家路線

我不明白是什麼問題。

NotFoundHttpException在RouteCollection.php線161:

路線

// Authentication routes... 
Route::get('auth/login', 'Auth\[email protected]'); 
Route::post('auth/login', 'Auth\[email protected]'); 
Route::get('auth/logout', 'Auth\[email protected]'); 

// Registration routes... 
Route::get('auth/register', 'Auth\[email protected]'); 
Route::post('auth/register', 'Auth\[email protected]'); 

// Password reset link request routes... 
Route::get('password/email', 'Auth\[email protected]'); 
Route::post('password/email', 'Auth\[email protected]'); 

// Password reset routes... 
Route::get('password/reset/{token}', 'Auth\[email protected]eset'); 
Route::post('password/reset', 'Auth\[email protected]'); 

Route::get('activate/{token}', 'Auth\[email protected]'); 

Route::get('/', function() { 
return view('index'); 
}); 


Route::get('feed', 'Feed\[email protected]'); 

FeedController

namespace App\Http\Controllers\Feed; 

use Illuminate\Http\Request; 
use App\Http\Requests; 
use App\Http\Controllers\Controller; 

class FeedController extends Controller 
{ 
    /** 
    * Display a listing of the resource. 
    * 
    * @return \Illuminate\Http\Response 
    */ 
    public function index() 
    { 
     return view('feed'); 
    } 
} 

PasswordController

namespace App\Http\Controllers\Auth; 

use App\Http\Controllers\Controller; 
use Illuminate\Foundation\Auth\ResetsPasswords; 
use Eloquent; 
use Models; 
use App\Models\User; 
use Auth; 
use Session; 

class PasswordController extends Controller 
{ 
    /* 
    |-------------------------------------------------------------------------- 
    | Password Reset Controller 
    |-------------------------------------------------------------------------- 
    | 
    | This controller is responsible for handling password reset requests 
    | and uses a simple trait to include this behavior. You're free to 
    | explore this trait and override any methods you wish to tweak. 
    | 
    */ 

    use ResetsPasswords; 

    /** 
    * Create a new password controller instance. 
    * 
    * @return void 
    */ 
    public function __construct() 
    { 
     $this->middleware('guest'); 
    } 

    public function activate($token) { 
     //get token value. 
     // find the user that belongs to that token. 
     $activation = User::where("confirmation_code", $token)->get()->first(); 
     $activation->confirmed = 1; 
     $activation->save(); 
     Auth::loginUsingId($activation->id, true); 

    } 
} 

AuthController

namespace App\Http\Controllers\Auth; 

use App\Models\User; 
use Validator; 
use App\Http\Controllers\Controller; 
use Illuminate\Foundation\Auth\ThrottlesLogins; 
use Illuminate\Foundation\Auth\AuthenticatesAndRegistersUsers; 
use Mail; 
use Auth; 

class AuthController extends Controller 
{ 

    protected $redirectTo = '/feed'; 
    protected $loginPath = '/'; 
    /* 
    |-------------------------------------------------------------------------- 
    | 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; 

    /** 
    * Create a new authentication controller instance. 
    * 
    * @return void 
    */ 
    public function __construct() 
    { 
     $this->middleware('guest', ['except' => 'getLogout']); 
    } 

    /** 
    * 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|confirmed|min:6', 
      ] 
     ); 
    } 

    /** 
    * Create a new user instance after a valid registration. 
    * 
    * @param array $data 
    * @return User 
    */ 
    protected function create(array $data) 
    { 
     $confirmation_code = md5(uniqid(mt_rand(), true)); 
     $email = $data['email']; 

     Mail::send('emails.verify', ['confirmation_code' => $confirmation_code], function ($m) use ($email) { 
      $m->to($email)->subject("Here's your email"); 
     }); 

     return User::create(
      [ 
      'name'    => $data['name'], 
      'email'    => $data['email'], 
      'password'   => bcrypt($data['password']), 
      'confirmation_code' => $confirmation_code, 
      ] 
     ); 
    } 
} 

回答

1

我RedirectIfAuthenticated.php文件改變手柄功能的重定向URL,它已經解決了。

下面是一個例子。

public function handle($request, Closure $next) 
    { 
     if ($this->auth->check()) { 
      return redirect('/feed'); 
     } 

     return $next($request); 
    }