|
@@ -9,17 +9,22 @@ use App\Enums\UserTypeEnum;
|
|
|
use Carbon\Carbon;
|
|
use Carbon\Carbon;
|
|
|
use Illuminate\Support\Facades\Auth;
|
|
use Illuminate\Support\Facades\Auth;
|
|
|
use Illuminate\Support\Facades\DB;
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
|
+use Illuminate\Support\Facades\Hash;
|
|
|
use Illuminate\Support\Str;
|
|
use Illuminate\Support\Str;
|
|
|
|
|
|
|
|
class AuthService
|
|
class AuthService
|
|
|
{
|
|
{
|
|
|
- public function login(string $email, string $password, string $tipo): ?array
|
|
|
|
|
|
|
+ public function login(string $identifier, string $password, string $tipo): ?array
|
|
|
{
|
|
{
|
|
|
- if (!Auth::attempt(["email" => $email, "password" => $password])) {
|
|
|
|
|
|
|
+ $user = User::where("email", $identifier)
|
|
|
|
|
+ ->orWhere("registration", $identifier)
|
|
|
|
|
+ ->first();
|
|
|
|
|
+
|
|
|
|
|
+ if (!$user || !Hash::check($password, $user->password)) {
|
|
|
return null;
|
|
return null;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- $user = User::where("email", $email)->first();
|
|
|
|
|
|
|
+ Auth::login($user);
|
|
|
|
|
|
|
|
if ($user->type->value !== $tipo) {
|
|
if ($user->type->value !== $tipo) {
|
|
|
Auth::logout();
|
|
Auth::logout();
|