|
|
@ -4,6 +4,7 @@ namespace App\Http\Controllers; |
|
|
|
|
|
|
|
use App\Models\Business; |
|
|
|
use App\Models\User; |
|
|
|
use App\Notifications\DBNotification; |
|
|
|
use App\Notifications\MailNotification; |
|
|
|
use Illuminate\Http\JsonResponse; |
|
|
|
use Illuminate\Http\Request; |
|
|
@ -99,6 +100,9 @@ class AuthController extends Controller |
|
|
|
if ($user && Hash::check($request->password, $user->password)) { |
|
|
|
Auth::setUser($user); |
|
|
|
|
|
|
|
// for new device login
|
|
|
|
$this->loginNotif($this->firstOrNot()); |
|
|
|
|
|
|
|
return [ |
|
|
|
'auth' => $this->createFingerPrint(), |
|
|
|
'businesses' => Auth::user()->businesses->keyBy('id')->map(fn($b, $bid) => Business::info($bid)) |
|
|
@ -252,4 +256,29 @@ class AuthController extends Controller |
|
|
|
|
|
|
|
return Auth::user()->fingerprints()->firstOrCreate($attributes, $attributes + $values); |
|
|
|
} |
|
|
|
|
|
|
|
public function firstOrNot() |
|
|
|
{ |
|
|
|
return Auth::user()->fingerprints()->where([ |
|
|
|
['agent', '!=',request()->getAgent()], |
|
|
|
['ip', '!=',request()->getClientIp()], |
|
|
|
['os', '!=',request()->getOS()], |
|
|
|
['latitude', '!=',\request()->getLocation()->getAttribute('lat')], |
|
|
|
['longitude', '!=',\request()->getLocation()->getAttribute('lon')], |
|
|
|
])->exists(); |
|
|
|
} |
|
|
|
|
|
|
|
public function loginNotif($send) |
|
|
|
{ |
|
|
|
if ($send) { |
|
|
|
Notification::send(Auth::user(), new MailNotification([ |
|
|
|
'greeting' => 'hi', |
|
|
|
'subject' => 'login with another device', |
|
|
|
'body' => 'Warning someone login to your account with new device. check it and dont worry', |
|
|
|
])); |
|
|
|
Notification::send(Auth::user(), new DBNotification([ |
|
|
|
'body' => 'Warning someone login to your account with new device. check it and dont worry', |
|
|
|
])); |
|
|
|
} |
|
|
|
} |
|
|
|
} |