mirror of
https://github.com/sp-tarkov/forge.git
synced 2025-02-12 12:10:41 -05:00
Username Handling
- When a new user is created using Discord OAuth information, if the username returned from Discord is already taken, append randomness to the end of the username. - Validates that a new account name is unique. - Validates that an updated account name is unique.
This commit is contained in:
parent
7a68e31f30
commit
0d043ff880
@ -20,7 +20,7 @@ class CreateNewUser implements CreatesNewUsers
|
||||
public function create(array $input): User
|
||||
{
|
||||
Validator::make($input, [
|
||||
'name' => ['required', 'string', 'max:255'],
|
||||
'name' => ['required', 'string', 'max:36', 'unique:users'],
|
||||
'email' => ['required', 'string', 'email', 'max:255', 'unique:users'],
|
||||
'password' => $this->passwordRules(),
|
||||
'terms' => Jetstream::hasTermsAndPrivacyPolicyFeature() ? ['accepted', 'required'] : '',
|
||||
|
@ -16,7 +16,7 @@ class UpdateUserProfileInformation implements UpdatesUserProfileInformation
|
||||
public function update(User $user, array $input): void
|
||||
{
|
||||
Validator::make($input, [
|
||||
'name' => ['required', 'string', 'max:255'],
|
||||
'name' => ['required', 'string', 'max:255', Rule::unique('users')->ignore($user->id)],
|
||||
'email' => ['required', 'email', 'max:255', Rule::unique('users')->ignore($user->id)],
|
||||
'photo' => ['nullable', 'mimes:jpg,jpeg,png', 'max:1024'],
|
||||
'cover' => ['nullable', 'mimes:jpg,jpeg,png', 'max:2048'],
|
||||
|
@ -78,14 +78,22 @@ class SocialiteController extends Controller
|
||||
return $oauthConnection->user;
|
||||
}
|
||||
|
||||
// If the username already exists in the database, append a random string to it to ensure uniqueness.
|
||||
$username = $providerUser->getName() ?? $providerUser->getNickname();
|
||||
$random = '';
|
||||
while (User::whereName($username.$random)->exists()) {
|
||||
$random = '-'.Str::random(5);
|
||||
}
|
||||
$username .= $random;
|
||||
|
||||
// The user has not connected their account with this OAuth provider before, so a new connection needs to be
|
||||
// established. Check if the user has an account with the same email address that's passed in from the provider.
|
||||
// If one exists, connect that account. Otherwise, create a new one.
|
||||
|
||||
return DB::transaction(function () use ($providerUser, $provider) {
|
||||
return DB::transaction(function () use ($providerUser, $provider, $username) {
|
||||
|
||||
$user = User::firstOrCreate(['email' => $providerUser->getEmail()], [
|
||||
'name' => $providerUser->getName() ?? $providerUser->getNickname(),
|
||||
'name' => $username,
|
||||
'password' => null,
|
||||
]);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user