public function register() { if (isset($_POST['username'], $_POST['password'])) { try { htmlspecialchars($user = $_POST['username']); htmlspecialchars($pass = $_POST['password']); if (!empty($user) && !empty($pass)) { if (User::isRegistered($user)) { throw new \Exception('Username already exists'); } else { if (User::tryReg($user, $pass)) { $_SESSION['id'] = User::getUser($user)[0]; for ($i = 0; $i < 2; $i++) { Map::assignMap(); } session_destroy(); header("Location: /MVCProject/home/home"); exit; } else { throw new \Exception('Error occured during registration'); } } } else { throw new \Exception('All fields required'); } } catch (Exception $e) { echo $e->getMessage(); } } $model = new UserRegisterViewModel(); return new View($model); }
public static function map() { $map = Map::getMap()->fetch_all(); View::$data['map'] = $map; $model = null; return new View($model); }