[ 'username' => 'required|alpha_dash:ascii|max:50', 'password' => 'required|alpha_dash:ascii|max:50', 'device' => 'required|alpha_dash:ascii|max:10', ], ]; function signIn(): \Illuminate\Http\JsonResponse { $request = request(); $username = $request->input('username'); $password = $request->input('password'); $device = $request->input('device'); $oCustomerUser = new CustomerUser(); $oUser = $oCustomerUser->findItemByUsername($username); if (!$oUser) { return $this->error('用户名不存在'); } if (!$oCustomerUser->checkPasswd($oUser->id,$password)) { return $this->error('密码错误'); } $oAuthService = new AuthService(); $token = $oAuthService->createTokenToUser($oUser->id,$device); $data = [ 'token' => $token, 'user' => [ 'id' => $oUser->id, 'username' => $oUser->username, 'nickname' => $oUser->nickname, 'is_google_auth' => $oUser->is_google_auth, 'created_at' => $oUser->created_at, 'updated_at' => $oUser->updated_at, ], ]; return $this->success($data); } function signOut(): \Illuminate\Http\JsonResponse { $oAuthService = new AuthService(); $token = $oAuthService->getTokenFromReq(); $aUser = $oAuthService->getCurrentUser(); $oAuthService->delTokenToUser($aUser['uid'],$token); return $this->success(); } function register() { $request = request(); $username = $request->input('username'); $password = $request->input('password'); $device = $request->input('device'); $oCustomerUser = new CustomerUser(); $oUser = $oCustomerUser->findItemByUsername($username,['id']); if ($oUser) { return $this->error('用户名已存在'); } $oUser = $oCustomerUser->addUser([ 'username' => $username, 'password' => $password, 'nickname' => $username, ]); if (!$oUser) { return $this->error('注册失败'); } $oAuthService = new AuthService(); $token = $oAuthService->createTokenToUser($oUser->id,$device); $data = [ 'token' => $token, 'user' => [ 'id' => $oUser->id, 'username' => $oUser->username, 'nickname' => $oUser->nickname, 'is_google_auth' => $oUser->is_google_auth, 'created_at' => $oUser->created_at, 'updated_at' => $oUser->updated_at, ], ]; return $this->success($data); } }