/**
  * This method gets and return user id from the database
  * @param LoginData $userLoginData
  * @return mixed
  */
 public function getUserIdFromDB(LoginData $userLoginData)
 {
     $query = $this->connect->prepare("SELECT `" . self::USER_ID_COL . "` FROM `" . self::TABLE_NAME . "` WHERE `" . self::NICKNAME_COL . "` = ?");
     $query->bind_param('s', $this->escape_string($userLoginData->getNickname()));
     $query->execute();
     $query->bind_result($userID);
     $query->fetch();
     return $userID;
 }
 /**
  * This method performs login functionality
  * @param LoginData $userLoginData
  * @throws CustomException if nickname not found or password does not match or other login error occurred
  */
 public function login(LoginData $userLoginData)
 {
     $userDAO = new UserDAO();
     if ($userDAO->doNicknameExistInDB($userLoginData->getNickname())) {
         if (password_verify($userLoginData->getPassword(), $userDAO->getUserPasswordFromDB($userLoginData->getNickname()))) {
             session_regenerate_id();
             $_SESSION['tastyRecipeUser'] = $userDAO->getUserIdFromDB($userLoginData);
         } else {
             throw new CustomException("Password do not match with username you entered! :( Try again!");
         }
     } else {
         throw new CustomException("We could not find the nickname you entered. :( Make sure you enter right nickname! ");
     }
 }