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Alw0by4+p9fU
 xGEDlfEtdEWe60xslnp7GCcQJEBNmqTrugXDXP5iK47MFpfsWUkgCZCsYIs3hKLS
 NRoFQC4R+TqWYYfBj5mUdVfLesR+IIT2Uhz41Cn2E4sHUvY8CGfTgAIZDCSdix/T
 Tr2sl/MxfD+voEFpKcNwd9fX5xg3FbQ+Hx8OVtjt/vXEKBXMt5bn8s5K2qxUH/n7
 IyuXi+OE
 =hp06
 -----END PGP SIGNATURE-----

Merge tag '2.2.3' into trunk

2.2.3
This commit is contained in:
Jérémy Munsch 2021-10-26 12:52:31 +02:00
commit fbb0c638e2
14 changed files with 55 additions and 48 deletions

View file

@ -2,7 +2,7 @@ APP_NAME=Laravel
APP_ENV=testing
APP_KEY=base64:UypKzhOMAs2aDu3ovgw/lINvWZQWicbz9nfUXDpDzeQ=
APP_DEBUG=true
APP_URL="http://127.0.0.25:8888"
APP_URL="http://127.0.0.1:8888"
LOG_CHANNEL=stack
LOG_LEVEL=debug

View file

@ -28,7 +28,8 @@ class Handler extends ExceptionHandler
* @var array
*/
protected $dontReport = [
ApiErrorException::class
ApiErrorException::class,
RedirectTo::class
];
/**
@ -51,22 +52,6 @@ class Handler extends ExceptionHandler
//
}
/**
* Report or log an exception.
*
* @param \Throwable $exception
* @return void
*
* @throws \Exception
*/
public function report(Throwable $e)
{
if (get_class($e) == RedirectTo::class) {
abort(redirect($e->url));
}
parent::report($e);
}
/**
* Render an exception into an HTTP response.
*

View file

@ -43,7 +43,7 @@ class CustomerController extends Controller
}
$brandId = $request->brand_id;
$email = filter_var($request->email, FILTER_SANITIZE_EMAIL);
$email = strtolower(filter_var($request->email, FILTER_SANITIZE_EMAIL));
$firstname = filter_var($request->firstname, FILTER_SANITIZE_STRING);
$lastname = filter_var($request->lastname, FILTER_SANITIZE_STRING);
$optIn = filter_var($request->opt_in, FILTER_SANITIZE_STRING);
@ -55,7 +55,7 @@ class CustomerController extends Controller
// Si le customer n'existe pas déjà
if (!$customer) {
$customer = new Customer();
$customer->email = strtolower($email);
$customer->email = $email;
$customer->save();
$singleOptin = SingleOptin::where([['email', $email], ['brand_id', $brandId]])->first();
if ($singleOptin) {
@ -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

@ -9,6 +9,7 @@ use App\Models\Customer;
use App\Models\CustomerInfo;
use App\Models\CustomerLogin;
use App\Models\SingleOptin;
use Exception;
use Illuminate\Database\Query\JoinClause;
use Illuminate\Http\Request;
use Illuminate\Support\Carbon;
@ -179,11 +180,11 @@ class CustomerController extends Controller
$continue = true;
// continue
case CustomerExportType::customer():
$i = 0;
$page = 1;
/** @var \Illuminate\Database\Eloquent\Builder $req */
$req = CustomerInfo::where('brand_id', $request->brand);
$total = $req->count();
$pages = $total / $pagination;
$pages = \ceil($total / $pagination);
do {
/** @var \Illuminate\Pagination\LengthAwarePaginator $items */
$items = $req->with('customer', function ($q) {
@ -192,7 +193,7 @@ class CustomerController extends Controller
$pagination,
['lastname', 'firstname', 'hashcode', 'customer_id'],
'page',
$i
$page
);
$items->map(function (CustomerInfo $customerInfo) use ($w) {
$w->insertOne([
@ -202,7 +203,7 @@ class CustomerController extends Controller
'hashcode' => $customerInfo->hashcode
]);
});
} while ($i++ <= $pages);
} while ($page++ <= $pages);
if (!isset($continue)) {
break;
}
@ -218,6 +219,8 @@ class CustomerController extends Controller
]);
});
break;
default:
throw new Exception(sprintf('Unhandled CustomerExportType %s', $exportType->label));
}
//we create a callable to output the CSV in chunk

View file

@ -2,9 +2,11 @@
namespace App\Http\Requests\Api\V2;
use ArondeParon\RequestSanitizer\Sanitizers\Capitalize;
use ArondeParon\RequestSanitizer\Sanitizers\Lowercase;
use ArondeParon\RequestSanitizer\Sanitizers\RemoveNonNumeric;
use ArondeParon\RequestSanitizer\Sanitizers\Trim;
use ArondeParon\RequestSanitizer\Sanitizers\TrimDuplicateSpaces;
use ArondeParon\RequestSanitizer\Traits\SanitizesInputs;
use Illuminate\Foundation\Http\FormRequest;
@ -13,9 +15,15 @@ abstract class BaseApiRequest extends FormRequest
use SanitizesInputs;
protected $sanitizers = [
'firstname' => [Trim::class, TrimDuplicateSpaces::class, Capitalize::class],
'lastname' => [Trim::class, TrimDuplicateSpaces::class, Capitalize::class],
'address' => [Trim::class, TrimDuplicateSpaces::class],
'address2' => [Trim::class, TrimDuplicateSpaces::class],
'city' => [Trim::class, TrimDuplicateSpaces::class],
'password' => Trim::class,
'phone' => Trim::class,
'email' => [Lowercase::class, Trim::class],
'postcode' => RemoveNonNumeric::class
'postcode' => [RemoveNonNumeric::class, Trim::class]
];
/**

View file

@ -9,13 +9,13 @@ use Illuminate\Http\Resources\Json\JsonResource;
class CustomerResource extends JsonResource
{
/** @var Customer */
/** @var \App\Models\Customer */
private $customer;
/** @var CustomerInfo */
/** @var \App\Models\CustomerInfo */
private $info;
/** @var CustomerLogin */
/** @var \App\Models\CustomerLogin */
private $login;
private static $skeleton = [
@ -75,7 +75,8 @@ class CustomerResource extends JsonResource
$this->getSkeleton()
);
$data['country'] = $this->info->newcountry->value;
$data['country'] = $this->info->newcountry->value;
$data['address2'] = $this->info->address2 ?? '';
return $data;
}

View file

@ -17,6 +17,10 @@ class CustomerInfo extends Model
'newcountry' => Country::class
];
protected $casts = [
'opt_in' => 'bool'
];
protected $fillable = [
'firstname',
'lastname',
@ -44,7 +48,7 @@ class CustomerInfo extends Model
if (ctype_digit($customerInfo->country)) {
try {
$customerInfo->newcountry = Country::make((int)$customerInfo->country);
} catch (\TypeError $e) {
} catch (\BadMethodCallException $e) {
// TODO change this when country column is updated
// Set afghanistan as default country for now
$customerInfo->newcountry = Country::afghanistan();
@ -68,7 +72,7 @@ class CustomerInfo extends Model
if (ctype_digit($customerInfo->country)) {
try {
$customerInfo->newcountry = Country::make((int)$customerInfo->country);
} catch (\TypeError $e) {
} catch (\BadMethodCallException $e) {
// TODO change this when country column is updated
// Set afghanistan as default country for now
$customerInfo->newcountry = Country::afghanistan();

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) {

@ -1 +1 @@
Subproject commit c5249d37a14d125dfa85d49cea495da4efb79490
Subproject commit 390033d3da4b5f9447410656f3d23787557588b5

View file

@ -1,7 +1,7 @@
{
"name": "ldc/ldccrmv2client",
"type": "project",
"version": "2.2.1",
"version": "2.2.3",
"description": "LDC CRM V2",
"authors": [
{
@ -94,8 +94,8 @@
"configclear": "@php artisan config:clear",
"runtestmigration": "@php artisan migrate:fresh --env=testing --seed",
"runtest": "@php artisan test",
"runserve": "@php artisan serve --host=127.0.0.25 --port=8888 --env=testing&",
"killserve": "kill $(ps -f | grep '[1]27.0.0.25:8888' | awk '{print $2}')",
"runserve": "@php artisan serve --host=127.0.0.1 --port=8888 --env=testing&",
"killserve": "kill $(ps -f | grep '[1]27.0.0.1:8888' | awk '{print $2}')",
"post-autoload-dump": [
"Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
"@php artisan package:discover --ansi"

View file

@ -19,7 +19,7 @@
</coverage>
<php>
<server name="APP_ENV" value="testing"/>
<server name="APP_URL" value="http://127.0.0.25:8888"/>
<server name="APP_URL" value="http://127.0.0.1:8888"/>
<server name="BCRYPT_ROUNDS" value="4"/>
<server name="CACHE_DRIVER" value="array"/>
<server name="MAIL_MAILER" value="array"/>

View file

@ -39,7 +39,7 @@ abstract class CrmClientTester extends TestCase
}
config(['crm.token' => self::$service->bearer_token]);
config(['crm.password' => self::$service->bearer_pwd]);
config(['crm.endpoint' => 'http://127.0.0.25:8888']);
config(['crm.endpoint' => 'http://127.0.0.1:8888']);
}
/**

View file

@ -155,13 +155,13 @@ class CrmClientV2CustomerTest extends CrmClientTester
$this->assertTrue($customer->save());
$customer = $api->getCustomerOrNew(static::$info->hashcode);
$this->assertEquals('toto', $customer->firstname);
$this->assertEquals('Toto', $customer->firstname);
$customer->lastname = 'pouet';
$this->assertTrue($customer->save());
$customer = $api->getCustomerOrNew(static::$info->hashcode);
$this->assertEquals('pouet', $customer->lastname);
$this->assertEquals('Pouet', $customer->lastname);
$customer->country = Country::belgium();
$customer->save();
@ -223,7 +223,7 @@ class CrmClientV2CustomerTest extends CrmClientTester
$this->assertTrue($customer->save());
$this->assertEquals('toto', $customer->firstname);
$this->assertEquals('Toto', $customer->firstname);
$this->assertEquals(null, $customer->password);
}