Bläddra i källkod

changePassword

AI 6 månader sedan
förälder
incheckning
fdff0676ec

+ 32 - 1
app/Controller/UserController.php

@@ -281,7 +281,38 @@ class UserController extends AbstractController
         return Result::success($result['data']);
     }
 
-
+     /**
+     * 修改密码
+     * @return array
+     */
+    public function  changePassword()
+    {
+        $requireData = $this->request->all();
+        $validator = $this->validationFactory->make(
+            $requireData,
+            [
+                'password' => 'required',
+                'new_password' => 'required|min:6',
+                'new_password1' => 'required|same:new_password',
+            ],
+            [
+                'password.required' => '密码不能为空',
+                'new_password1.required' => '确认密码不能为空',
+                'new_password1.same' => '新密码和确认密码不一致',
+                'new_password.min' =>"密码长度不能低于6位数",
+            ]
+        );
+        if ($validator->fails()){
+            $errorMessage = $validator->errors()->first();
+            return Result::error($errorMessage);
+        }
+        $requireData['user_id'] =Context::get("UserId");
+        $result =  $this->userServiceClient->changePassword($requireData);
+        if ($result['code'] != ErrorCode::SUCCESS) {
+            return Result::error($result['message'],0,[]);
+        }
+        return Result::success($result['data']);
+    }
 
 
 }

+ 10 - 2
app/JsonRpc/UserService.php

@@ -56,7 +56,7 @@ class UserService extends AbstractServiceClient implements UserServiceInterface
      * @remark 创建登录日志信息
      * @param array $data
      */
-    public function createUserLogin(array $data){
+    public function createUserLogin(array $data): mixed{
         return $this->__request(__FUNCTION__, $data);
     }
 
@@ -64,7 +64,7 @@ class UserService extends AbstractServiceClient implements UserServiceInterface
      * 更新用户信息
      * @param array $data
      */
-    public function updateUser(array $data){
+    public function updateUser(array $data): mixed{
         return $this->__request(__FUNCTION__, $data);
     }
 
@@ -140,4 +140,12 @@ class UserService extends AbstractServiceClient implements UserServiceInterface
     public function addWechatInfo(array $data){
         return $this->__request(__FUNCTION__, $data);
     }
+
+     /**
+     * @param array $data
+     * @return array|mixed
+     */
+    public function changePassword(array $data){
+        return $this->__request(__FUNCTION__, $data);
+    }
 }

+ 6 - 0
app/JsonRpc/UserServiceInterface.php

@@ -98,4 +98,10 @@ interface UserServiceInterface
      * @return mixed
      */
     public function addWechatInfo(array $data);
+
+    /**
+     * @param array $data
+     * @return mixed
+     */
+    public function changePassword(array $data);
 }

+ 1 - 1
config/api/user.php

@@ -17,7 +17,7 @@ Router::addGroup(
         Router::post('/addRole', [UserController::class, 'addRole']);
         Router::post('/delRole', [UserController::class, 'delRole']);
         Router::post('/updateRole', [UserController::class, 'updateRole']);
-
+        Router::post('/changePassword', [UserController::class, 'changePassword']);
     },
     ['middleware' => [FooMiddleware::class]]
 );