|
|
@@ -2,22 +2,31 @@
|
|
|
|
|
|
namespace App\Services;
|
|
|
|
|
|
+use App\Enums\UserTypeEnum;
|
|
|
use App\Models\User;
|
|
|
use App\Models\PersonalAccessToken;
|
|
|
use Carbon\Carbon;
|
|
|
+use Exception;
|
|
|
use Illuminate\Support\Facades\Auth;
|
|
|
use Illuminate\Support\Facades\DB;
|
|
|
use Illuminate\Support\Str;
|
|
|
|
|
|
class AuthService
|
|
|
{
|
|
|
- public function login(string $email, string $password): ?array
|
|
|
+ public function login(string $email, string $password, string $origem): ?array
|
|
|
{
|
|
|
if (!Auth::attempt(["email" => $email, "password" => $password])) {
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
$user = User::where("email", $email)->first();
|
|
|
+
|
|
|
+ if ($origem === 'admin') {
|
|
|
+ if ($user->user_type !== UserTypeEnum::ADMIN) {
|
|
|
+ throw new Exception('credenciais invalidas para acesso de franqueadora');
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
$deviceId = Str::uuid()->toString();
|
|
|
|
|
|
$accessToken = $user->createAccessToken($deviceId);
|