{"id":258,"date":"2025-04-01T10:48:12","date_gmt":"2025-04-01T10:48:12","guid":{"rendered":"https:\/\/www.yehger.com\/?p=258"},"modified":"2025-04-01T10:48:32","modified_gmt":"2025-04-01T10:48:32","slug":"fastadmin-%e7%a6%81%e6%ad%a2%e5%a4%9a%e7%ab%af%e7%99%bb%e5%bd%95","status":"publish","type":"post","link":"https:\/\/www.yehger.com\/index.php\/2025\/04\/01\/fastadmin-%e7%a6%81%e6%ad%a2%e5%a4%9a%e7%ab%af%e7%99%bb%e5%bd%95\/","title":{"rendered":"fastadmin \u7981\u6b62\u591a\u5730\u591a\u7aef\u767b\u5f55"},"content":{"rendered":"<pre><code class=\"language-php\">public function login()\n    {\n        $account = $this-&gt;request-&gt;post(&#039;account&#039;);\n        $password = $this-&gt;request-&gt;post(&#039;password&#039;);\n        if (!$account || !$password) {\n            $this-&gt;error(__(&#039;Invalid parameters&#039;));\n        }\n        $ret = $this-&gt;auth-&gt;login($account, $password);\n        if ($ret) {\n            $userInfo = $this-&gt;auth-&gt;getUserinfo();\n            $token = $userInfo[&#039;token&#039;]; \/\/ \u83b7\u53d6\u5f53\u524d\u767b\u5f55\u7684 token\n            $config = \\think\\Config::get(&#039;token&#039;);\n            $realToken = hash_hmac($config[&#039;hashalgo&#039;], $token, $config[&#039;key&#039;]);\n            if ($realToken) {\n                \/\/ \u5220\u9664\u8be5\u7528\u6237\u9664\u4e86\u6700\u65b0 token \u4ee5\u5916\u7684\u6240\u6709 token\n                Db::name(&#039;user_token&#039;)\n                    -&gt;where(&#039;user_id&#039;, $userInfo[&#039;id&#039;])\n                    -&gt;where(&#039;token&#039;,&#039;&lt;&gt;&#039;,$realToken)\n                    -&gt;delete();\n            }\n\n            $data = [&#039;userinfo&#039; =&gt; $userInfo];\n            $this-&gt;success(__(&#039;Logged in successful&#039;), $data);\n        } else {\n            $this-&gt;error($this-&gt;auth-&gt;getError());\n        }\n    }<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>public function login() { $account = $this-&gt;request-&gt;post(&#039;account&#039;); $password = $this-&gt;request-&gt;post(&#039;password&#039;); if (!$account || !$password) { $this-&gt;error(__(&#039;Invalid parameters&#039;)); } $ret =&#8230; <a class=\"read-more\" href=\"https:\/\/www.yehger.com\/index.php\/2025\/04\/01\/fastadmin-%e7%a6%81%e6%ad%a2%e5%a4%9a%e7%ab%af%e7%99%bb%e5%bd%95\/\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-258","post","type-post","status-publish","format-standard","hentry","category-my-nonsence"],"_links":{"self":[{"href":"https:\/\/www.yehger.com\/index.php\/wp-json\/wp\/v2\/posts\/258","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.yehger.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.yehger.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.yehger.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.yehger.com\/index.php\/wp-json\/wp\/v2\/comments?post=258"}],"version-history":[{"count":2,"href":"https:\/\/www.yehger.com\/index.php\/wp-json\/wp\/v2\/posts\/258\/revisions"}],"predecessor-version":[{"id":260,"href":"https:\/\/www.yehger.com\/index.php\/wp-json\/wp\/v2\/posts\/258\/revisions\/260"}],"wp:attachment":[{"href":"https:\/\/www.yehger.com\/index.php\/wp-json\/wp\/v2\/media?parent=258"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.yehger.com\/index.php\/wp-json\/wp\/v2\/categories?post=258"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.yehger.com\/index.php\/wp-json\/wp\/v2\/tags?post=258"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}