PUT api.module.admin (added setMail + used setPassword)
This commit is contained in:
parent
97b7515264
commit
9f5279fb79
|
@ -68,4 +68,50 @@
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* (3) Updates an existing new administrator
|
||||||
|
*
|
||||||
|
* @id_admin<id> UID de l'administrateur
|
||||||
|
* @mail<string> [OPT] Adresse mail de l'administrateur
|
||||||
|
* @password<string> [OPT] Mot de passe de l'administrateur
|
||||||
|
*
|
||||||
|
* @return admin<array> The new administrator data
|
||||||
|
*
|
||||||
|
---------------------------------------------------------*/
|
||||||
|
public static function put($args){
|
||||||
|
extract($args);
|
||||||
|
debug();
|
||||||
|
|
||||||
|
/* (1) If @mail given
|
||||||
|
---------------------------------------------------------*/
|
||||||
|
if( !is_null($mail) ){
|
||||||
|
|
||||||
|
/* (1) Update mail address */
|
||||||
|
$updated = Repo::request('admin', 'setMail', $id_admin, $mail);
|
||||||
|
|
||||||
|
/* (2) Gestion erreur */
|
||||||
|
if( $updated === false )
|
||||||
|
return [ 'error' => new Error(Err::RepoError) ];
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (2) If @password given
|
||||||
|
---------------------------------------------------------*/
|
||||||
|
if( !is_null($password) ){
|
||||||
|
|
||||||
|
/* (1) Update password */
|
||||||
|
$updated = Repo::request('admin', 'setPassword', $id_admin, $password);
|
||||||
|
|
||||||
|
/* (2) Gestion erreur */
|
||||||
|
if( $updated === false )
|
||||||
|
return [ 'error' => new Error(Err::RepoError) ];
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (3) Renvoi @id_admin */
|
||||||
|
return [ 'id_admin' => Repo::request('admin', 'getById', $id_admin) ];
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -181,7 +181,40 @@
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (7) Creates a new admin
|
|
||||||
|
/* (7) Set the mail address for a admin
|
||||||
|
*
|
||||||
|
* @id_admin<String> The admin UID
|
||||||
|
* @mail<String> The mail address to set
|
||||||
|
*
|
||||||
|
* @return set<bool> Whether the mail address has been set or not
|
||||||
|
*
|
||||||
|
---------------------------------------------------------*/
|
||||||
|
public function setMail(int $id_admin, String $mail){
|
||||||
|
|
||||||
|
/* (1) Check @mail is unique
|
||||||
|
---------------------------------------------------------*/
|
||||||
|
/* (1) If @mail already exists -> abort */
|
||||||
|
if( is_array($this->getByMail($mail)) )
|
||||||
|
return false;
|
||||||
|
|
||||||
|
|
||||||
|
/* (2) Update mail address
|
||||||
|
---------------------------------------------------------*/
|
||||||
|
/* (1) Prepare Statement */
|
||||||
|
$pst = $this->pdo->prepare("UPDATE `admin` SET `mail` = :mail WHERE `id_admin` = :id_admin");
|
||||||
|
|
||||||
|
/* (3) Bind variables */
|
||||||
|
$pst->bindParam(':mail', $mail, \PDO::PARAM_STR, 50);
|
||||||
|
$pst->bindParam(':id_admin', $id_admin, \PDO::PARAM_INT);
|
||||||
|
|
||||||
|
/* (4) Execute -> dispatch status */
|
||||||
|
return $pst->execute();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* (8) Creates a new admin
|
||||||
*
|
*
|
||||||
* @username<String> The username (must be unique)
|
* @username<String> The username (must be unique)
|
||||||
* @mail<String> The mail address (must be unique)
|
* @mail<String> The mail address (must be unique)
|
||||||
|
|
|
@ -13,18 +13,21 @@
|
||||||
},
|
},
|
||||||
|
|
||||||
"PUT": {
|
"PUT": {
|
||||||
"description": "Gets an administrator's data",
|
"description": "Updates an existing administrator's data",
|
||||||
"permissions": [],
|
"permissions": [],
|
||||||
"parameters": {
|
"parameters": {
|
||||||
"URL0": { "description": "Some string token", "type": "text", "rename": "id_article" },
|
"URL0": { "description": "The UID of the wanted administrator.", "type": "id", "rename": "id_admin" },
|
||||||
"postdata": { "description": "Some string token", "type": "text" }
|
"mail": { "description": "The new administrator email address", "type": "mail", "optional": true },
|
||||||
|
"password": { "description": "The new administrator passowrd", "type": "text", "optional": true }
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
"DELETE": {
|
"DELETE": {
|
||||||
"description": "Deletes an administrator",
|
"description": "Deletes an administrator",
|
||||||
"permissions": [["admin"]],
|
"permissions": [["admin"]],
|
||||||
"parameters": {}
|
"parameters": {
|
||||||
|
"URL0": { "description": "The UID of the wanted administrator.", "type": "id", "optional": true, "rename": "id_admin" }
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
"GET": {
|
"GET": {
|
||||||
|
|
Loading…
Reference in New Issue