Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function updateProfil($id, $username = false, $pass = false, $pic, $mail, $rang, $Avertissement, $Ammende, $vacance, $paye){
- global $PATH;
- require $PATH.'../../config/config.php';
- require $PATH.'../../config/database.php';
- $id = intval($id);
- $userExist = $this->userUpdateExist($id);
- if(is_array($pic)){
- $imageId = $this->registerImage($pic);
- }else {
- $imageId = $pic;
- }
- if($userExist == 0){
- if($pass == false) {
- $sth = $bdd->prepare('UPDATE `' . $config['bdd']['name'] . '`.`' . $config['bdd']['tables']['users'] . '` SET `mail`= :mail, `imageId`= :imageId WHERE `id`=:id ;');
- }else {
- $options = [
- 'cost' => 10,
- 'salt' => mcrypt_create_iv(22, MCRYPT_DEV_URANDOM),
- ];
- $pass = password_hash($pass, PASSWORD_BCRYPT, $options);
- $sth = $bdd->prepare('UPDATE `' . $config['bdd']['name'] . '`.`' . $config['bdd']['tables']['users'] . '` SET `pass`=:pass, `mail`= :mail, `imageId`= :imageId WHERE `id`=:id ;');
- $sth->bindValue(':pass', $pass);
- }
- $sth->bindValue(':imageId', $imageId, PDO::PARAM_INT);
- $sth->bindValue(':id', $id, PDO::PARAM_INT);
- $sth->bindValue(':mail', $mail, PDO::PARAM_STR);
- if ($sth->execute()){
- $sth->closeCursor();
- $sth = $bdd->prepare('SELECT * FROM `' . $config['bdd']['name'] . '`.`' . $config['bdd']['tables']['users'] . '` WHERE `id`=:id');
- $sth->bindValue(':id', $id);
- $sth->execute();
- $data = $sth->fetch();
- if($id == $this->getUserId()) {
- $_SESSION['username'] = $data['username'];
- $_SESSION['mail'] = $data['mail'];
- $_SESSION['rang'] = $data['rang'];
- }
- return 0;
- }else {
- return 2; //Erreur base de donnée
- }
- }else {
- return 1; //Cet utilisateur n'existe pas
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement