public function execute($request) { if ($request->getMethod() == coreRequest::POST) { $validator = new coreValidator('formdemo'); $validator->validate($request->getParameterHolder()->getAll()); } }
public function execute($request) { if ($request->getMethod() === coreRequest::POST) { // validate post parameters and save user's review session info $validator = new coreValidator($this->getContext()->getActionName()); $this->forward404Unless($validator->validate($request->getParameterHolder()->getAll())); $this->saveReviewSessionInfo($request->getParameterHolder()); // update review stats for the active members list ActiveMembersPeer::updateFlashcardInfo($this->getUser()->getUserId()); } else { // grab the user's most recent review session info from db $params = ActiveMembersPeer::getReviewSummaryInfo($this->getUser()->getUserId()); $this->forward404Unless($params); $request->getParameterHolder()->add($params); } // template vars $this->ts_start = $request->getParameter('ts_start', 0); $this->numRemembered = (int) $request->getParameter('fc_pass', 0); $this->numForgotten = (int) $request->getParameter('fc_fail', 0); $this->numTotal = $this->numRemembered + $this->numForgotten; if ($this->numRemembered == $this->numTotal) { $this->title = 'Hurrah! All remembered!'; } elseif ($this->numForgotten == $this->numTotal && $this->numTotal > 1) { $this->title = 'Eek! All forgotten!'; } else { $this->title = 'Remembered ' . $this->numRemembered . ' of ' . $this->numTotal . ' kanji.'; } }
/** * Return EditStory component based on GET or POST request. * * PARAMS * framenum Valid kanji id (frame number) * kanjiData Kanji data for kanji id * reviewMode True if called from the Review page * * POST requests to update the story for current user. * * character Current kanji (utf8) * chkPublic Public story * txtStory Story * * * @return * @param object $request */ public function execute($request) { if ($request->getMethod() !== coreRequest::POST) { // get user's story $story = StoriesPeer::getStory($this->getUser()->getUserId(), $this->framenum); if ($story) { $request->getParameterHolder()->add(array('txtStory' => $story->text, 'chkPublic' => $story->public)); } } else { $validator = new coreValidator($this->getActionName()); if ($validator->validate($request->getParameterHolder()->getAll())) { if ($request->hasParameter('doUpdate')) { $txtStory = trim($request->getParameter('txtStory', '')); $txtStory = strip_tags($txtStory); // delete empty story if (empty($txtStory)) { StoriesPeer::deleteStory($this->getUser()->getUserId(), $this->framenum); } else { StoriesPeer::updateStory($this->getUser()->getUserId(), $this->framenum, array('text' => $txtStory, 'public' => $request->hasParameter('chkPublic') ? 1 : 0)); } $request->setParameter('txtStory', $txtStory); } } } // set state $request->setParameter('framenum', $this->framenum); if (!$request->hasParameter('reviewMode')) { $this->isRestudyKanji = ReviewsPeer::isRestudyKanji($this->getUser()->getUserId(), $this->framenum); $this->isRelearnedKanji = LearnedKanjiPeer::hasKanji($this->getUser()->getUserId(), $this->framenum); } $this->formatted_story = StoriesPeer::getFormattedStory($request->getParameter('txtStory', ''), $this->kanjiData->keyword, true); return coreView::SUCCESS; }
public function execute($request) { $this->display_form = true; $this->display_kanji = false; $this->kanji_text = ''; if ($request->getMethod() != coreRequest::POST) { // default text in utf-8 below $default_text = <<<EOD むかし、むかし、ご存知のとおり、うさぎとかめは、山の上まで競争しました。誰もが、うさぎの方がかめよりも早くそこに着くと思いました。しかし迂闊にも、うさぎは途中で寝てしまいました。目が覚めた時は、もうあとのまつりでした。かめはすでに山のてっ辺に立っていました。 EOD; $request->setParameter('jtextarea', $default_text); } else { $validator = new coreValidator($this->getActionName()); if ($validator->validate($request->getParameterHolder()->getAll())) { $this->display_form = false; $this->display_kanji = true; $this->kanji_text = $this->transformJapaneseText($request->getParameter('jtextarea')); } } }
/** * Change Password. * * Update the user's password on the RevTK site AND the corresponding PunBB forum account. * */ public function executePassword($request) { if ($request->getMethod() != coreRequest::POST) { return coreView::SUCCESS; } // handle the form submission $validator = new coreValidator($this->getActionName()); if ($validator->validate($request->getParameterHolder()->getAll())) { // verify old password $oldpassword = trim($request->getParameter('oldpassword')); $user = $this->getUser()->getUserDetails(); if ($user && $this->getUser()->getSaltyHashedPassword($oldpassword) == $user['password']) { // proceed with password update $new_raw_password = trim($request->getParameter('newpassword')); $user = $this->getUser()->getUserDetails(); // update the password on main site and forum $this->getUser()->changePassword($user['username'], $new_raw_password); // save username before signing out $this->username = $this->getUser()->getUserName(); // log out user (sign out, clear cookie, clear punbb cookie(not on staging website)) $this->getUser()->signOut(); $this->getUser()->clearRememberMeCookie(); if (coreContext::getInstance()->getConfiguration()->getEnvironment() !== 'staging' && coreConfig::get('app_path_to_punbb') !== null) { PunBBUsersPeer::signOut(); } try { // send email confirmation $mailer = new rtkMail(); $mailer->sendUpdatePasswordConfirmation($user['email'], $user['username'], $new_raw_password); } catch (coreException $e) { $request->setError('mail_error', 'Oops, we tried sending you a confirmation email but the mail server didn\'t respond. Your password has been updated though!'); } return 'Done'; } else { $request->setError('login_invalid', "Old password doesn't match."); } } // clear the password fields (avoid input mistakes) $request->setParameter('oldpassword', ''); $request->setParameter('newpassword', ''); $request->setParameter('newpassword2', ''); }
/** * Contact/Feedback Form page. * */ public function executeContact($request) { if ($request->getMethod() != coreRequest::POST) { return; } $validator = new coreValidator($this->getActionName()); if ($validator->validate($request->getParameterHolder()->getAll())) { $name_from = trim($request->getParameter('name')); $reply_to = trim($request->getParameter('email')); $message = trim($request->getParameter('message')); try { $mailer = new rtkMail(); $mailer->sendFeedbackMessage($reply_to, $name_from, $message); } catch (coreException $e) { $request->setError('smtp_mail', "I'm sorry, there was a problem sending the email. " . "Please try again shortly."); return; } return 'EmailSent'; } }
public function executeRemoveCustomConfirm($request) { $validator = new coreValidator('RemoveCustom'); if ($validator->validate($request->getParameterHolder()->getAll())) { // create flashcard selection from string $fcSel = new rtkFlashcardSelection($request); if ($fcSel->setFromString($request->getParameter('txtSelection'))) { // store valid selection in session $cards = $fcSel->getCards(); if (count($cards)) { $this->getUser()->setAttribute('selection', serialize($cards)); } return $this->renderPartial('RemoveCustomConfirm', array('cards' => $cards, 'count' => count($cards))); } else { $request->setError('x', 'Invalid selection.'); } } $this->forward('manage', 'removecustom'); }