Compare commits
1 commit
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
68cf2d94b0 |
2 changed files with 66 additions and 13 deletions
|
|
@ -4,17 +4,22 @@ namespace App\Http\Controllers\Fo\Auth;
|
||||||
|
|
||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Controller;
|
||||||
use App\Http\Controllers\Fo\Klub\MesBrController;
|
use App\Http\Controllers\Fo\Klub\MesBrController;
|
||||||
|
use App\Models\Customer;
|
||||||
use App\Models\Game;
|
use App\Models\Game;
|
||||||
use App\Providers\RouteServiceProvider;
|
use App\Providers\RouteServiceProvider;
|
||||||
|
use Exception;
|
||||||
use Illuminate\Contracts\Auth\StatefulGuard;
|
use Illuminate\Contracts\Auth\StatefulGuard;
|
||||||
use Illuminate\Contracts\View\View;
|
use Illuminate\Contracts\View\View;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
use Illuminate\Foundation\Auth\AuthenticatesUsers;
|
use Illuminate\Foundation\Auth\AuthenticatesUsers;
|
||||||
use Illuminate\Foundation\Auth\ThrottlesLogins;
|
use Illuminate\Foundation\Auth\ThrottlesLogins;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Support\Arr;
|
||||||
use Illuminate\Support\Facades\Auth;
|
use Illuminate\Support\Facades\Auth;
|
||||||
use Illuminate\Support\Facades\Cache;
|
use Illuminate\Support\Facades\Cache;
|
||||||
|
use Illuminate\Support\Facades\Log;
|
||||||
use Illuminate\Support\Facades\Session;
|
use Illuminate\Support\Facades\Session;
|
||||||
|
use LDC\LDCCRM\Models\Customer as CrmCustomer;
|
||||||
|
|
||||||
class LoginController extends Controller
|
class LoginController extends Controller
|
||||||
{
|
{
|
||||||
|
|
@ -99,4 +104,49 @@ class LoginController extends Controller
|
||||||
{
|
{
|
||||||
return response()->redirectToIntended()->getTargetUrl();
|
return response()->redirectToIntended()->getTargetUrl();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Attempt to log the user into the application.
|
||||||
|
*
|
||||||
|
* @param \Illuminate\Http\Request $request
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
protected function attemptLogin(Request $request): bool
|
||||||
|
{
|
||||||
|
$credentials = $this->credentials($request);
|
||||||
|
$customerModel = Customer::query()->where('email', Arr::get($credentials, 'email'))->first();
|
||||||
|
$crmCustomer = CrmCustomer::findWithEmail(Arr::get($credentials, 'email'));
|
||||||
|
|
||||||
|
// Check database customer.
|
||||||
|
if (!$customerModel) {
|
||||||
|
// Check crm customer.
|
||||||
|
if (!$crmCustomer) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @var \App\Models\Customer $customerModel */
|
||||||
|
$customerModel = new Customer(Arr::only($crmCustomer->jsonSerialize(), ['email']));
|
||||||
|
$customerModel->hashcode = $crmCustomer->hashcode;
|
||||||
|
|
||||||
|
if (!$customerModel->saveOrFail()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Check crm customer.
|
||||||
|
if (!$crmCustomer) {
|
||||||
|
$customerModel->delete();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} //end if
|
||||||
|
|
||||||
|
try {
|
||||||
|
CrmCustomer::login(Arr::get($credentials, 'email'), Arr::get($credentials, 'password'));
|
||||||
|
} catch (Exception $ex) {
|
||||||
|
Log::error($ex);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->guard()->loginUsingId($customerModel->getKey());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -80,7 +80,9 @@ class Customer extends Authenticatable implements MustVerifyEmail
|
||||||
}
|
}
|
||||||
$model->notify(new DestroyedCustomer());
|
$model->notify(new DestroyedCustomer());
|
||||||
} else {
|
} else {
|
||||||
$model->notify(new DestroyCustomer());
|
if ($model->existsInCrm()) {
|
||||||
|
$model->notify(new DestroyCustomer());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
static::restored(function () {
|
static::restored(function () {
|
||||||
|
|
@ -222,7 +224,7 @@ class Customer extends Authenticatable implements MustVerifyEmail
|
||||||
}
|
}
|
||||||
$this->forceDelete();
|
$this->forceDelete();
|
||||||
throw ValidationException::withMessages([
|
throw ValidationException::withMessages([
|
||||||
'error' => trans('Le compte \'existe pas.')
|
'error' => trans('Le compte n\'existe pas.')
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -239,7 +241,7 @@ class Customer extends Authenticatable implements MustVerifyEmail
|
||||||
get: fn (): CrmCustomer => self::cacheCrm($this->hashcode, "apiData", function () {
|
get: fn (): CrmCustomer => self::cacheCrm($this->hashcode, "apiData", function () {
|
||||||
/** @var \LDC\LDCCRM\CrmApiV4 */
|
/** @var \LDC\LDCCRM\CrmApiV4 */
|
||||||
$crm = app('crmAPI');
|
$crm = app('crmAPI');
|
||||||
$crmCustomer = $crm->getCustomer($this->hashcode);
|
$crmCustomer = $crm->getCustomer(\strval($this->hashcode));
|
||||||
if (!$crmCustomer) {
|
if (!$crmCustomer) {
|
||||||
throw new CrmException('CRM get Customer returned null');
|
throw new CrmException('CRM get Customer returned null');
|
||||||
}
|
}
|
||||||
|
|
@ -263,6 +265,7 @@ class Customer extends Authenticatable implements MustVerifyEmail
|
||||||
// phpcs:enable
|
// phpcs:enable
|
||||||
/** @var \LDC\LDCCRM\Models\Customer */
|
/** @var \LDC\LDCCRM\Models\Customer */
|
||||||
$crmCustomer = $this->api_data;
|
$crmCustomer = $this->api_data;
|
||||||
|
|
||||||
if (!$crmCustomer) {
|
if (!$crmCustomer) {
|
||||||
throw new CrmException('CRM get Customer returned null');
|
throw new CrmException('CRM get Customer returned null');
|
||||||
}
|
}
|
||||||
|
|
@ -337,17 +340,17 @@ class Customer extends Authenticatable implements MustVerifyEmail
|
||||||
parent::toArray(),
|
parent::toArray(),
|
||||||
(array)$this->apiData
|
(array)$this->apiData
|
||||||
))->intersectByKeys([
|
))->intersectByKeys([
|
||||||
'email' => '',
|
'email' => '',
|
||||||
'firstname' => '',
|
'firstname' => '',
|
||||||
'lastname' => '',
|
'lastname' => '',
|
||||||
'address' => '',
|
'address' => '',
|
||||||
'address2' => '',
|
'address2' => '',
|
||||||
'postcode' => '',
|
'postcode' => '',
|
||||||
'birth_date' => '',
|
'birth_date' => '',
|
||||||
'city' => '',
|
'city' => '',
|
||||||
'country' => '',
|
'country' => '',
|
||||||
'opt_in' => '',
|
'opt_in' => '',
|
||||||
'phone' => ''
|
'phone' => ''
|
||||||
])->toArray();
|
])->toArray();
|
||||||
} else {
|
} else {
|
||||||
return parent::toArray();
|
return parent::toArray();
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue