return $app->render('login.php', array('error' => "Bad password", 'login' => $userName)); } $_SESSION['id'] = $user->getUserId(); $_SESSION['userName'] = $user->getUserName(); $_SESSION['is_connected'] = true; }); // Matches if the HTTP method is POST -> /register $app->post('/register', function (Request $request) use($app, $userMapper) { $userName = $request->getParameter('userName'); $userPassword = $request->getParameter('userPassword'); if (!isset($userName) || !isset($userPassword)) { $response = new Response("Invalid parameters", 400); $response->send(); return $app->render('register.php', array('error' => "Invalid parameters", 'login' => $userName)); } $userMapper->persist(new User(null, $userName, password_hash($userPassword, PASSWORD_DEFAULT))); $app->redirect('/login', 201); }); // Matches if the HTTP method is PUT -> / $app->put('/', function () use($app) { return $app->render('index.php'); }); // Matches if the HTTP method is DELETE -> /statuses/id $app->delete('/statuses/(\\d+)', function (Request $request, $id) use($app, $statusFinder, $statusMapper) { if (null == $statusFinder->findOneById($id)) { throw new HttpException(404, 'Not Found'); } $statusMapper->remove($id); $app->redirect('/statuses'); }); return $app;
public function createSubmit() { if (isset($_REQUEST['n_aid']) || !isset($_REQUEST['name'])) { $this->redirect('/apps/apps'); } $this->printHeader = false; $this->printFooter = false; $name = $_POST['name']; $storeUrl = $_POST['storeUrl']; $platform = $_POST['platform']; $fgColor = $_POST['fgColor']; $bgColor = $_POST['bgColor']; $cycleTime = $_POST['cycleTime']; $transition = $_POST['transition']; $locationOn = $_POST['locationOn']; $app = new App(); $app->id = SDB::uuid(); $app->uid = $this->user->id; $app->name = $name; $app->storeUrl = $storeUrl; $app->platform = $platform; $app->fgColor = $fgColor; $app->bgColor = $bgColor; $app->cycleTime = $cycleTime; $app->transition = $transition; $app->locationOn = $locationOn; $app->adsOn = 1; $app->put(); $_POST['aid'] = $app->id; // before finishing, check to see if the new app has been added to th SDB $sdb = SDB::getInstance(); // sleeps for half a second until we see an entry for this id $fields = "name"; while (!$sdb->get($app->getSDBDomain(), $app->id, $fields)) { $fields = "name"; // necessary since get overwrites $fields usleep(500); } }