/**
	 * @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');
	}
コード例 #2
0
 /**
  * @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;
     }
 }
コード例 #3
0
ファイル: QueueController.php プロジェクト: jasonhai/yii-nfy
 /**
  * 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));
 }
コード例 #4
0
 /**
  * @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');
     }
 }
コード例 #5
0
 /**
  * @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();
 }
コード例 #6
0
 /**
  * @see Form::validate()
  */
 public function validate()
 {
     parent::validate();
 }
コード例 #7
0
 /**
  * @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();
 }
コード例 #8
0
 /**
  * @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();
 }
コード例 #10
0
 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]);
 }
コード例 #11
0
 /**
  * @see Form::validate()
  */
 public function validate()
 {
     parent::validate();
     if ($this->action == 'comment' && StringUtil::length($this->text) > $this->maxTextLength) {
         throw new UserInputException('text', 'tooLong');
     }
 }
コード例 #12
0
 /**
  * @see Form::validate()
  */
 public function validate()
 {
     if ($this->tplSelect) {
         return;
     }
     parent::validate();
 }
コード例 #13
0
 /**
  * @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');
     }
 }
コード例 #14
0
 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));
 }