dpqy77560 2016-01-28 10:11
浏览 23

如何在laravel 5.1中验证失败后停止引导模式关闭?

I have a bootstrap modal for login but when ever it fails it redirects to auth/login and the modal closes. So how would I stop the modal from closing when the authentication fails and how will I stop it from redirecting back to auth/login?

My login form:

<form action="{{ URL::to('auth/login')}}" method="POST">

{!! csrf_field() !!}

<div class="left-form__form">
    <div class="mdl-textfield mdl-js-textfield mdl-textfield--floating-label">
        <input class="mdl-textfield__input" type="text" id="mdl_email" name="email">
        <label class="mdl-textfield__label" for="mdl_email">Email ID</label>
    </div>
    <div class="mdl-textfield mdl-js-textfield mdl-textfield--floating-label">
        <input class="mdl-textfield__input" type="password" id="mdl_password" name="password">
        <label class="mdl-textfield__label" for="mdl_password">Password</label>
    </div>
    <div class="left-form__form--bottom">
        <button type="submit" class="btn-style1 mdl-button mdl-js-button mdl-js-ripple-effect mdl-button--accent">
            login
        </button>
        <a href="javascript:void(0);" class="fgt-pwd">forgot password?</a>
    </div>
    <a href="#" class="register-link">New to srsgrocery? <span>SIGNUP</span></a>
</div>
</form>

The modal :

@if(Auth::guest())
    <div class="col-lg-4 col-md-4 col-sm-4 col-xs-4 top-right">
        <span class="call-icon"></span>
        <span class="call-text">Call to Order: 1800-419-2777</span>
        <a href="" title="" class="login" data-toggle="modal" data-target="#loginRegisterModal">Login |</a>
        <a href="" title="" class="register" data-toggle="modal" data-target="#loginRegisterModal">Register</a>
    </div>
    @else
    <div class="col-lg-4 col-md-4 col-sm-4 col-xs-4 top-right">
        <span class="call-icon"></span>
        <span class="call-text">Call to Order: 1800-419-2777</span>
        <a href="{{URL::to('myaccount')}}">My Account </a>                        
        <a href="{{URL::to('auth/logout')}}">Logout</a>
    </div>
@endif
  • 写回答

1条回答 默认 最新

  • dongqin1819 2016-01-28 10:47
    关注

    Try This : The Login Modal :

    <div id="loginRegisterModal" class="modal fade" tabindex="-1" role="dialog">
      <div class="modal-dialog" role="document">
        <div class="modal-content">
          <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
            <h4 class="modal-title">Login : </h4>
          </div>
                        <div class="modal-body">
                        <!-- Login Form inside modal -->
                        ...               
    
                        <div class="modal-footer">
                             <button type="cancel" class="btn btn-danger" data-dismiss="modal">Close</button>                                                                           
                        </div>
    
                    </div>                                                                                                             
    
                </div>            
            </div>
        </div>
    

    In your AuthController :

      ...
      public function postLogin(Request $request)
      {
        $data = $request->all();
    
        $v = Validator::make($data, $this->rules);           
    
        if ($v->fails())
        {                        
            return Response::json(array(
              'success' => false,
              'errors' => $v->errors(),
              'status' => 422              
            ));
    
        }
        if (Auth::attempt($credentials, $request->has('remember')))
            {
                return redirect()->intended($this->redirectPath())
                ->with('success', 'You are successfully logged in');
            }
        return Response::json(array(
              'password' => 'password invalid',
              'email' => 'email invalid'                          
            ));             
      }
    
    protected $rules = array(
        'email' => 'required',
        'password' => 'required|min:6',      
    );
    

    Hope it helps you :)

    评论

报告相同问题?

悬赏问题

  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行