class LoginController extends BaseController {
public function __construct()
{
$this->beforeFilter('csrf', array('on' => 'post'));
}
public function getIndex()
{
if (Auth::check()) {
return Redirect::action('[email protected]')
->with('message', 'You are already logged in.');
}
return View::make('guests.login');
}
public function postIndex()
{
$validation = User::validateForm(Input::all());
if ($validation->passes()) {
$user = array(
'username' => Input::get('username'),
'password' => Input::get('password')
);
// Try to log the user in.
if (Auth::attempt($user, Input::has('remember_me'))) {
return Redirect::to('/');
}
return Redirect::to('login')
->withErrors(array('password' => 'The username or password you entered is incorrect.'))
->withInput(Input::except('password'));
}
return Redirect::to('login')
->withErrors($validation)
->withInput(Input::except('password'));
}
}
filters.php
App::after(function($request, $response) {
if (Auth::check()){
$ckname=Auth::getRecallerName(); //Get the name of the cookie, where remember me expiration time is stored
$ckval=Cookie::get($ckname); //Get the value of the cookie
return $response->withCookie(Cookie::make($ckname,$ckval,720)); //change the expiration time
}
});
routes.php. 이므로 filters.php
파일 find App::after()
방법으로 쿠키 만료 시간을 변경하십시오. 예 - 토론에서
App::after(function($request, $response)
{
if (Auth::check()){
$ckname=Auth::getRecallerName(); //Get the name of the cookie, where remember me expiration time is stored
$ckval=Cookie::get($ckname); //Get the value of the cookie
return $response->withCookie(Cookie::make($ckname,$ckval,360)); //change the expiration time
}
});
경우 :
당신 : 나는 12 시간 만료 시간을 설정하고 싶은 무엇 @Trying. App:after
메서드를 시도했지만 코드가 실행될 때마다 원래 12 시간을 덮어 쓰거나 새로 고칩니다. 어떻게 해결할 수 있을까요?
나 : 그것은 업데이 트 쿠키를 존재하고 세션 값을 삭제하면 u는 이렇게하면 당신은 UR 로그인 방법에 세션 값을 설정하려고 할 수 THN이 App::after
방법, 세션 값에 그것을 확인 , 이 만 업데이트됩니다 일단 쿠키, 나는 로그인 할 때 전자.
예 : -
Login code
if (Auth::attempt($user, Input::has('remember_me'))) {
Session::put('key',value);
return Redirect::to('/');
}
App after method
App::after(function($request, $response) {
if(Session::has('key')){
if (Auth::check()){
$ckname=Auth::getRecallerName(); //Get the name of the cookie, where remember me expiration time is stored
$ckval=Cookie::get($ckname); //Get the value of the cookie
Session::forget('key');
return $response->withCookie(Cookie::make($ckname,$ckval,720)); //change the expiration time
}
}
});
당신이 컨트롤러에서 변경할 수 없습니다, 당신은 만료 시간을 설정 할 원하는 after' 방법 –
@Trying Tobemyself :: 앱'에서 변경해야 ~ 12 시간. 나는 App : after 메서드를 사용했지만 코드가 실행될 때마다 기존의 쿠키에 12 시간을 추가/추가합니다. 나는 그것을 어떻게하지 않아서 그렇게하지 않을 것인가? – user1307016
그게 나를 위해 일하고, 당신은 코드를 게시 할 수 –