おマンコ
This commit is contained in:
@@ -35,6 +35,7 @@ class Auth {
|
||||
}
|
||||
|
||||
public function setToken(string $username, string $password): \Result {
|
||||
if (!AUTH_ENABLED) return \Result::Error('エラー:認証システムは無効です。');
|
||||
$userData = $this->getUserData();
|
||||
if (!isset($userData->tokens) || !is_array($userData->tokens)) $userData->tokens = [];
|
||||
|
||||
@@ -102,12 +103,14 @@ class Auth {
|
||||
}
|
||||
|
||||
public function getToken(): string {
|
||||
if (!AUTH_ENABLED) return '';
|
||||
$userData = $this->getUserData();
|
||||
if (!isset($userData->tokens) || !is_array($userData->tokens)) $userData->tokens = [];
|
||||
$userData = $this->purgeOldTokens($userData);
|
||||
}
|
||||
|
||||
public function logout(?string $token = null): \Result {
|
||||
if (!AUTH_ENABLED) return \Result::Error('エラー:認証システムは無効です。');
|
||||
$secure = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off');
|
||||
$domain = $_SERVER['SERVER_NAME'];
|
||||
$userData = $this->getUserData();
|
||||
@@ -131,6 +134,7 @@ class Auth {
|
||||
}
|
||||
|
||||
public function isUserExist(?string $username = null): \Result {
|
||||
if (!AUTH_ENABLED) return \Result::Error('エラー:認証システムは無効です。');
|
||||
if (null === $username) return \Result::Error('エラー:ユーザー名をご入力下さい。');
|
||||
$userList = scandir($this->dataDir);
|
||||
|
||||
@@ -145,6 +149,7 @@ class Auth {
|
||||
}
|
||||
|
||||
public function mkUser(?string $username = null, ?string $password = null, ?string $passwordVerify = null, ?string $email = null): \Result {
|
||||
if (!AUTH_ENABLED) return \Result::Error('エラー:認証システムは無効です。');
|
||||
if (!AUTH_REGISTER_ENABLED) return \Result::Error('ユーザー登録は無効です。');
|
||||
$resUsr = $this->verifyUsername($username);
|
||||
$resPwd = $this->verifyPassword($password, $passwordVerify);
|
||||
@@ -206,6 +211,7 @@ class Auth {
|
||||
////////////////////
|
||||
|
||||
private function verifyLogin(string $username, string $password): \Result {
|
||||
if (!AUTH_ENABLED) return \Result::Error('エラー:認証システムは無効です。');
|
||||
$userData = $this->getUserData();
|
||||
if ($username !== $userData->username || !password_verify($password, $userData->password)) {
|
||||
return \Result::Error('エラー:ユーザー名又はパスワードが一致していません。');
|
||||
@@ -225,6 +231,7 @@ class Auth {
|
||||
}
|
||||
|
||||
private function purgeOldTokens(\stdClass $userData): \stdClass|\Result {
|
||||
if (!AUTH_ENABLED) return \Result::Error('エラー:認証システムは無効です。');
|
||||
// 有効期限切れたトークンの削除
|
||||
$out = $userData;
|
||||
$out->tokens = array_filter($userData->tokens, function($t): bool {
|
||||
@@ -241,7 +248,8 @@ class Auth {
|
||||
return $out;
|
||||
}
|
||||
|
||||
private function getUserId(?string $username = null, ?string $token): int {
|
||||
private function getUserId(?string $username = null, ?string $token = null): int {
|
||||
if (!AUTH_ENABLED) return 0;
|
||||
if (!$username && !$token) return 0;
|
||||
$file = scandir($this->dataDir);
|
||||
$matches = [];
|
||||
@@ -267,6 +275,7 @@ class Auth {
|
||||
}
|
||||
|
||||
private function getUserData(): \stdClass {
|
||||
if (!AUTH_ENABLED) return new \stdClass;
|
||||
$file = scandir($this->dataDir);
|
||||
$userFile = "";
|
||||
$matches = [];
|
||||
@@ -297,6 +306,7 @@ class Auth {
|
||||
}
|
||||
|
||||
private function isEmailExist(?string $email = null): \Result {
|
||||
if (!AUTH_ENABLED) return \Result::Error('エラー:認証システムは無効です。');
|
||||
$userList = scandir($this->dataDir);
|
||||
$matches = [];
|
||||
|
||||
@@ -316,6 +326,7 @@ class Auth {
|
||||
}
|
||||
|
||||
private function verifyEmail(?string $email = null): \Result {
|
||||
if (!AUTH_ENABLED) return \Result::Error('エラー:認証システムは無効です。');
|
||||
if (null === $email || '' === $email) return \Result::Error('エラー:メールアドレスをご入力下さい。');
|
||||
if (strpos($email, '@') === false) return \Result::Error('エラー:メールアドレスは不正です。');
|
||||
|
||||
@@ -335,6 +346,7 @@ class Auth {
|
||||
}
|
||||
|
||||
private function verifyUsername(?string $username): \Result {
|
||||
if (!AUTH_ENABLED) return \Result::Error('エラー:認証システムは無効です。');
|
||||
if (null === $username || '' === $username) return \Result::Error('エラー:ユーザー名をご入力下さい。');
|
||||
if (strlen($username) < 6) return \Result::Error('エラー:ユーザー名は6文字以上をご入力下さい。');
|
||||
|
||||
@@ -350,6 +362,7 @@ class Auth {
|
||||
}
|
||||
|
||||
private function verifyPassword(?string $password = null, ?string $passwordVerify = null): \Result {
|
||||
if (!AUTH_ENABLED) return \Result::Error('エラー:認証システムは無効です。');
|
||||
if (null === $password || '' === $password) return \Result::Error('エラー:パスワードをご入力下さい。');
|
||||
if ($password !== $passwordVerify) return \Result::Error('エラー:パスワードは一致していません。');
|
||||
|
||||
@@ -362,6 +375,7 @@ class Auth {
|
||||
}
|
||||
|
||||
private function checkPasswordStandards(?string $password = null): \Result {
|
||||
if (!AUTH_ENABLED) return \Result::Error('エラー:認証システムは無効です。');
|
||||
if (strlen($password) < $this->minPassLen) return \Result::Error("エラー:パスワードは{$this->minPassLen}以上をご入力下さい。");
|
||||
|
||||
if (!\countmatch($password)) {
|
||||
|
||||
Reference in New Issue
Block a user