userValidate = $userValidate; $this->userService = $userService; } /** * 注册 function * * @author dotdotdot <6383846@qq.com> * @date 2022-08-06 * @param Request $request * @return array */ public function register(Request $request) { $actionAllowed = ['method' => 'register_', 'key' => $request->param('phone'), 'period' => 5]; Hook::listen('action_allowed', $actionAllowed); $params = [ 'phone' => $request->param('phone'), 'password' => $request->param('password'), 'confirm_password' => $request->param('confirm_password') ]; if (!$this->userValidate->scene('register')->check($params)) { throw new ApiException((string)$this->userValidate->getError(), EnumCode::ValidateError); } $this->userService->register($params); return json(['code' => EnumCode::Success, 'msg' => 'ok']); } /** * 登录 function * * @author dotdotdot <6383846@qq.com> * @date 2022-08-08 * @param Request $request * @return array */ public function login(Request $request) { $actionAllowed = ['method' => 'login_', 'key' => $request->param('phone'), 'period' => 5]; Hook::listen('action_allowed', $actionAllowed); $params = [ 'phone' => $request->param('phone'), 'password' => $request->param('password') ]; if (!$this->userValidate->scene('login')->check($params)) { throw new ApiException((string)$this->userValidate->getError(), EnumCode::ValidateError); } $data = $this->userService->login($params); return json(['code' => EnumCode::Success, 'msg' => 'ok', 'data' => $data]); } }