public function profile() { if (!$this->isLogged()) { header("Location: " . Helpers::url() . 'editor/login'); exit; } $userModel = new Editor(self::DB_INSTANCE); $viewModel = new ProfileInformation(); $userRow = $userModel->getInfo($_SESSION['id']); $user = new EditorViewModel($userRow['username'], $userRow['password'], $userRow['id'], $userRow['email']); $viewModel->setUser($user); if (isset($_POST['edit'])) { try { $bm = new UserEditBindingModel(); if ($_POST['password'] != $_POST['confirm'] || empty($_POST['password'])) { throw new \Exception('Empty password or passwords do not match'); } $acsrf = new \Hyper\Core\Csrf(); if ($acsrf->validateToken()) { $user = new EditorViewModel($bm->getUsername(), $bm->getPassword(), $_SESSION['id'], $bm->getEmail()); if ($userModel->edit($user)) { $viewModel->getUser()->setUsername($user->getUsername()); $viewModel->success = 'Edit successful'; } } else { throw new \Exception('Anti-CSRF token does not match'); } } catch (\Exception $e) { $viewModel->error = $e->getMessage(); return new View($viewModel); } } return new View($viewModel); }
<ul class="nav navbar-nav navbar-right"> <li><a href="<?php echo \Hyper\Helpers\Helpers::url() . 'editor/login'; ?> " class="hvr-underline-reveal"><span class="glyphicon glyphicon-log-in"></span> Login</a></li> </ul> <?php } else { ?> <ul class="nav navbar-nav"> <li><a href="<?php echo \Hyper\Helpers\Helpers::url() . 'editor/profile'; ?> " class="hvr-underline-reveal"><span class="glyphicon glyphicon-user"></span> Profile</a></li> </ul> <ul class="nav navbar-nav navbar-right"> <li><a href="<?php echo \Hyper\Helpers\Helpers::url() . 'editor/logout'; ?> " class="hvr-underline-reveal"><span class="glyphicon glyphicon-log-out"></span> Logout</a></li> </ul> <?php } ?> </ul> </div><!-- /.navbar-collapse --> </div><!-- /.container-fluid --> </nav> </header> <main class="row">
" class="hvr-underline-reveal"><span class="glyphicon glyphicon-log-in"></span> Login</a></li> <li><a href="<?php echo \Hyper\Helpers\Helpers::url() . 'User/register'; ?> " class="hvr-underline-reveal"><span class="glyphicon glyphicon-registration-mark"></span> Register</a></li> </ul> <?php } else { ?> <ul class="nav navbar-nav"> <li><a href="<?php echo \Hyper\Helpers\Helpers::url() . 'User/profile'; ?> " class="hvr-underline-reveal"><span class="glyphicon glyphicon-user"></span> Profile</a></li> </ul> <ul class="nav navbar-nav navbar-right"> <li><a href="<?php echo \Hyper\Helpers\Helpers::url() . 'User/logout'; ?> " class="hvr-underline-reveal"><span class="glyphicon glyphicon-log-out"></span> Logout</a></li> </ul> <?php } ?> </ul> </div><!-- /.navbar-collapse --> </div><!-- /.container-fluid --> </nav> </header> <main class="row">