protected function processSubmit(ChainContainer $chain)
 {
     $request = $chain->getRequest();
     $user = $chain->getFrom();
     $lang = $user->getLang();
     $onlineLimitRule = function ($val) {
         $val = (int) $val;
         return $val >= 0 && $val <= 50;
     };
     $aboutRule = function ($val) {
         $len = mb_strlen($val);
         return $len >= 0 && $len <= 1024;
     };
     try {
         $form = (new Form())->import($request)->addRule(PropertiesDAO::NAME, Rules::namePattern(), $lang->getPhrase('InvalidNameFormat'))->addRule(PropertiesDAO::ABOUT, $aboutRule, $lang->getPhrase('InvalidField'))->addRule(PropertiesDAO::TIM, Rules::timPattern(), $lang->getPhrase('InvalidTIMFormat'))->addRule(PropertiesDAO::SEX, Rules::sexPattern(), $lang->getPhrase('InvalidSexFormat'))->addRule(PropertiesDAO::CITY, Rules::cityPattern(), $lang->getPhrase('InvalidCityFormat'))->addRule(PropertiesDAO::BIRTH, Rules::birthYears(), $lang->getPhrase('InvalidYearFormat'))->addRule(PropertiesDAO::CENSOR, Rules::notNull(), $lang->getPhrase('InvalidField'))->addRule(PropertiesDAO::NOTIFY_VISUAL, Rules::notNull(), $lang->getPhrase('InvalidField'))->addRule(PropertiesDAO::NOTIFY_SOUND, Rules::notNull(), $lang->getPhrase('InvalidField'))->addRule(PropertiesDAO::LINE_BREAK_TYPE, Rules::notNull(), $lang->getPhrase('InvalidField'))->addRule(PropertiesDAO::ONLINE_NOTIFICATION, $onlineLimitRule, $lang->getPhrase('InvalidField'))->addRule(PropertiesDAO::IS_SUBSCRIBED, Rules::notNull(), $lang->getPhrase('InvalidField'))->addRule(PropertiesDAO::MESSAGE_ANIMATION_TYPE, Rules::msgAnimationType(), $lang->getPhrase('InvalidField'));
     } catch (WrongRuleNameException $e) {
         RespondError::make($user, ['property' => $lang->getPhrase('InvalidProperty') . ' ' . $e->getMessage()]);
         return;
     }
     if (!$form->validate()) {
         RespondError::make($user, $form->getErrors());
         return;
     }
     $userName = $request[PropertiesDAO::NAME] = strip_tags(trim($request[PropertiesDAO::NAME]));
     if (!$this->checkIfAlreadyRegisteredName(CharTranslator::toEnglish($userName), $user)) {
         return;
     }
     if (!$this->checkIfAlreadyRegisteredName(CharTranslator::toRussian($userName), $user)) {
         return;
     }
     if ($user->isInPrivateChat() || PendingDuals::get()->getUserPosition($user)) {
         $this->forbiddenChangeInDualization($user);
         $this->propertiesResponse($user);
         return;
     }
     $oldName = $user->getProperties()->getName();
     $this->importProperties($user, $request);
     $this->guestsUpdateResponse($user, $oldName);
     $this->propertiesResponse($user);
     ChannelNotifier::notifyOnPendingDuals($user);
 }
Esempio n. 2
0
 public static function setChannelName(ChainContainer $chain)
 {
     $user = $chain->getFrom();
     $request = $chain->getRequest();
     $lang = $user->getLang();
     if (!isset($request['name']) || !isset($request['channelId'])) {
         RespondError::make($user);
         return;
     }
     try {
         $form = (new Form())->import($request)->addRule('channelId', Rules::existsChannel(), $lang->getPhrase('ChannelNotExists'))->addRule('name', Rules::namePattern(100, true), $lang->getPhrase('InvalidNameFormat'), '_nameFormat')->addRule('name', Rules::channelNameDuplication(), $lang->getPhrase('InvalidNameFormat'), '_nameUnique');
     } catch (WrongRuleNameException $e) {
         RespondError::make($user, ['property' => $lang->getPhrase('InvalidProperty')]);
         return;
     }
     if (!$form->validate()) {
         RespondError::make($user, $form->getErrors());
         return;
     }
     $channel = ChannelsCollection::get()->getChannelById($request['channelId']);
     if ($channel->getOwnerId() != $user->getId()) {
         RespondError::make($user, [PropertiesDAO::USER_ID => $lang->getPhrase('InsufficientRights')]);
         return;
     }
     $channel->setName($request['name']);
 }