function edit() { if (Auth::guest()) { $this->app->flash('info', 'You must be logged in to edit your profile.'); $this->app->redirect('/login'); return; } $user = Auth::user(); if (!$user) { throw new \Exception("Unable to fetch logged in user's object from db."); } if ($this->app->request->isPost()) { $request = $this->app->request; $email = $request->post('email'); $bio = $request->post('bio'); $age = $request->post('age'); $user->setEmail($email); $user->setBio($bio); $user->setAge($age); if (!User::validateAge($user)) { $this->app->flashNow('error', 'Age must be between 0 and 150.'); } else { $user->save(); $this->app->flashNow('info', 'Your profile was successfully saved.'); } } $this->render('edituser.twig', ['user' => $user]); }
function render($template, $variables = []) { if (!Auth::guest()) { $variables['isLoggedIn'] = true; $variables['isAdmin'] = Auth::isAdmin(); $variables['loggedInUsername'] = $_SESSION['user']; } print $this->app->render($template, $variables); }
function index() { if (Auth::guest()) { $this->app->flash('info', "You must be logged in to view the admin page."); $this->app->redirect('/'); } if (!Auth::isAdmin()) { $this->app->flash('info', "You must be administrator to view the admin page."); $this->app->redirect('/'); } $variables = ['users' => User::all()]; $this->render('admin.twig', $variables); }