Now generating new user IDs at random
Default is length is 6 digits. This can be changed in the linkstack.php config file in /config with the key user_id_length. Sequential numbering can still be used by setting disable_random_user_ids to true.
This commit is contained in:
parent
9e980fea5b
commit
f6155b5959
|
@ -6,6 +6,7 @@ use Illuminate\Contracts\Auth\MustVerifyEmail;
|
||||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||||
use Illuminate\Notifications\Notifiable;
|
use Illuminate\Notifications\Notifiable;
|
||||||
|
use Illuminate\Support\Str;
|
||||||
|
|
||||||
class User extends Authenticatable implements MustVerifyEmail
|
class User extends Authenticatable implements MustVerifyEmail
|
||||||
{
|
{
|
||||||
|
@ -25,7 +26,6 @@ class User extends Authenticatable implements MustVerifyEmail
|
||||||
'provider_id',
|
'provider_id',
|
||||||
'email_verified_at',
|
'email_verified_at',
|
||||||
'littlelink_name',
|
'littlelink_name',
|
||||||
|
|
||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -51,8 +51,29 @@ class User extends Authenticatable implements MustVerifyEmail
|
||||||
{
|
{
|
||||||
return visits($this)->relation();
|
return visits($this)->relation();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function socialAccounts()
|
public function socialAccounts()
|
||||||
{
|
{
|
||||||
return $this->hasMany(socialAccount::class);
|
return $this->hasMany(SocialAccount::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected static function boot()
|
||||||
|
{
|
||||||
|
parent::boot();
|
||||||
|
|
||||||
|
static::creating(function ($user) {
|
||||||
|
if (config('linkstack.disable_random_user_ids') != 'true') {
|
||||||
|
$numberOfDigits = config('linkstack.user_id_length') ?? 6;
|
||||||
|
|
||||||
|
$minIdValue = 10**($numberOfDigits - 1);
|
||||||
|
$maxIdValue = 10**$numberOfDigits - 1;
|
||||||
|
|
||||||
|
do {
|
||||||
|
$randomId = rand($minIdValue, $maxIdValue);
|
||||||
|
} while (User::find($randomId));
|
||||||
|
|
||||||
|
$user->id = $randomId;
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue