Merge branch 'develop' into v2
This commit is contained in:
commit
4f4575cb49
6 changed files with 57 additions and 2 deletions
|
|
@ -334,6 +334,11 @@ class CustomerController extends Controller
|
|||
if ($customer) {
|
||||
$customerLogin = $customer->logins()->where('brand_id', $brandId)->first();
|
||||
if ($customerLogin) {
|
||||
// Check if same password
|
||||
if (Hash::check($password, $customerLogin->password)){
|
||||
return new StatusResource(['status' => 'KO', 'code' => 123, 'message' => 'Same password.']);
|
||||
}
|
||||
|
||||
$customerLogin->password = Hash::make($password);
|
||||
$customerLogin->save();
|
||||
} else {
|
||||
|
|
@ -448,8 +453,40 @@ class CustomerController extends Controller
|
|||
}
|
||||
}
|
||||
|
||||
public function addSingleOptin(Request $request)
|
||||
{
|
||||
/**
|
||||
* Remove opt-in for the customer on this brand
|
||||
* @param Request $request
|
||||
* @param $hashcode
|
||||
*/
|
||||
public function removeOptin(Request $request, $hashcode) {
|
||||
// TODO : Liaison des opt-in avec MailJet
|
||||
$brandId = $request->brand_id;
|
||||
|
||||
$infos = CustomerInfos::where([
|
||||
['brand_id', $brandId],
|
||||
['hashcode', $hashcode]
|
||||
])->first();
|
||||
|
||||
if ($infos) {
|
||||
$infos->opt_in = 0;
|
||||
|
||||
// On enregistre l'historique du changement d'optin
|
||||
$optinHistory = new CustomerOptInHistory();
|
||||
$optinHistory->customer_id = $infos->customer_id;
|
||||
$optinHistory->new_value = 0;
|
||||
$optinHistory->brand_id = $brandId;
|
||||
$optinHistory->save();
|
||||
|
||||
$infos->save();
|
||||
// "Changement effectué"
|
||||
return new StatusResource(['status' => 'OK', 'message' => 'Update complete.']);
|
||||
} else {
|
||||
// "Ce compte n'a pas d'information liés à cette marque"
|
||||
return new StatusResource(['status' => 'KO', 'code' => 122, 'message' => 'User not found.']);
|
||||
}
|
||||
}
|
||||
|
||||
public function addSingleOptin(Request $request) {
|
||||
$validator = Validator::make($request->all(), [
|
||||
'email' => 'required|email',
|
||||
]);
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@ class CustomerResource extends JsonResource
|
|||
'crm_id' => $this->id,
|
||||
'firstname' => $infos->firstname,
|
||||
'lastname' => $infos->lastname,
|
||||
'email' => $this->email,
|
||||
'birth_date' => $infos->birth_date,
|
||||
'address' => $infos->address,
|
||||
'address2' => $infos->address2,
|
||||
|
|
|
|||
|
|
@ -48,4 +48,12 @@ class Brand extends Model
|
|||
{
|
||||
return $this->hasMany(SingleOptin::class);
|
||||
}
|
||||
|
||||
public function getAccountsAttribute(){
|
||||
return $this->customer_infos()->count();
|
||||
}
|
||||
|
||||
public function getTotalOptinsAttribute(){
|
||||
return $this->customer_infos()->where('opt_in', 1)->count() + $this->single_optins()->count();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -92,6 +92,10 @@ class ApiV1
|
|||
return $this->callAPI('POST', "/customer/$id/toggle-optin");
|
||||
}
|
||||
|
||||
public function removeOptInCustomer($hashcode){
|
||||
return $this->callAPI('POST', "/customer/$hashcode/remove-optin");
|
||||
}
|
||||
|
||||
public function loginCustomer($email, $password){
|
||||
return $this->callAPI('POST', "/customer/login", ['email' => $email, 'password' => $password]);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,6 +8,8 @@
|
|||
<table class="table">
|
||||
<thead>
|
||||
<th>Nom de la marque</th>
|
||||
<th>Nombre de comptes</th>
|
||||
<th>Nombre d'optins</th>
|
||||
<th>Date d'ajout en base</th>
|
||||
<th></th>
|
||||
</thead>
|
||||
|
|
@ -15,6 +17,8 @@
|
|||
@foreach ($brands as $brand)
|
||||
<tr>
|
||||
<td>{{ $brand->name }}</td>
|
||||
<td>{{ $brand->accounts }}</td>
|
||||
<td>{{ $brand->total_optins }}</td>
|
||||
<td>{{ \Carbon\Carbon::parse($brand->created_at)->format('d/m/Y à H:i') }}</td>
|
||||
<td><a href="{{ route('manage-brand', $brand->id) }}" class="btn btn-sm btn-success">Modifier</a></td>
|
||||
</tr>
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ Route::prefix('v1')->middleware(['auth:api', 'check-brand'])->group(function ()
|
|||
Route::post('/{id}/change-password', [CustomerController::class, 'changePassword']);
|
||||
Route::post('/{id}/activate', [CustomerController::class, 'activateAccount']);
|
||||
Route::post('/{id}/toggle-optin', [CustomerController::class, 'toggleOptin']);
|
||||
Route::post('/{hashcode}/remove-optin', [CustomerController::class, 'removeOptin']);
|
||||
Route::post('/login', [CustomerController::class, 'authenticate']);
|
||||
});
|
||||
// Optin simple
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue