Advertisement
Guest User

Untitled

a guest
Dec 13th, 2019
242
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.23 KB | None | 0 0
  1. function updateProfil($id, $username = false, $pass = false, $pic, $mail, $rang, $Avertissement, $Ammende, $vacance, $paye){
  2. global $PATH;
  3. require $PATH.'../../config/config.php';
  4. require $PATH.'../../config/database.php';
  5.  
  6. $id = intval($id);
  7.  
  8. $userExist = $this->userUpdateExist($id);
  9.  
  10. if(is_array($pic)){
  11. $imageId = $this->registerImage($pic);
  12. }else {
  13. $imageId = $pic;
  14. }
  15.  
  16. if($userExist == 0){
  17. if($pass == false) {
  18. $sth = $bdd->prepare('UPDATE `' . $config['bdd']['name'] . '`.`' . $config['bdd']['tables']['users'] . '` SET `mail`= :mail, `imageId`= :imageId WHERE `id`=:id ;');
  19. }else {
  20. $options = [
  21. 'cost' => 10,
  22. 'salt' => mcrypt_create_iv(22, MCRYPT_DEV_URANDOM),
  23. ];
  24.  
  25. $pass = password_hash($pass, PASSWORD_BCRYPT, $options);
  26.  
  27. $sth = $bdd->prepare('UPDATE `' . $config['bdd']['name'] . '`.`' . $config['bdd']['tables']['users'] . '` SET `pass`=:pass, `mail`= :mail, `imageId`= :imageId WHERE `id`=:id ;');
  28.  
  29. $sth->bindValue(':pass', $pass);
  30. }
  31. $sth->bindValue(':imageId', $imageId, PDO::PARAM_INT);
  32. $sth->bindValue(':id', $id, PDO::PARAM_INT);
  33. $sth->bindValue(':mail', $mail, PDO::PARAM_STR);
  34.  
  35. if ($sth->execute()){
  36.  
  37. $sth->closeCursor();
  38.  
  39. $sth = $bdd->prepare('SELECT * FROM `' . $config['bdd']['name'] . '`.`' . $config['bdd']['tables']['users'] . '` WHERE `id`=:id');
  40. $sth->bindValue(':id', $id);
  41. $sth->execute();
  42.  
  43. $data = $sth->fetch();
  44.  
  45. if($id == $this->getUserId()) {
  46.  
  47. $_SESSION['username'] = $data['username'];
  48. $_SESSION['mail'] = $data['mail'];
  49. $_SESSION['rang'] = $data['rang'];
  50. }
  51.  
  52. return 0;
  53. }else {
  54. return 2; //Erreur base de donnée
  55. }
  56.  
  57. }else {
  58. return 1; //Cet utilisateur n'existe pas
  59. }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement