一个 Auth 登录的问题
出现的问题:
·填写好账号密码验证码都正确的情况下直接还在原来页面,在次填写账号密码验证码后就正常了。登录成功。
地址:https://www.5xdns.com/login
html登录代码
<form action="" method="POST" role="form" class="mt15" enctype="multipart/form-data">
@csrf
<div class="form-group">
<label for="mail" class="control-label">邮箱</label>
<input type="text" class="form-control" onfocus="document.getElementById('i1').innerHTML=''" id="email" name="email" required="" placeholder="邮箱" value="{{ old('email') }}">
<i class="text-warning" id="i1" style="color: red">{{$errors->first('email')}}</i>
</div>
<div class="form-group">
<label for="password" class="control-label">密码</label>
<input type="password" class="form-control" onfocus="document.getElementById('i2').innerHTML=''" name="password" required="" placeholder="不少于 8 位 不大于 8 位的密码">
<i class="text-warning" id="i2" style="color: red">{{$errors->first('password')}}</i>
</div>
<div class="form-group">
<label for="password" class="control-label">验证码</label>
<div class="captchaInput mb10">
<input type="text" class="form-control" onfocus="document.getElementById('i3').innerHTML=''" name="captcha" placeholder="右侧的验证码" style="width:50%; display: inline; margin-right: 15px;" required="'">
<span class="mt10">
<a id="loginReloadCaptcha" href="javascript:void(0)">
<img src="{{ captcha_src('math') }}" class="cap" width="135" height="34" onclick="this.src='{{ captcha_src('math') }}?tm='+Math.random()""></a>
</span>
</div>
<i class="text-warning" id="i3" style="color: red">{{$errors->first('captcha')}}</i>
</div>
<div class="checkbox">
<label>
<input type="checkbox" name="online"> 记住我
</label>
</div>
<div class="form-group clearfix">
<button type="submit" class="btn-block btn btn-primary pl20 pr20 pull-right" style="background-color: #009a61" onclick="">
登陆
</button>
</div>
<div class="form-group clearfix">
<div class="pull-left">
<a href="{{ route('register') }}">尚未账号?</a>
</div>
<div class="pull-right">
<a href="{{ route('seed') }}">忘记密码?</a>
</div>
</div>
</form>
controller代码
public function login(Request $request){
if ($request->isMethod('post')){
$this->validate($request,[
'email' => 'required|email',
'password' => 'required|between:8,32',
'captcha' => 'required|between:2,4|captcha',
],[
'captcha' => ':attribute 错误',
],[
'captcha' => '验证码'
]);
$date = $request->only('email','password');
$requests = Auth::attempt($date,$request->get('online'));
if($requests){
if (Auth::user()->activation == '1'){
Auth::logoutOtherDevices($request->input('password')); //弹出其他登录用户
return redirect('user')->withErrors(['user'=>'登录成功']);
}else{
Auth::logout();
return redirect('login')->withErrors(['login'=>'尚未激活账户,请在邮箱中查看,并激活。'])->withInput();
}
}else{
return redirect()->back()->withErrors(['login'=>'账号或者密码错误'])->withInput();
}
}else{
return view('home.login');
}
}
推荐文章: