user add provider_id

This commit is contained in:
xiaomlove
2025-05-02 14:49:50 +07:00
parent cd6ac587c2
commit 14f06778b2
4 changed files with 41 additions and 4 deletions

View File

@@ -125,7 +125,7 @@ class OauthController extends Controller
}
}
$newUser = $this->createUser($providerUsername, $providerEmail);
$newUser = $this->createUser($providerUsername, $providerEmail, $provider->id);
$socialAccountData = [
'user_id' => $newUser->id,
'provider_id' => $provider->id,
@@ -139,7 +139,7 @@ class OauthController extends Controller
return redirect($homeUrl);
}
private function createUser($username, $email): User
private function createUser($username, $email, $providerId): User
{
if ($username) {
if (User::query()->where('username', $username)->exists()) {
@@ -154,6 +154,7 @@ class OauthController extends Controller
'email' => $email,
'password' => $password,
'password_confirmation' => $password,
'provider_id' => $providerId,
];
$userRep = new UserRepository();
for ($i = 0; $i < 3; $i++) {

View File

@@ -185,7 +185,7 @@ class User extends Authenticatable implements FilamentUser, HasName
'username', 'email', 'passhash', 'secret', 'stylesheet', 'editsecret', 'added', 'enabled', 'status',
'leechwarn', 'leechwarnuntil', 'page', 'class', 'uploaded', 'downloaded', 'clientselect', 'showclienterror', 'last_home',
'seedbonus', 'downloadpos', 'vip_added', 'vip_until', 'title', 'invites', 'attendance_card',
'seed_points_per_hour', 'passkey', 'auth_key', 'last_login', 'lang'
'seed_points_per_hour', 'passkey', 'auth_key', 'last_login', 'lang', 'provider_id'
];
/**

View File

@@ -10,6 +10,7 @@ use App\Models\ExamUser;
use App\Models\Invite;
use App\Models\LoginLog;
use App\Models\Message;
use App\Models\OauthProvider;
use App\Models\Setting;
use App\Models\Snatch;
use App\Models\Torrent;
@@ -89,7 +90,7 @@ class UserRepository extends BaseRepository
/**
* create user
*
* @param array $params must: username, email, password, password_confirmation. optional: id, class
* @param array $params must: username, email, password, password_confirmation. optional: id, class, provider_id
* @return User
*/
public function store(array $params)
@@ -155,6 +156,13 @@ class UserRepository extends BaseRepository
do_log("[CREATE_USER], specific id: " . $params['id']);
$user->id = $params['id'];
}
if (!empty($params['provider_id'])) {
if (!OauthProvider::query()->find($params['provider_id'])) {
throw new \InvalidArgumentException("provider_id: {$params['provider_id']} not exists.");
}
do_log("[CREATE_USER], specific provider_id: " . $params['provider_id']);
$user->provider_id = $params['provider_id'];
}
$user->save();
fire_event("user_created", $user);
return $user;

View File

@@ -0,0 +1,28 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('users', function (Blueprint $table) {
$table->bigInteger("provider_id")->default(0);
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('users', function (Blueprint $table) {
$table->dropColumn("provider_id");
});
}
};