From 49fad95ad882b72ce591c2eed9d16467cd7897f0 Mon Sep 17 00:00:00 2001 From: xdrm-brackets Date: Mon, 20 Feb 2017 11:59:44 +0100 Subject: [PATCH] =?UTF-8?q?[Fixed]=20Auto-input=20pour=20code=20de=20view:?= =?UTF-8?q?users/edit[Done]=20Managed=20anti-duplication=20username|code?= =?UTF-8?q?=20pour=20`userDefault/create`=20et=20`userDefault/edit`=20(int?= =?UTF-8?q?erne=20=C3=A0=20warehouse)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build/api/module/userDefault.php | 41 ++++++++++++++++++++++++++++++-- build/error/core/Err.php | 3 +++ build/error/core/Error.php | 24 ++++++++++++------- public_html/view/js/users.js | 10 ++++++++ 4 files changed, 67 insertions(+), 11 deletions(-) diff --git a/build/api/module/userDefault.php b/build/api/module/userDefault.php index 7ba5706..8b42ed8 100755 --- a/build/api/module/userDefault.php +++ b/build/api/module/userDefault.php @@ -4,6 +4,7 @@ use \database\core\DatabaseDriver; use \manager\sessionManager; use \error\core\Error; + use \error\core\Err; use \database\core\Repo; class userDefault{ @@ -25,6 +26,26 @@ public function create($params){ extract($params); + + /* [1] Vérification unicitié (dans warehouse) + =========================================================*/ + /* (1) Vérification username */ + $byUsername_r = new Repo('user/getByUsername', [$_SESSION['WAREHOUSE']['id'], $username]); + $byUsername = $byUsername_r->answer(); + + /* (2) Si existe déja -> erreur */ + if( $byUsername != false ) + return ['error' => new Error(Err::AlreadyExists, 'username')]; + + /* (3) Vérification username */ + $byCode_r = new Repo('user/getByCode', [$_SESSION['WAREHOUSE']['id'], $code]); + $byCode = $byCode_r->answer(); + + /* (4) Si existe déja -> erreur */ + if( $byCode != false ) + return ['error' => new Error(Err::AlreadyExists, 'code')]; + + /* [1] Creation de l'utilisateur =========================================================*/ $create_user = new Repo('user/create', [ @@ -39,7 +60,7 @@ // Si une erreur est retournee, on retourne une erreur if( $id_user === false ) - return ['error' => new Error(Err::error)]; + return ['error' => new Error(Err::RepoError)]; /* [2] Gestion du retour @@ -222,7 +243,7 @@ $_SESSION['WAREHOUSE']['id'], $username ]); - $answer = $request->answer(); + $answer = $request->answer(); // Si aucun resultat, on retourne une erreur if( $answer === false ) @@ -293,7 +314,23 @@ if( !is_array($user_data) ) return ['error' => new Error(Err::NoMatchFound)]; + /* [2] Vérification de l'unicité + =========================================================*/ + /* (1) Vérification username */ + $byUsername_r = new Repo('user/getByUsername', [$_SESSION['WAREHOUSE']['id'], $username]); + $byUsername = $byUsername_r->answer(); + /* (2) Si existe déja */ + if( $byUsername != false && $byUsername['id_user'] != $id_user ) + return ['error' => new Error(Err::AlreadyExists, 'username')]; + + /* (3) Vérification username */ + $byCode_r = new Repo('user/getByCode', [$_SESSION['WAREHOUSE']['id'], $code]); + $byCode = $byCode_r->answer(); + + /* (4) Si existe déja */ + if( $byCode != false && $byCode['id_user'] != $id_user ) + return ['error' => new Error(Err::AlreadyExists, 'code')]; /* [2] Normalisation + verification des donnees =========================================================*/ diff --git a/build/error/core/Err.php b/build/error/core/Err.php index bd7a56c..449733e 100644 --- a/build/error/core/Err.php +++ b/build/error/core/Err.php @@ -104,6 +104,9 @@ /* (4) Erreur inconnue */ const UnknownError = 28; + + /* (5) Entrée existante */ + const AlreadyExists = 29; } ?> diff --git a/build/error/core/Error.php b/build/error/core/Error.php index 70f9944..7092ada 100644 --- a/build/error/core/Error.php +++ b/build/error/core/Error.php @@ -74,7 +74,7 @@ case Err::UncallableModule: return $this->UncallableModule(); break; case Err::UncallableMethod: return $this->UncallableMethod(); break; case Err::UnknownHttpMethod: return $this->UnknownHttpMethod(); break; - case Err::ConfigError: return $this->ConfigError(); break; + case Err::ConfigError: return $this->ConfigError(); break; case Err::MissingParam: return $this->MissingParam(); break; case Err::WrongParam: return $this->WrongParam(); break; case Err::ModuleError: return $this->ModuleError(); break; @@ -88,6 +88,7 @@ case Err::UnknownTemplate: return $this->UnknownTemplate(); break; case Err::UnknownAddress: return $this->UnknownAddress(); break; case Err::UnknownError: return $this->UnknownError(); break; + case Err::AlreadyExists: return $this->AlreadyExists(); break; default: return $this->UnknownDebugError(); break; } @@ -98,7 +99,7 @@ return 'all right'; }private function ParsingFailed(){ if( count($this->arguments) > 0 ) - return $this->arguments[0].' parsing failed'; + return "{$this->arguments[0]} parsing failed"; else return 'parsing failed'; }private function UnreachableResource(){ @@ -119,22 +120,22 @@ return 'wrong module\'s path'; }private function UnknownModule(){ if( count($this->arguments) > 0 ) - return 'unknown module \''.$this->arguments[0].'\''; + return "unknown module '{$this->arguments[0]}'"; else return 'unknown module'; }private function UnknownMethod(){ if( count($this->arguments) > 0 ) - return 'unknown method \''.$this->arguments[0].'\''; + return "unknown method '{$this->arguments[0]}'"; else return 'unknown method'; }private function UncallableModule(){ if( count($this->arguments) > 0 ) - return 'uncallable module \''.$this->arguments[0].'\''; + return "uncallable module '{$this->arguments[0]}'"; else return 'uncallable module'; }private function UncallableMethod(){ if( count($this->arguments) > 0 ) - return 'uncallable method \''.$this->arguments[0].'\''; + return "uncallable method '{$this->arguments[0]}'"; else return 'uncallable method'; }private function UnknownHttpMethod(){ @@ -143,15 +144,15 @@ return 'configuration error'; }private function MissingParam(){ if( count($this->arguments) > 0 ) - return 'missing param \''.$this->arguments[0].'\''; + return "missing param '{$this->arguments[0]}'"; else return 'missing param'; }private function WrongParam(){ if( count($this->arguments) > 0 ) if( count($this->arguments) > 1 ) - return 'wrong param \''.$this->arguments[0].'\' expected to be of type \''.$this->arguments[1].'\''; + return "wrong param '{$this->arguments[0]}' expected to be of type '{$this->arguments[1]}'"; else - return 'wrong param \''.$this->arguments[0].'\''; + return "wrong param '{$this->arguments[0]}'"; else return 'wrong param'; }private function ModuleError(){ @@ -178,6 +179,11 @@ return 'unknown error'; }private function UnknownDebugError(){ return 'unknown debug error'; + }private function AlreadyExists(){ + if( count($this->arguments) > 0 ) + return "'{$this->arguments[0]}' already exists"; + + return 'entry already exists'; } diff --git a/public_html/view/js/users.js b/public_html/view/js/users.js index 099cc33..1f8e30d 100755 --- a/public_html/view/js/users.js +++ b/public_html/view/js/users.js @@ -590,6 +590,16 @@ if( section.edit.element != null ){ submit: document.querySelector(section.edit.text + '#edit_submit') }; + /* (1) Gestion du code RFID */ + createChecker.append( section.edit.input.code, format_code, '01-AB-CD-23'); + section.edit.input.code.addEventListener('keyup', function(e){ + e.target.value = e.target.value.toUpperCase(); + if( !createChecker.check(e.target) ) + createChecker.correct(e.target, false); + + }, false); + + /* (2) Gestion de l'auto-remplissage par lien ---------------------------------------------------------*/