[FIX] User creation command referral code
This commit is contained in:
parent
2c041bbe14
commit
2c16379ec1
|
@ -7,6 +7,7 @@ use App\Models\User;
|
||||||
use Illuminate\Console\Command;
|
use Illuminate\Console\Command;
|
||||||
use Illuminate\Support\Facades\Hash;
|
use Illuminate\Support\Facades\Hash;
|
||||||
use Illuminate\Support\Facades\Validator;
|
use Illuminate\Support\Facades\Validator;
|
||||||
|
use Illuminate\Support\Str;
|
||||||
|
|
||||||
class MakeUserCommand extends Command
|
class MakeUserCommand extends Command
|
||||||
{
|
{
|
||||||
|
@ -37,6 +38,19 @@ class MakeUserCommand extends Command
|
||||||
$this->pterodactyl = $pterodactyl;
|
$this->pterodactyl = $pterodactyl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $userid
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function generateCode(){
|
||||||
|
$random = STR::random(8);
|
||||||
|
if (User::where('referral_code', '=', $random)->doesntExist()) {
|
||||||
|
return $random;
|
||||||
|
} else {
|
||||||
|
$this->generateCode();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Execute the console command.
|
* Execute the console command.
|
||||||
*
|
*
|
||||||
|
@ -78,12 +92,12 @@ class MakeUserCommand extends Command
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
$user = User::create([
|
$user = User::create([
|
||||||
'name' => $response['first_name'],
|
'name' => $response['first_name'],
|
||||||
'email' => $response['email'],
|
'email' => $response['email'],
|
||||||
'role' => 'admin',
|
'role' => 'admin',
|
||||||
'password' => Hash::make($password),
|
'password' => Hash::make($password),
|
||||||
|
'referral_code' => $this->generateCode(),
|
||||||
'pterodactyl_id' => $response['id'],
|
'pterodactyl_id' => $response['id'],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
@ -93,6 +107,7 @@ class MakeUserCommand extends Command
|
||||||
['Username', $user->name],
|
['Username', $user->name],
|
||||||
['Ptero-ID', $user->pterodactyl_id],
|
['Ptero-ID', $user->pterodactyl_id],
|
||||||
['Admin', $user->role],
|
['Admin', $user->role],
|
||||||
|
['Referral code', $user->referral_code],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
|
|
Loading…
Reference in a new issue