From 410a838e8b1dbdf0e80a3ffcbbc944c254c6f035 Mon Sep 17 00:00:00 2001 From: Jerry Yan <792602257@qq.com> Date: Mon, 2 Dec 2024 14:35:03 +0800 Subject: [PATCH] =?UTF-8?q?Staff=E7=99=BB=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/controller/api/Login.php | 20 ++++++++++++++++--- .../src/controller/api/auth/Staff.php | 7 +++++++ .../src/model/InspectionStaffToken.php | 2 +- 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/plugs/think-plugs-inspection/src/controller/api/Login.php b/plugs/think-plugs-inspection/src/controller/api/Login.php index cff4722..eec6018 100644 --- a/plugs/think-plugs-inspection/src/controller/api/Login.php +++ b/plugs/think-plugs-inspection/src/controller/api/Login.php @@ -10,17 +10,31 @@ class Login extends Controller public function login() { $this->title = '登录'; - $this->staff = InspectionStaff::mk()->where('phone', $this->request->post('phone'))->find(); + if ($this->request->post('phone')) { + $where = $this->_vali([ + 'phone.require' => '手机号码不能为空', + ]); + $this->staff = InspectionStaff::mk()->where($where)->find(); + } else { + $where = $this->_vali([ + 'account.require' => '登录账号不能为空', + ]); + $this->staff = InspectionStaff::mk()->where($where)->find(); + } if (empty($this->staff)) { $this->error('用户不存在'); } - if ($this->staff->password !== md5($this->request->post('password'))) { + ["password" => $password] = $this->_vali([ + 'password.require' => '登录密码不能为空', + ]); + if ($this->staff->password !== $password) { $this->error('密码错误'); } $this->staff->save(['last_login_at' => date('Y-m-d H:i:s')]); -// $this->staff->tokens()->where('token', '<>', '')->delete(); + $this->staff->tokens()->where('token', '<>', '')->delete(); $this->success('登录成功', [ 'token' => $this->staff->tokens()->save(['token' => md5(uniqid())])->token, + 'user' => $this->staff->toArray(), ]); } } \ No newline at end of file diff --git a/plugs/think-plugs-inspection/src/controller/api/auth/Staff.php b/plugs/think-plugs-inspection/src/controller/api/auth/Staff.php index 0ac51fc..bbe7c10 100644 --- a/plugs/think-plugs-inspection/src/controller/api/auth/Staff.php +++ b/plugs/think-plugs-inspection/src/controller/api/auth/Staff.php @@ -6,6 +6,13 @@ use plugin\inspection\controller\api\Auth; class Staff extends Auth { + public function check() { + $this->success('登录成功', [ + 'token' => $this->tokenInfo->token, + 'user' => $this->staff + ]); + } + public function logout() { $this->staff->tokens()->delete(); $this->success('退出成功'); diff --git a/plugs/think-plugs-inspection/src/model/InspectionStaffToken.php b/plugs/think-plugs-inspection/src/model/InspectionStaffToken.php index 420d780..1ecbd3d 100644 --- a/plugs/think-plugs-inspection/src/model/InspectionStaffToken.php +++ b/plugs/think-plugs-inspection/src/model/InspectionStaffToken.php @@ -8,6 +8,6 @@ class InspectionStaffToken extends Model { public function staff() { - return $this->belongsTo(InspectionStaff::class, 'id', 'staff_id'); + return $this->belongsTo(InspectionStaff::class, 'staff_id'); } } \ No newline at end of file