48 lines
1.5 KiB
PHP
48 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace App\Services\Auth;
|
|
|
|
use App\Models\User;
|
|
use Illuminate\Support\Str;
|
|
use Illuminate\Support\Facades\Hash;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Illuminate\Contracts\Auth\Authenticatable;
|
|
use Illuminate\Support\Facades\Auth;
|
|
|
|
class RegistrationService
|
|
{
|
|
public function createUser(array $data): User
|
|
{
|
|
return DB::transaction(function () use ($data) {
|
|
$user = User::create([
|
|
'username' => 'rdl_'.Str::random(10),
|
|
'phone' => $data['phone'],
|
|
'email' => $data['email'] ?? null,
|
|
'password' => Hash::make($data['password'] ?? Str::random(12)),
|
|
'level' => $data['level'],
|
|
'fullname' => $data['fullname'] ?? null,
|
|
'national_code' => $data['national_code'] ?? null,
|
|
'clinic_name' => $data['clinic_name'] ?? null,
|
|
'clinic_phone' => $data['clinic_phone'] ?? null,
|
|
'province' => $data['province'] ?? null,
|
|
'city' => $data['city'] ?? null,
|
|
'address' => $data['address'] ?? null,
|
|
'specialty' => $data['specialty'] ?? null,
|
|
]);
|
|
|
|
return $user;
|
|
});
|
|
}
|
|
|
|
public function registerAndLogin(array $data): Authenticatable
|
|
{
|
|
$user = $this->createUser($data);
|
|
|
|
Auth::login($user);
|
|
session()->regenerate();
|
|
session()->forget(['register_phone', 'verified_phone', 'otp_verified', 'login_phone', 'login_level', 'available_levels']);
|
|
|
|
return $user;
|
|
}
|
|
}
|