diff --git a/app/Http/Controllers/OAuthController.php b/app/Http/Controllers/OAuthController.php index 77127c45..e394b446 100644 --- a/app/Http/Controllers/OAuthController.php +++ b/app/Http/Controllers/OAuthController.php @@ -86,7 +86,7 @@ class OAuthController extends Controller $userAuth = UserOauth::whereType($provider)->whereIdentifier($registerInfo->getId())->first(); if (! $userAuth) { // 第三方账号未被绑定 - $user = Helpers::addUser($registerInfo->getEmail(), Str::random(), MiB * sysConfig('default_traffic'), (int) sysConfig('default_days'), $registerInfo->getNickname()); + $user = Helpers::addUser($registerInfo->getEmail(), Str::random(), MiB * sysConfig('default_traffic'), (int) sysConfig('default_days'), $registerInfo->getNickname(), 1); $user->userAuths()->create([ 'type' => $provider, diff --git a/app/Utils/Helpers.php b/app/Utils/Helpers.php index 79f65cb2..616b0eb2 100644 --- a/app/Utils/Helpers.php +++ b/app/Utils/Helpers.php @@ -47,14 +47,15 @@ class Helpers /** * 添加用户. * - * @param string $username 用户 + * @param string $username 用户名 * @param string $password 用户密码 * @param int $transfer_enable 可用流量 * @param int $date 可使用天数 * @param int|null $inviter_id 邀请人 * @param string|null $nickname 昵称 + * @param int $status 状态:-1-禁用、0-未激活、1-正常 */ - public static function addUser(string $username, string $password, int $transfer_enable = 0, int $date = 0, ?int $inviter_id = null, ?string $nickname = null): User + public static function addUser(string $username, string $password, int $transfer_enable = 0, int $date = 0, ?int $inviter_id = null, ?string $nickname = null, int $status = 0): User { return User::create([ 'nickname' => $nickname ?? $username, @@ -71,6 +72,7 @@ class Helpers 'user_group_id' => null, 'reg_ip' => IP::getClientIp(), 'inviter_id' => $inviter_id, + 'status' => $status, ]); } diff --git a/database/migrations/2024_07_14_233110_update_oauth_accounts_status.php b/database/migrations/2024_07_14_233110_update_oauth_accounts_status.php new file mode 100644 index 00000000..9050a762 --- /dev/null +++ b/database/migrations/2024_07_14_233110_update_oauth_accounts_status.php @@ -0,0 +1,30 @@ +join('user', 'user_oauth.user_id', '=', 'user.id') + ->where('user.status', 0) + ->whereRaw('ABS(TIMESTAMPDIFF(SECOND, user_oauth.created_at, user.created_at)) <= 5') + ->update(['user.status' => 1]); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + DB::table('user_oauth') + ->join('user', 'user_oauth.user_id', '=', 'user.id') + ->where('user.status', 1) // 状态从1 + ->whereRaw('ABS(TIMESTAMPDIFF(SECOND, user_oauth.created_at, user.created_at)) <= 5') + ->update(['user.status' => 0]); // 更新为0 + } +};