| | @@ -34,7 +34,27 @@ |
| 34 | 34 | return $this->pubUser;
|
| 35 | 35 | }
|
| 36 | 36 |
|
| 37 | | - public function setToken(string $username, string $password): \Result {
|
| 37 | + public function getUser(string $name): \stdClass {
|
| 38 | + $user = $this->getUserDataFromName($name);
|
| 39 | + unset($user->password);
|
| 40 | + unset($user->tokens);
|
| 41 | + $myself = $this->getUserData();
|
| 42 | + if ($myself->role === 1) {
|
| 43 | + unset($user->email);
|
| 44 | + }
|
| 45 | + $user->name = namecolor($user);
|
| 46 | + $user->regDate = date('Y年m月d日', $user->regDate);
|
| 47 | + $user->gender = $user->gender === 0 ? '男' : ($user->gender === 1 ? '女' : '不明');
|
| 48 | + $user->role = $user->role === 1 ? '管理者' : ($user->role === -1 ? 'BANされた' : 'ユーザー');
|
| 49 | + $user->avatar = '/static/user/'.($user->avatar === '' ? 'noicon.png' : $user->username.'/'.$user->avatar);
|
| 50 | + $user->altName = $user->displayname ?: $user->username;
|
| 51 | + unset($user->username);
|
| 52 | + unset($user->displayname);
|
| 53 | + unset($user->namecolor);
|
| 54 | + return $user;
|
| 55 | + }
|
| 56 | +
|
| 57 | + public function setToken(string $username, #[SensitiveParameter] string $password): \Result {
|
| 38 | 58 | if (!AUTH_ENABLED) return \Result::Error('エラー:認証システムは無効です。');
|
| 39 | 59 | $userData = $this->getUserData();
|
| 40 | 60 | if (!isset($userData->tokens) || !is_array($userData->tokens)) $userData->tokens = [];
|
| | @@ -129,7 +149,7 @@ |
| 129 | 149 | return \Result::Error("エラー:ユーザー「{$username}」は存在しません。");
|
| 130 | 150 | }
|
| 131 | 151 |
|
| 132 | | - public function mkUser(?string $username = null, ?string $password = null, ?string $passwordVerify = null, ?string $email = null): \Result {
|
| 152 | + public function mkUser(?string $username = null, #[SensitiveParameter] ?string $password = null, ?string $passwordVerify = null, ?string $email = null): \Result {
|
| 133 | 153 | if (!AUTH_ENABLED) return \Result::Error('エラー:認証システムは無効です。');
|
| 134 | 154 | if (!AUTH_REGISTER_ENABLED) return \Result::Error('ユーザー登録は無効です。');
|
| 135 | 155 | $resUsr = $this->verifyUsername($username);
|
| | @@ -191,7 +211,7 @@ |
| 191 | 211 |
|
| 192 | 212 | ////////////////////
|
| 193 | 213 |
|
| 194 | | - private function verifyLogin(string $username, string $password): \Result {
|
| 214 | + private function verifyLogin(string $username, #[SensitiveParameter] string $password): \Result {
|
| 195 | 215 | if (!AUTH_ENABLED) return \Result::Error('エラー:認証システムは無効です。');
|
| 196 | 216 | $userData = $this->getUserData();
|
| 197 | 217 | if ($username !== $userData->username || !password_verify($password, $userData->password)) {
|
| | @@ -286,6 +306,39 @@ |
| 286 | 306 | return json_decode($lines);
|
| 287 | 307 | }
|
| 288 | 308 |
|
| 309 | + private function getUserDataFromName(string $name): \stdClass {
|
| 310 | + if (!AUTH_ENABLED) return new \stdClass;
|
| 311 | + $file = scandir($this->dataDir);
|
| 312 | + $userFile = "";
|
| 313 | + $matches = [];
|
| 314 | +
|
| 315 | + foreach ($file as $f) {
|
| 316 | + if ($f === '.kara' || $f === '.' || $f === '..') continue;
|
| 317 | + if (preg_match('/^(.*?)\.(.*?)\.json$/', $f, $matches)) {
|
| 318 | + if (isset($matches[2]) && $matches[2] === $name) {
|
| 319 | + $userFile = $matches[0];
|
| 320 | + break;
|
| 321 | + }
|
| 322 | + }
|
| 323 | + }
|
| 324 | + $path = $this->dataDir.$userFile;
|
| 325 | + unset($file, $userFile);
|
| 326 | +
|
| 327 | + if (!file_exists($path) || !is_readable($path)) {
|
| 328 | + kys('エラー');
|
| 329 | + }
|
| 330 | +
|
| 331 | + $fp = fopen($path, 'r');
|
| 332 | + assert_not_null($fp);
|
| 333 | + if (!$fp) kys('ユーザーが存在しない。');
|
| 334 | + $lines = "";
|
| 335 | + while (($buf = fgets($fp, 4096)) !== false) $lines .= $buf.PHP_EOL;
|
| 336 | + if (!feof($fp)) kys("エラー:不明なエラー");
|
| 337 | + fclose($fp);
|
| 338 | + unset($path);
|
| 339 | + return json_decode($lines);
|
| 340 | + }
|
| 341 | +
|
| 289 | 342 | private function isEmailExist(?string $email = null): \Result {
|
| 290 | 343 | if (!AUTH_ENABLED) return \Result::Error('エラー:認証システムは無効です。');
|
| 291 | 344 | $userList = scandir($this->dataDir);
|
| | @@ -342,7 +395,7 @@ |
| 342 | 395 | return \Result::Success();
|
| 343 | 396 | }
|
| 344 | 397 |
|
| 345 | | - private function verifyPassword(?string $password = null, ?string $passwordVerify = null): \Result {
|
| 398 | + private function verifyPassword(#[SensitiveParameter] ?string $password = null, #[SensitiveParameter] ?string $passwordVerify = null): \Result {
|
| 346 | 399 | if (!AUTH_ENABLED) return \Result::Error('エラー:認証システムは無効です。');
|
| 347 | 400 | if (null === $password || '' === $password) return \Result::Error('エラー:パスワードをご入力下さい。');
|
| 348 | 401 | if ($password !== $passwordVerify) return \Result::Error('エラー:パスワードは一致していません。');
|
| | @@ -355,7 +408,7 @@ |
| 355 | 408 | return \Result::Success();
|
| 356 | 409 | }
|
| 357 | 410 |
|
| 358 | | - private function checkPasswordStandards(?string $password = null): \Result {
|
| 411 | + private function checkPasswordStandards(#[SensitiveParameter] ?string $password = null): \Result {
|
| 359 | 412 | if (!AUTH_ENABLED) return \Result::Error('エラー:認証システムは無効です。');
|
| 360 | 413 | if (strlen($password) < $this->minPassLen) return \Result::Error("エラー:パスワードは{$this->minPassLen}以上をご入力下さい。");
|
| 361 | 414 |
|