feat: RootAPI/Admin/BanEmailAddress

This commit is contained in:
2024-12-22 03:56:12 +00:00
parent 367db15d93
commit 2483a7723f
2 changed files with 64 additions and 0 deletions
+5
View File
@@ -4,6 +4,11 @@ import { callSammoAPI, extractHttpMethod, GET, POST, type APICallT, type APITail
export type { ValidResponse, InvalidResponse }; export type { ValidResponse, InvalidResponse };
const apiRealPath = { const apiRealPath = {
Admin: {
BanEmailAddress: POST as APICallT<{
email: string,
}>
},
Login: { Login: {
LoginByID: POST as APICallT<{ LoginByID: POST as APICallT<{
username: string, username: string,
+59
View File
@@ -0,0 +1,59 @@
<?php
namespace sammo\API\Login;
use sammo\Session;
use DateTimeInterface;
use sammo\BaseAPI;
use sammo\Enums\APIRecoveryType;
use sammo\RootDB;
use sammo\TimeUtil;
use sammo\Validator;
class BanEmailAddress extends \sammo\BaseAPI
{
public function validateArgs(): ?string
{
$v = new Validator($this->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' => '등록되었습니다.'
];
}
}