2015-10-03 47 views
0

我有一個奇怪的問題,我無法解決。Laravel 5用戶激活

當用戶註冊後,我將它們重定向到一個供稿網址,打開一個模式,並通過點擊我發送給他們的電子郵件鏈接來通知我的用戶激活他的帳戶。但是當我點擊鏈接後,我仍然被重定向到完全相同的頁面(feed),並且我的賬戶沒有被激活。這裏可能是什麼問題?

routes.php文件

Route::group(['namespace' => 'Auth'], function() 
{ 
    Route::group(['middleware' => 'auth'], function() 
    { 
     Route::get('activate/{token}', '[email protected]'); 
    }); 
}); 

PasswordController

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(); 
} 

RedirectIfAuthenticated.php如果我刪除提要URL,它的工作原理。但我不想這樣做。

public function handle($request, Closure $next) 
{ 
    if ($this->auth->check()) { 

     return redirect('/feed'); 
    } 

    return $next($request); 
} 
+0

你能發佈所有的路由嗎?例如,我現在甚至都沒有看到路徑文件中的'/ feed'。 – djt

回答

1

假設您使用laravel默認身份驗證系統。請執行下列操作。

在您的AuthController中添加該方法。這將創建用戶,但不會將其登錄,因爲他們尚未激活其帳戶。請注意,laravel將自動登錄用戶,因此下面的函數將覆蓋默認行爲。

public function postRegister(Request $request) 
{ 
    $validator = $this->validator($request->all()); 

    if ($validator->fails()) { 
     $this->throwValidationException(
      $request, $validator 
     ); 
    } 
    $this->create($request->all()); 
    return redirect('/feed'); 
} 

在RedirectIfAuthenticated.php刪除'/feed',而是有一個URL哪些用戶如果登錄重定向。由於具有進料會有用戶重定向到網頁,要求他們激活帳號有每次登錄的時間。

在您的密碼控制器的激活功能中,沒有關於一旦激活用戶應該做什麼的邏輯。在$ activation-> save()之後添加以下行:

Auth::login($activation); 
return redirect('/');