From 37f0f717d4b1d86db5519e8bf19d9a0bf057424d Mon Sep 17 00:00:00 2001 From: Christophe LATOUR Date: Tue, 16 Jan 2018 15:42:18 +0100 Subject: [PATCH] #15435 - Saving user version on singup --- app/Models/User.php | 21 +++++++++++++++++++++ app/Web/Controllers/AuthController.php | 8 ++++++++ config/api.local.php | 1 + config/api.pprod.php | 1 + config/api.prod.php | 1 + 5 files changed, 32 insertions(+) diff --git a/app/Models/User.php b/app/Models/User.php index f5685ba..36be642 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -30,6 +30,27 @@ class User extends BaseCustomer implements WsseUser return $model; } + /** + * Save customer version in DB + * + * @param string $version + * + * @return boolean Whether operation succeed + */ + public function saveVersion($version = null) { + if ($version === null) { + $version = config('api.defaultVersion'); + } + return \Db::getInstance()->ExecuteS(' + INSERT INTO `'._DB_PREFIX_.'customer_version` + VALUES ( + '.(int) $this->id.', + "'.pSQL(!isset($version) ? 'fr': $version).'", + NOW() + ) + '); + } + /** * @see Antadis\Auth\Wsse\Contracts\WsseUser::getWssePassword() */ diff --git a/app/Web/Controllers/AuthController.php b/app/Web/Controllers/AuthController.php index 514fb26..ed89f51 100644 --- a/app/Web/Controllers/AuthController.php +++ b/app/Web/Controllers/AuthController.php @@ -7,6 +7,7 @@ use Antadis\API\Front\Web\Controllers\AuthController as BaseAuthController; use Antadis\API\Front\Exceptions\HttpBadRequestException; use Illuminate\Http\Request; +use ApiValidate; use ApiCart; class AuthController extends BaseAuthController @@ -45,10 +46,17 @@ class AuthController extends BaseAuthController /** * {@inheritdoc} + * + * @Override #15435 - Saving user version */ public function signup(Request $request) { $user = parent::signup($request); + + if (ApiValidate::isLoadedObject($user)) { + $user->saveVersion(); + } + return $user; } diff --git a/config/api.local.php b/config/api.local.php index f636911..108eaed 100644 --- a/config/api.local.php +++ b/config/api.local.php @@ -18,4 +18,5 @@ return array( ], ], 'id_cms_ant_support' => array(14), + 'defaultVersion' => 'fr', ); \ No newline at end of file diff --git a/config/api.pprod.php b/config/api.pprod.php index f636911..108eaed 100644 --- a/config/api.pprod.php +++ b/config/api.pprod.php @@ -18,4 +18,5 @@ return array( ], ], 'id_cms_ant_support' => array(14), + 'defaultVersion' => 'fr', ); \ No newline at end of file diff --git a/config/api.prod.php b/config/api.prod.php index f636911..108eaed 100644 --- a/config/api.prod.php +++ b/config/api.prod.php @@ -18,4 +18,5 @@ return array( ], ], 'id_cms_ant_support' => array(14), + 'defaultVersion' => 'fr', ); \ No newline at end of file