diff --git a/hwe/ts/SammoRootAPI.ts b/hwe/ts/SammoRootAPI.ts index 4bcf5b7c..0d3284c0 100644 --- a/hwe/ts/SammoRootAPI.ts +++ b/hwe/ts/SammoRootAPI.ts @@ -4,6 +4,11 @@ import { callSammoAPI, extractHttpMethod, GET, POST, type APICallT, type APITail export type { ValidResponse, InvalidResponse }; const apiRealPath = { + Admin: { + BanEmailAddress: POST as APICallT<{ + email: string, + }> + }, Login: { LoginByID: POST as APICallT<{ username: string, diff --git a/src/sammo/API/Admin/BanEmailAddress.php b/src/sammo/API/Admin/BanEmailAddress.php new file mode 100644 index 00000000..945469ff --- /dev/null +++ b/src/sammo/API/Admin/BanEmailAddress.php @@ -0,0 +1,59 @@ +args); + $v + ->rule('required', [ + 'email', + ]); + + if (!$v->validate()) { + return $v->errorStr(); + } + return null; + } + + public function getRequiredSessionMode(): int + { + return BaseAPI::REQ_LOGIN | BaseAPI::REQ_READ_ONLY; + } + + public function launch(Session $session, ?DateTimeInterface $modifiedSince, ?string $reqEtag): null | string | array | APIRecoveryType + { + $RootDB = RootDB::db(); + $email = $this->args['email']; + + if ($session->userGrade < 5) { + return '권한이 없습니다.'; + } + $globalSalt = RootDB::getGlobalSalt(); + + try{ + $RootDB->insert('banned_member', [ + 'hashed_email' => hash('sha512', $globalSalt.$email.$globalSalt), + 'info' => TimeUtil::now(), + ]); + } + catch(\Exception $e){ + return '이미 등록된 이메일입니다.'; + } + + return [ + 'result' => true, + 'reason' => '등록되었습니다.' + ]; + } +}