[Fixed] Auto-input pour code de view:users/edit[Done] Managed anti-duplication username|code pour `userDefault/create` et `userDefault/edit` (interne à warehouse)
This commit is contained in:
parent
203f1c9d59
commit
dd2e94d979
|
@ -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
|
||||
|
@ -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
|
||||
=========================================================*/
|
||||
|
|
|
@ -104,6 +104,9 @@
|
|||
|
||||
/* (4) Erreur inconnue */
|
||||
const UnknownError = 28;
|
||||
|
||||
/* (5) Entrée existante */
|
||||
const AlreadyExists = 29;
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
@ -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';
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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
|
||||
---------------------------------------------------------*/
|
||||
|
|
Loading…
Reference in New Issue