Advertisement
Guest User

Untitled

a guest
May 25th, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.07 KB | None | 0 0
  1. <?php
  2. // use \Kernel\Auth; si pas présent
  3. public function index()
  4. {
  5.   if(!empty($_GET['id']) && !empty(Auth::getInstance()->getUserById(htmlspecialchars(trim($_GET['id'])))))
  6.   {
  7.     $id = htmlspecialchars(trim($_GET['id']));
  8.     $articles = $this->model->getArticleFromAuthor($id);
  9.     $user = Auth::getInstance()->getUserById(htmlspecialchars(trim($_SESSION['userID']))); // <=
  10.  
  11.     if(isset($_POST['submit']) && ($_SESSION['userID'] == $id || $user['admin'] == 1)) // <=
  12.     {
  13.       if(
  14.           !empty($_POST['firstname'])
  15.           && !empty($_POST['lastname'])
  16.           && !empty($_POST['username'])
  17.           && !empty($_POST['email'])
  18.         )
  19.         {
  20.           $firstname = htmlspecialchars($_POST['firstname']);
  21.           $lastname= htmlspecialchars($_POST['lastname']);
  22.           $username = htmlspecialchars($_POST['username']);
  23.           $email = htmlspecialchars($_POST['email']);
  24.           if(empty($_POST['currentPassword']) && empty($_POST['newPassword']) && empty($_POST['confirmPassword']))
  25.           {
  26.             $this->model->updateProfile($firstname, $lastname, $username, $email);
  27.           }
  28.           else
  29.           {
  30.             if(!empty($_POST['currentPassword']) && !empty($_POST['newPassword']) && !empty($_POST['confirmPassword']))
  31.             {
  32.               $currentPassword = htmlspecialchars($_POST['currentPassword']);
  33.               $newPassword= htmlspecialchars($_POST['newPassword']);
  34.               $confirmPassword = htmlspecialchars($_POST['confirmPassword']);
  35.               $user = Auth::getInstance()->getUserById(htmlspecialchars(trim($_SESSION['userID'])), true);
  36.  
  37.                 if(password_verify($currentPassword, $user['password']))
  38.                 {
  39.                   if($newPassword == $confirmPassword)
  40.                   {
  41.                     $newPassword = password_hash($newPassword, PASSWORD_BCRYPT, ['cost' => 12]);
  42.                     $this->model->updateProfile($firstname, $lastname, $username, $email, $newPassword);
  43.                     if($user['admin'] == 1) // <=
  44.                     { // <=
  45.                         header('Location: x'); // <=
  46.                     } // <=
  47.                   }
  48.                 }else
  49.                 {
  50.                     $error = 'Mot de passe incorrect';
  51.                 }
  52.             }else
  53.             {
  54.               $error = 'Veuillez remplir tous les champs du changement de votre mot de passe';
  55.             }
  56.           }
  57.         }else
  58.         {
  59.             $error = 'Vous devez au minimum remplir tous les champs excepté le mot de passe';
  60.         }
  61.  
  62.         if(empty($error))
  63.         {
  64.           $this->render('index',['user' => Auth::getInstance()->getUserById($id), 'articles' => $articles, 'success' => true]);
  65.         }else
  66.         {
  67.           $this->render('index',['user' => Auth::getInstance()->getUserById($id), 'articles' => $articles, 'error' => $error]);
  68.         }
  69.     }else
  70.     {
  71.       $this->render('index',['user' => Auth::getInstance()->getUserById($id), 'articles' => $articles]);
  72.     }
  73.   }else
  74.   {
  75.     header('Location:dashboard');
  76.   }
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement