private function searchUser(User $from, $userId)
 {
     if ($userId == '') {
         return null;
     }
     if ($userId == $from->getId()) {
         return $from;
     }
     $form = (new Form())->import([UserDAO::ID => $userId])->addRule(UserDAO::ID, Rules::isUserOnline(), $from->getLang()->getPhrase('UserIsNotOnline'));
     if (!$form->validate()) {
         RespondError::make($from, $form->getErrors());
         DI::get()->getLogger()->warn("Trying to find userId = {$userId} for private message but not found", [__CLASS__]);
         return false;
     }
     $recipient = $form->getResult(UserDAO::ID);
     /* @var $recipient User */
     return $recipient;
 }
 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);
 }
 public function handleRequest(ChainContainer $chain)
 {
     $action = $chain->getRequest()['action'];
     if (!isset($this->actionsMap[$action])) {
         RespondError::make($chain->getFrom());
         return;
     }
     $user = $chain->getFrom();
     $request = $chain->getRequest();
     try {
         $form = (new Form())->import($request)->addRule('login', Rules::email(), 'Некорректный формат email')->addRule('password', Rules::password(), 'Пароль должен быть от 8 до 20 символов');
     } catch (WrongRuleNameException $e) {
         RespondError::make($user, ['property' => 'Некорректно указано свойство']);
         return;
     }
     if (!$form->validate()) {
         RespondError::make($user, $form->getErrors());
         return;
     }
     $this->{$this->actionsMap[$action]}($chain);
 }
Exemple #4
0
    echo $sex->getName();
    ?>
</option>
                    <?php 
}
?>
                </select>
            </div>
            <div class="col-md-2 btn-vert-block">
                <select class="form-control" id="profile-year">
                    <option selected disabled><?php 
echo $lang->getPhrase('profile.Birth');
?>
</option>
                    <?php 
foreach (Rules::getBirthYearsRange() as $year) {
    ?>
                        <option value="<?php 
    echo $year;
    ?>
"><?php 
    echo $year;
    ?>
</option>
                    <?php 
}
?>
                </select>
            </div>
        </div>
use SocioChat\Forms\Rules;
use Zend\Config\Config;
require_once dirname(__DIR__) . DIRECTORY_SEPARATOR . 'config.php';
$container = DI::get()->container();
DIBuilder::setupNormal($container);
$config = $container->get('config');
/* @var $config Config */
$email = isset($_REQUEST['email']) ? $_REQUEST['email'] : null;
$code = isset($_REQUEST['code']) ? $_REQUEST['code'] : null;
$validation = null;
if (!$email || !$code) {
    exit;
}
$form = new Form();
$form->import($_REQUEST);
$form->addRule(ActivationsDAO::EMAIL, Rules::email(), 'email в таком формате не может существовать.', 'emailPattern')->addRule(ActivationsDAO::EMAIL, function ($val) {
    $user = UserDAO::create()->getByEmail($val);
    return (bool) $user->getId();
}, 'Такой email не найден в системе.', 'userSearch');
$validation = $form->validate();
if (!$validation) {
    $heading = 'Ошибка!';
    $message = 'Email невалиден.';
    require_once "pages/common_page.php";
    exit;
}
$activation = ActivationsDAO::create();
$result = $activation->getActivation($email, $code);
$activation = $result[0];
/* @var $activation ActivationsDAO */
if (!$activation->getId() || $activation->getIsUsed()) {
 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']);
 }
    require_once "pages/activation/error.php";
    exit;
}
if (strtotime($activation->getTimestamp()) + $config->activationTTL < time()) {
    $activation->setIsUsed(true);
    $activation->save();
    require_once "pages/activation/error.php";
    exit;
}
if (!$password) {
    require_once "pages/activation/prepare.php";
    exit;
}
$form = new Form();
$form->import($_REQUEST);
$form->addRule('password', Rules::password(), 'Пароль должен быть от 8 до 20 символов')->addRule('password-repeat', Rules::password(), 'Пароль должен быть от 8 до 20 символов');
$validation = $form->validate();
if (!$validation) {
    require_once "pages/activation/prepare.php";
    exit;
}
if ($password != $passwordRepeat) {
    $validation = false;
    $form->markWrong('password', 'Введенные пароли не совпадают');
    require_once "pages/activation/prepare.php";
    exit;
}
$user = UserDAO::create()->getByEmail($email);
$user->setPassword(password_hash($password, PASSWORD_BCRYPT));
$user->save();
$activation->setIsUsed(true);