<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                # 訪客模式 在前面幾節的中間件策略中,我們始終沒有放開 `Auth/@index` 的訪客訪問,在未登錄的情況下,直接訪問將會跳轉到登錄頁面,并且已登錄用戶無法瀏覽其他用戶的頁面,接下來的步驟將會解決這個問題。 ## 放開權限 由于在控制器中多個方法都被中間件攔截,現在重新編輯 `application\user\controller\Auth.php` ~~~php ... protected $middleware = [ 'UserAuthorize' => [ 'except' => [ 'create', 'save', 'index', 'read' ] ], ... ~~~ 退出登錄后再次訪問 http://thinkphp.test/user/auth/index ,即可看到所有用戶的列表,然后我們隨意點擊一個用戶的名字,發現頁面中出現 `歡迎您` 的字樣和 `編輯資料` 按鈕,這是訪客模式不可見的,現在我們需要一一解決。 ## 判斷訪客 訪客分為兩種: 1. 未登錄用戶 2. 已登錄用戶訪問其他用戶頁面 非常簡單的,雖然擁有兩種狀態,但是我們只需要在控制器中傳入 `Session` 即可判斷。 `application\user\controller\Auth.php` ~~~php public function read($id) { $user = User::find($id); $this->assign([ 'user' => $user, 'session' => Session::get('user') ]); return $this->fetch(); } ~~~ 再編輯前端頁面 `resources\views\user\auth\read.blade.php` ~~~html @extends('_layout.default') @section('title', $user->name) @section('content') <div class="col-md-offset-2 col-md-8"> <div class="panel panel-default mt-5"> <div class="panel-heading mb-3"> <h4> @if(!is_null($session) && $session->id === $user->id) <a class="btn btn-primary" href="{{ url('user/auth/edit', ['id' => session('user.id')]) }}"> 編輯資料 </a> 歡迎您 @else 您正在查看 @endif {{ $user->name }} </h4> </div> </div> </div> @stop ~~~ 現在用不登錄和登錄狀態隨意訪問其他用戶的頁面,可以看到以上問題均解決了。 在上一節添加刪除按鈕的時候,我們刪除邏輯中排除了管理員自己刪除自己,現在需要在前端頁面中移除這個按鈕。 `resources\views\user\auth\index.blade.php` ~~~html @if ($god && !$user->god) <form action="{{ url('user/auth/delete', ['id' => $user->id]) }}" method="post" class="float-right"> @php echo token() @endphp <input type="hidden" name="_method" value="DELETE"> <button type="submit" class="btn btn-sm btn-danger delete-btn">刪除</button> </form> @endif ~~~ 非常簡單的,只需要判斷循環列表的用戶 `god` 屬性就行。 使用管理員登錄并訪問所有用戶頁面,可以看到所有是管理員的刪除按鈕全部消失了。
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看