feat: RootAPI/Admin/BanEmailAddress
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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' => '등록되었습니다.'
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user