Created
July 2, 2018 09:36
-
-
Save studio-fars-company/38e4472cd10ca8b94a4e50a7732923c3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Http\Controllers\Auth; | |
use App\Http\Controllers\Controller; | |
use Illuminate\Foundation\Auth\AuthenticatesUsers; | |
use Illuminate\Http\Request; | |
use Cartalyst\Sentinel\Checkpoints\NotActivatedException; | |
use Cartalyst\Sentinel\Checkpoints\ThrottlingException; | |
use Sentinel; | |
class LoginController extends Controller | |
{ | |
/** | |
* Where to redirect users after login. | |
* | |
* @var string | |
*/ | |
protected $redirectTo = '/home'; | |
/** | |
* Create a new controller instance. | |
* | |
* @return void | |
*/ | |
public function __construct() | |
{ | |
$this->middleware('guest', ['except' => 'logout']); | |
} | |
/** | |
* ログイン処理 | |
*/ | |
public function login(Request $request) { | |
// バリデーション | |
$this->validate($request, [ | |
'email' => 'required|email|max:255', | |
'password' => 'required|between:6,255', | |
'remember' => 'boolean', | |
]); | |
// 認証処理 | |
try { | |
$this->userInterface = Sentinel::authenticate([ | |
'email' => $request['email'], | |
'password' => $request['password'] | |
], $request['remember']); | |
} catch (NotActivatedException $notactivated) { | |
return view('auth.login', [ | |
'resend_code' => $request['email'] | |
])->withErrors([trans('sentinel.not_activation')]); | |
} catch (ThrottlingException $throttling) { | |
return view('auth.login')->withErrors([trans('sentinel.login_throttling')."[あと".$throttling->getDelay()."秒]"]); | |
} | |
if (!$this->userInterface) { | |
// エラー | |
return view('auth.login')->withErrors([trans('sentinel.login_failed')]); | |
} | |
return redirect($this->redirectTo); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment