Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Laravel-如何防止登录和中间件后重定向?_Laravel - Fatal编程技术网

Laravel-如何防止登录和中间件后重定向?

Laravel-如何防止登录和中间件后重定向?,laravel,Laravel,我想阻止laravel在登录失败后重定向。我没办法。它总是重定向到/myspace,即使它失败了 我尝试在登录页面中添加这个,但它重定向到与“302找到”相同的页面。 问题是我正在使用VueJS以模式登录。所以我希望它不要重定向到任何地方,这样我就可以通知用户他的凭据是错误的 [编辑]它起作用了 vuelogin(){ 这是LoginController: use AuthenticatesUsers; protected $redirectTo = '/myspace'; public fun

我想阻止laravel在登录失败后重定向。我没办法。它总是重定向到/myspace,即使它失败了

我尝试在登录页面中添加这个,但它重定向到与“302找到”相同的页面。 问题是我正在使用VueJS以模式登录。所以我希望它不要重定向到任何地方,这样我就可以通知用户他的凭据是错误的

[编辑]它起作用了

vuelogin(){

这是LoginController:

use AuthenticatesUsers;
protected $redirectTo = '/myspace';
public function __construct()
{
   $this->middleware('guest')->except('logout');
}

public function username()
{
    return 'email';
}

public function password()
{
    return 'password';
}
我有一个与此登录关联的中间件:

class LoginNewPassword
{
    function newPwdExists($login){
        //bla bla bla
    }

    public function remembermembretoken(){
        //blablabla
        return true;
    }


    public function handle($request, Closure $next)
    {
        if($this->newPwdExists($request->email)==0)
        {
            return redirect('/password/reset')->with('email',$request->email);
        }
        $response = $next($request);
        $loggedin = $this->remembermembretoken();
        if($loggedin) return redirect('/myspace');
        return $response; **//if I remove this, I get the error "Trying to get property 'headers' of non-object"**
    }
}
这里是Login.vue

<template>
    <form method="POST" id="formlogin" action="/vuelogin" style="margin: 1em;">
        <input type="hidden" name="_token" :value="csrf">
        <div class=" login-card itra-green-bgr text-center" v-if="isloggedin==false" style="padding-top:1em;">
            <!-- <label style="color: white; font-family:Montserrat-ExtraBold;" for="rememberme">{{ $t('login.login') }}</label> -->
            <hr/>
            <input id="email" type="email" v-model="email" placeholder="Email" class="form-control" name="email" style="margin-bottom: 1em;" required autofocus>

            <input id="password" type="password" v-model="password" :placeholder="$t('login.password')" class="form-control" name="password">
            <div class="error" v-if="error!=''">{{$t('login.badcredentials')}}</div>
            <div class="">
                <div class="form-check">
                    <input class="form-check-input" type="checkbox" name="remember" id="remember">

                    <label class="form-check-label" for="remember">
                        {{ $t('login.rememberme') }}
                    </label>
                </div>
            </div>

            <div class="text-center">
                <div class="">
                    <button style="margin: 1em;" type="submit" class="btn-itra-black">
                        {{ $t('login.login') }}
                    </button>


                    <div style="margin: 1em;">
                        <a style="color:black" href="/password/reset">
                            {{ $t('login.forgotpwd') }}
                        </a>
                    </div>
                    <div><a class="btn-itra-white" href="/register">{{ $t('login.noAccount') }}</a></div>
                </div>
            </div>
        </div>
    </form>
</template>


<script>
    export default {
        nom: "login",
        data () {
            return {
                APP_URL: process.env.MIX_APP_URL,
                isloggedin: false,
                loggedin: '',
                email: '',
                password:'',
                rememberme:false,
                currentUser: null,
                csrf: "",
                error:''
            }
        },
        mounted()
        {
          this.csrf = $('meta[name="csrf-token"]').attr('content');
        },
        methods:{
            register(){
                window.location.href = this.APP_URL +'/register/';
            },
            logout(){
              axios.post("/logout");
            },

        }
    }
</script>


{{$t('login.badcredentials')} {{$t('login.rememberme')} {{$t('login.login')} 导出默认值{ 名字:“登录”, 数据(){ 返回{ 应用程序URL:process.env.MIX\u应用程序URL, 伊斯洛格丁:错, loggedin:“, 电子邮件:“”, 密码:“”, 记住:错, 当前用户:null, csrf:“, 错误:“” } }, 安装的() { this.csrf=$('meta[name=“csrf token”]').attr('content'); }, 方法:{ 寄存器(){ window.location.href=this.APP_URL+'/register/'; }, 注销(){ axios.post(“/注销”); }, } }
您应该从javascript登录请求发送一个标题
内容类型:application/json
,Laravel将确保它立即以json数组的形式返回验证错误,而不是使用错误包重定向。

您应该从javascript登录请求发送一个标题
内容类型:application/json
quest和Laravel将确保它立即以JSON数组的形式返回验证错误,而不是使用errorbag重定向。

谢谢,所以我需要通过axios发送它,我想?我用vuelogin更新了我的答案,在那里我直接发送表单。否则我无法正确发送csrf令牌…非常感谢!我更新了我的问题和工作解决方案谢谢,所以我想我需要通过axios发送它?我用vuelogin更新了我的答案,我直接在那里发送表单。否则我无法正确发送csrf令牌…非常感谢!我用工作解决方案更新了我的问题
<template>
    <form method="POST" id="formlogin" action="/vuelogin" style="margin: 1em;">
        <input type="hidden" name="_token" :value="csrf">
        <div class=" login-card itra-green-bgr text-center" v-if="isloggedin==false" style="padding-top:1em;">
            <!-- <label style="color: white; font-family:Montserrat-ExtraBold;" for="rememberme">{{ $t('login.login') }}</label> -->
            <hr/>
            <input id="email" type="email" v-model="email" placeholder="Email" class="form-control" name="email" style="margin-bottom: 1em;" required autofocus>

            <input id="password" type="password" v-model="password" :placeholder="$t('login.password')" class="form-control" name="password">
            <div class="error" v-if="error!=''">{{$t('login.badcredentials')}}</div>
            <div class="">
                <div class="form-check">
                    <input class="form-check-input" type="checkbox" name="remember" id="remember">

                    <label class="form-check-label" for="remember">
                        {{ $t('login.rememberme') }}
                    </label>
                </div>
            </div>

            <div class="text-center">
                <div class="">
                    <button style="margin: 1em;" type="submit" class="btn-itra-black">
                        {{ $t('login.login') }}
                    </button>


                    <div style="margin: 1em;">
                        <a style="color:black" href="/password/reset">
                            {{ $t('login.forgotpwd') }}
                        </a>
                    </div>
                    <div><a class="btn-itra-white" href="/register">{{ $t('login.noAccount') }}</a></div>
                </div>
            </div>
        </div>
    </form>
</template>


<script>
    export default {
        nom: "login",
        data () {
            return {
                APP_URL: process.env.MIX_APP_URL,
                isloggedin: false,
                loggedin: '',
                email: '',
                password:'',
                rememberme:false,
                currentUser: null,
                csrf: "",
                error:''
            }
        },
        mounted()
        {
          this.csrf = $('meta[name="csrf-token"]').attr('content');
        },
        methods:{
            register(){
                window.location.href = this.APP_URL +'/register/';
            },
            logout(){
              axios.post("/logout");
            },

        }
    }
</script>