Change customer status to boolean

This commit is contained in:
Jérémy Munsch 2021-10-26 12:01:40 +02:00
parent 7223ebfd85
commit fd80875410
No known key found for this signature in database
GPG key ID: 55196BEE445F6049
3 changed files with 14 additions and 8 deletions

View file

@ -103,8 +103,6 @@ class CustomerController extends Controller
$customerLogin->last_connection = now();
$customerLogin->brand_id = $brandId;
$customerLogin->status = 0;
// Par défaut à 0 pour activation par mail
//$customerLogin->status = $request->status !== null ? 1 : 0;
$customer->logins()->save($customerLogin);
@ -295,7 +293,7 @@ class CustomerController extends Controller
$login = $customer->logins()->where('brand_id', $brandId)->first();
if ($login) {
if (Hash::check($password, $login->password)) {
if ($login->status === 0) {
if ($login->status === false) {
$infos = $customer->infos()->where('brand_id', $brandId)->first();
// "Le compte de l'utilisateur n'est pas activé"
return new StatusResource(
@ -397,8 +395,8 @@ class CustomerController extends Controller
if ($customer) {
$login = $customer->logins()->where('brand_id', $brandId)->first();
if ($login) {
if ($login->status === 0) {
$login->status = 1;
if ($login->status === false) {
$login->status = true;
$login->save();
// "Le compte a bien été activé"
return new StatusResource(['status' => 'OK', 'message' => 'Update complete.']);

View file

@ -180,7 +180,7 @@ class CustomerController extends Controller
throw new ApiErrorException(ApiError::authFailed());
}
if ($customerLogin->status === 0) {
if (!$customerLogin->status) {
throw new ApiErrorException(ApiError::customerNotActivated());
}
@ -201,8 +201,8 @@ class CustomerController extends Controller
$this->authorize('customerBelongsToService', $customer);
$login = $customer->login($service->brand, Customer::FIRST_OR_FAIL);
if ($login->status === 0) {
$login->status = 1;
if (!$login->status) {
$login->status = true;
$login->save();
return response()->json();
} else {

View file

@ -10,10 +10,18 @@ class CustomerLogin extends Model
{
use HasFactory;
protected $attributes = [
'status' => false
];
protected $fillable = [
'password'
];
protected $casts = [
'status' => 'bool'
];
protected static function booted()
{
static::creating(function ($customerLogin) {