/** * @see Form::validate() */ public function validate() { parent::validate(); if (empty($this->pageName)) throw new UserInputException('pageName', 'empty'); if (!preg_match('/^[a-z0-9_-]+$/i', $this->pageName)) throw new UserInputException('pageName', 'invalid'); if (StringUtil::length($this->pageName) > 20) throw new UserInputException('pageName', 'tooLong'); if (empty($this->menuItem)) throw new UserInputException('menuItem', 'empty'); if (StringUtil::length($this->menuItem) > 20) throw new UserInputException('menuItem', 'tooLong'); }
/** * @see Form::validate() */ public function validate() { parent::validate(); // only for guests if (WCF::getUser()->userID == 0) { // username if (empty($this->username)) { throw new UserInputException('username'); } if (!UserUtil::isValidUsername($this->username)) { throw new UserInputException('username', 'notValid'); } if (!UserUtil::isAvailableUsername($this->username)) { throw new UserInputException('username', 'notAvailable'); } WCF::getSession()->setUsername($this->username); } else { $this->username = WCF::getUser()->username; } }
/** * Displays and send messages in the specified queue. * @param string $queue_name * @param string $subscriber_id */ public function actionMessages($queue_name, $subscriber_id = null) { if (($subscriber_id = trim($subscriber_id)) === '') { $subscriber_id = null; } list($queue, $authItems) = $this->loadQueue($queue_name, array('nfy.message.read', 'nfy.message.create')); $this->verifySubscriber($queue, $subscriber_id); $formModel = new MessageForm('create'); if ($authItems['nfy.message.create'] && isset($_POST['MessageForm'])) { $formModel->attributes = $_POST['MessageForm']; if ($formModel->validate()) { $queue->send($formModel->content, $formModel->category); $this->redirect(array('messages', 'queue_name' => $queue_name, 'subscriber_id' => $subscriber_id)); } } $dataProvider = null; if ($authItems['nfy.message.read']) { $dataProvider = new CArrayDataProvider($queue->peek($subscriber_id, 200, array(NfyMessage::AVAILABLE, NfyMessage::RESERVED, NfyMessage::DELETED)), array('sort' => array('attributes' => array('id'), 'defaultOrder' => array('id' => CSort::SORT_DESC)))); // reverse display order to simulate a chat window, where latest message is right above the message form $dataProvider->setData(array_reverse($dataProvider->getData())); } $this->render('messages', array('queue' => $queue, 'queue_name' => $queue_name, 'dataProvider' => $dataProvider, 'model' => $formModel, 'authItems' => $authItems)); }
/** * @see Form::validate() */ public function validate() { parent::validate(); if (empty($this->subject)) { throw new UserInputException('subject'); } if (empty($this->text)) { throw new UserInputException('text'); } if (StringUtil::length($this->text) > WCF::getUser()->getPermission('user.contest.maxSolutionLength')) { throw new UserInputException('text', 'tooLong'); } if (StringUtil::length($this->secretMessage) > WCF::getUser()->getPermission('user.contest.maxSolutionLength')) { throw new UserInputException('secretMessage', 'tooLong'); } if ($this->groupID) { $this->ownerGroups = ContestUtil::readAvailableGroups(); // validate group ids if (!array_key_exists($this->groupID, $this->ownerGroups)) { throw new UserInputException('ownerID'); } } if ($this->sponsorID) { if (!$this->contest->isOwner() && !ContestCrew::isMember()) { throw new UserInputException('ownerID'); } $this->ownerSponsors = array(); if ($this->contest->isOwner() || ContestCrew::isMember()) { foreach ($this->contest->getSponsors() as $sponsor) { $this->ownerSponsors[$sponsor->sponsorID] = $sponsor; } } // validate group ids if (!array_key_exists($this->sponsorID, $this->ownerSponsors)) { throw new UserInputException('ownerID'); } } if (!array_key_exists($this->state, $this->getStates())) { throw new UserInputException('state'); } }
/** * @see Form::validate() */ public function validate() { // prefix $this->validatePrefix(); // subject, text, captcha parent::validate(); // username $this->validateUsername(); // poll if ($this->showPoll) { $this->pollEditor->checkParams(); } // language $this->validateLanguage(); }
/** * @see Form::validate() */ public function validate() { parent::validate(); }
/** * @see Form::validate() */ public function validate() { // recipients if (empty($this->recipients) && empty($this->blindCopies) && !$this->draft) { throw new UserInputException('recipients'); } $this->recipientArray = $this->validateRecipients($this->recipients); $this->blindCopyArray = $this->validateRecipients($this->blindCopies, 'blindCopies'); if (!count($this->recipientArray) && !count($this->blindCopyArray) && !$this->draft) { throw new UserInputException('recipients'); } // check number of recipients if (count($this->recipientArray) + count($this->blindCopyArray) > WCF::getUser()->getPermission('user.pm.maxRecipients')) { throw new UserInputException('recipients', 'tooManyRecipients'); } // validate subject and text parent::validate(); }
/** * @see Form::validate() */ public function validate() { parent::validate(); if (empty($this->text)) { throw new UserInputException('text'); } if (StringUtil::length($this->text) > WCF::getUser()->getPermission('user.contest.maxSolutionLength')) { throw new UserInputException('text', 'tooLong'); } if ($this->ownerID != 0) { $this->availableGroups = ContestUtil::readAvailableGroups(); // validate group ids if (!array_key_exists($this->ownerID, $this->availableGroups)) { throw new UserInputException('ownerID'); } } else { if ($this->userid == 0) { throw new UserInputException('ownerID'); } } if (!array_key_exists($this->state, $this->getStates())) { throw new UserInputException('state'); } }
/** * @see Form::validate() */ public function validate() { parent::validate(); $this->validateUsername(); }
public function actionMessage() { $model = new MessageForm(); if ($model->load(Yii::$app->request->post())) { if ($model->validate()) { // form inputs are valid, do something here $model = save(); //return; } } return $this->render('message', ['model' => $model]); }
/** * @see Form::validate() */ public function validate() { parent::validate(); if ($this->action == 'comment' && StringUtil::length($this->text) > $this->maxTextLength) { throw new UserInputException('text', 'tooLong'); } }
/** * @see Form::validate() */ public function validate() { if ($this->tplSelect) { return; } parent::validate(); }
/** * @see Form::validate() */ public function validate() { parent::validate(); $this->availableClasses = ContestClass::getClasses(); // validate class ids foreach ($this->classIDArray as $key => $classID) { if (!isset($this->availableClasses[$classID])) { unset($this->classIDArray[$key]); } } if (count($this->classIDArray) == 0) { throw new UserInputException('classes'); } if ($this->ownerID != 0) { $this->availableGroups = ContestUtil::readAvailableGroups(); // validate group ids if (!array_key_exists($this->ownerID, $this->availableGroups)) { throw new UserInputException('ownerID'); } } else { if ($this->userID == 0) { throw new UserInputException('ownerID'); } } if (!array_key_exists($this->state, $this->getStates())) { throw new UserInputException('state'); } }
public function actionEmail($subject = '', $body = '') { $ids = Yii::app()->getUser()->getState('ids', array()); $students = Student::model()->findAllByPK($ids); $model = new MessageForm(); $model->subject = $subject; $model->body = $body; if (isset($_POST['MessageForm'])) { $model->attributes = $_POST['MessageForm']; if ($model->validate()) { $result = $model->prepareMessages($students); $flashes = array('success' => array(), 'error' => array()); if ($result['prepared']) { $flashes['success'][] = Yii::t('swu', 'One message has been correctly prepared.|{n} messages have been correctly prepared.', $result['prepared']); } if ($result['failed']) { $flashes['error'][] = Yii::t('swu', 'One message could not be prepared.|{n} messages could not be prepared.', $result['failed']); } $this->setAllFlashes($flashes); $this->refresh(); } } $this->render('message', array('model' => $model, 'students' => $students)); }