/** * Writes $contents to storage * * @param mixed $contents * @throws Zend_Auth_Storage_Exception If writing $contents to * storage is impossible * @return void */ public function write($contents) { if (isset($contents['password_hash'])) { unset($contents['password_hash']); } $value = json_encode($contents); $this->app->setCookie($this->cookieName, $value, $this->time); }
}; $app->post('/login', function () use($app) { try { // get user and pass from post if from form as dataType=html //$username = $app->request->post('username'); //$password = $app->request->post('password'); // get user and pass from post - get and decode JSON request body $body = $app->request()->getBody(); $input = json_decode($body); $username = (string) $input->username; $password = (string) $input->password; // this is how you can check what has been passed. Look into responds from ajaxPost.php //var_dump($password); if (isValidLogin($username, $password)) { // if username and pass are valid set Cookie $app->setCookie('username', $username, '1 day'); $app->setCookie('password', $password, '1 day'); $app->response()->header('Content-Type', 'application/json'); $app->response()->status(200); // OK echo json_encode(array('operation' => 'login', 'status' => 'ok')); } else { throw new AuthenticateFailedException(); } } catch (AuthenticateFailedException $e) { $app->response()->status(401); $app->response()->header('X-Status-Reason', 'Login failure'); } catch (Exception $e) { $app->response()->status(400); $app->response()->header('X-Status-Reason', $e->getMessage()); }
**/ $app->get('/', function () use($app, $dl) { $app->render('home.twig', array('code' => $app->getCookie('code'), 'email' => $app->getCookie('email'), 'album' => $app->getCookie('album'), 'subscribe' => $app->getCookie('subscribe'), 'albums' => $dl->get_albums())); })->name('home'); /** * HOME ROUTE POST HANDELING **/ $app->post('/', function () use($app, $dl, $mail) { // setup variables from the incoming post $album = $app->request->post('album'); $email = $app->request->post('email'); $code = strtoupper($app->request->post('code')); $subscribe = $app->request->post('mailing_list'); $address = $app->request->post('address'); // Set current entries to cookies $app->setCookie('code', $code); $app->setCookie('email', $email); $app->setCookie('album', $album); $app->setCookie('subscribe', $subscribe); // Make sure the Honey Pot field is empty. if (!empty($address)) { $app->flash('error', 'Your form submission has an error.'); // Push them back to the main screen with generic error message $app->redirect($app->urlFor('home')); } elseif (!empty($code) && !empty($email)) { // Clean up the form submissions $cleanCode = filter_var($code, FILTER_SANITIZE_STRING); $cleanEmail = filter_var($email, FILTER_SANITIZE_EMAIL); $cleanAlbum = filter_var($album, FILTER_SANITIZE_STRING); // validate the email format $validEmail = filter_var($cleanEmail, FILTER_VALIDATE_EMAIL);