<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>

                ??一站式輕松地調用各大LLM模型接口,支持GPT4、智譜、豆包、星火、月之暗面及文生圖、文生視頻 廣告
                [TOC] # 登錄 ~~~ // 登錄驗證 $result = \DB::table('user_login')->where(['username' => $input['username'], 'password' => $input['pass']])->find() if ($result) { # 登錄成功 // 制作 token $time = time(); // md5 加密 $singleToken = md5($request->getClientIp() . $result->guid . $time); // 當前 time 存入 Redis \Redis::set(STRING_SINGLETOKEN_ . $result->guid, $time); // 用戶信息存入 Session \Session::put('user_login', $result); // 跳轉到首頁, 并附帶 Cookie return response()->view('index')->withCookie('SINGLETOKEN', $singletoken); } else { # 登錄失敗邏輯處理 } ~~~ 我來解釋一下: 首先登錄成功之后, 得到目前時間戳, 通過 IP, time, 和 查詢得出用戶的 Guid 進行 MD5 加密, 得到 TOKEN 然后我們將剛剛得到的時間戳, 存入 Redis Redis Key 為字符串拼接上 Guid, 方便后面中間件的 TOKEN 驗證, 然后我們把用戶信息存入 Session 最后我們把計算的 TOKEN 以 Cookie 發送給客戶端. # 中間件 我們再來制作一個中間件, 讓我們用戶每一次操作都在我們掌控之中. ~~~ // 項目根目錄運行 php artisan make:middleware SsoMiddleware 上面個命令會在 app/Http/Middleware 下面生成一個 SsoMiddleware.php 文件, 將中間件添加到 Kernel.php /** * The application's route middleware. * * @var array */ protected $routeMiddleware = [ 'auth' => \App\Http\Middleware\Authenticate::class, 'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class, 'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class, 'SsoMiddleware' => \App\Http\Middleware\index\SsoMiddleware::class, ]; ~~~ 現在到中間件中寫程序 app/Http/Middleware/SsoMiddleware.php, 在文件中有 handle 方法, 我們在這個方法中寫邏輯. ~~~ /** * Handle an incoming request. * * @param \Illuminate\Http\Request $request * @param \Closure $next * @return mixed */ public function handle($request, Closure $next) { $userInfo = \Session::get('user_login'); if ($userInfo) { // 獲取 Cookie 中的 token $singletoken = $request->cookie('SINGLETOKEN'); if ($singletoken) { // 從 Redis 獲取 time $redisTime = \Redis::get(STRING_SINGLETOKEN_ . $userInfo->guid); // 重新獲取加密參數加密 $ip = $request->getClientIp(); $secret = md5($ip . $userInfo->guid . $redisTime); if ($singletoken != $secret) { // 記錄此次異常登錄記錄 \DB::table('data_login_exception')->insert(['guid' => $userInfo->guid, 'ip' => $ip, 'addtime' => time()]); // 清除 session 數據 \Session::forget('indexlogin'); return view('/403')->with(['Msg' => '您的帳號在另一個地點登錄..']); } return $next($request); } else { return redirect('/login'); } } else { return redirect('/login'); } } ~~~ 上面中間件之中做的事情是: 獲取用戶存在 Session 之中的數據作為第一重判斷, 如果通過判斷, 進入第二重判斷, 先獲取我們登錄之后發送給用戶的 Cookie 在 Cookie 之中會有我們登錄成功后傳到客戶端的 SINGLETOKEN 我們要做的事情就是重新獲取存入 Redis 的時間戳, 取出來安順序和 IP, Guid, time MD5 加密, 加密后和客戶端得到的 Cookie 之中的 SINGLETOKEN 對比. # 路由組 我們邏輯寫完了, 最后一步就是將用戶登錄后的每一步操作都掌控在自己手里, 這里我們就需要路由組 ~~~ // 有 Sso 中間件的路由組 Route::group(['middleware' => 'SsoMiddleware'], function() { # 用戶登錄成功后的路由 } ~~~
                  <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>

                              哎呀哎呀视频在线观看