繁体   English   中英

Laravel Vue.js - 服务器重启后,帐户不会注销

[英]Laravel Vue.js - after server restart, account does not log out

Laravel + Vue.js SPA(单页应用程序)中,我通过命令提示符php artisan serve启动服务器。 例如,对于页面profile/edit ,我在web.php

     Route::get('/profil/edit','UserController@edit_profile')->name('edit_profile');
     Route::get('/login','UserController@login')->name('login');
     Route::post('/login_now','UserController@login_now')->name('login_now');

我没有使用默认的auth控制器方法进行登录,因为它们似乎不适合使用axios ajax请求。 因此,我使用了自己的控制器方法,并采用了登录和注销功能的内置方法。

router.js ,我有:

    export default new VueRouter({
      mode: 'history',
      routes: [
       ......
       { path: '/profile/edit', component: EditProfile, name: 'edit_profile'
          , meta: {
            auth: true,
            title: 'Nogor Solutions - Edit Profile '
          }}

        .....
    ],
      scrollBehavior (to, from, savedPosition) {
        return { x: 0, y: 0 }
      }
    });

UserController ,我有:

          public function __construct(){

              $this->middleware('auth', ['except' => [
                'index',
                'login',
                'login_now'
                 ]]);
           }

           public function edit_profile(){

               $user=User::find(1,['name','email','address','country_code','national_number',
                   'phone_number','dob','profession','photo']);

               JavaScript::put([
                   'user_profile' => $user
               ]);  //  This makes the variable user_profile available in blade and vue files


                return view('app');

           }//end of function edit_profile

views目录中的app.blade.php ,我在一开始就有:

    <?php echo
    header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
    header("Cache-Control: post-check=0, pre-check=0", false);
    header("Pragma: no-cache");
    header('Content-Type: text/html');?>

现在首先我运行命令npm run dev ,然后npm run dev命令php artisa serve 然后当我点击地址127.0.0.1:8000 ,它会将我带到登录页面。 从那里登录后,我可以转到profile/edit页面。

到现在为止还挺好。 现在从命令提示符,如果我用Ctrl + C取消当前正在执行的命令,那么已经运行的服务器会停止。 让我再次使用php artisan serve启动服务器。 这一次,当我打的网址“/型材/编辑”这仍然是在浏览器已经打开,页面带我到登录页面一次。 它只是显示在那里。

提到的行为是可取的吗? 那里有任何安全问题或架构问题吗? 当我在服务器重启后点击相同的 URl ( profile/edit ) 时,如何使页面重定向到登录?

它可能会使用 cookie(或其他东西)跟踪您的登录状态。 您是否尝试过清除 cookie 和缓存以查看是否会将您带回登录页面?

如果是这样,那么它就是设计的一部分,您无需担心。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM