Exemplo n.º 1
0
 public function run(User $user, $args)
 {
     $args = explode(' ', $args, 2);
     $userName = $args[0];
     if (!isset($args[1])) {
         RespondError::make($user, ['msg' => 'Вы не ввели сообщения']);
         return;
     }
     $text = $args[1];
     $properties = PropertiesDAO::create()->getByUserName($userName);
     if (!$properties->getId()) {
         RespondError::make($user, ['msg' => "{$userName} не зарегистрирован или имя введено не верно"]);
         return;
     }
     $address = UserDAO::create()->getById($properties->getUserId());
     $permissions = new UserActions($user->getUserDAO());
     $actions = $permissions->getAllowed($address);
     if (!in_array(UserActions::MAIL, $actions)) {
         RespondError::make($user, ['msg' => $user->getLang()->getPhrase('NoPermission')]);
         return;
     }
     //@TODO сделать отправку по крону
     //также надо ограничить частоту отправки
     $config = DI::get()->getConfig();
     $mailerName = 'СоциоЧат';
     $headers = "MIME-Version: 1.0 \n" . "From: " . mb_encode_mimeheader($mailerName) . "<" . $config->adminEmail . "> \n" . "Reply-To: " . mb_encode_mimeheader($mailerName) . "<" . $config->adminEmail . "> \n" . "Content-Type: text/html;charset=UTF-8\n";
     $topic = 'Для вас есть сообщение';
     $msg = "<h2>Вам пришло сообщение от пользователя {$user->getProperties()->getName()}</h2>";
     $msg .= '<p>' . htmlentities(strip_tags($text)) . '</p>';
     $msg .= '<hr>';
     $msg .= 'Вернуться в <a href="' . $config->domain->protocol . $config->domain->web . '">СоциоЧат</a>';
     mb_send_mail($address->getEmail(), $topic, $msg, $headers);
     RespondError::make($user, ['msg' => 'Сообщение отправлено!']);
     return ['Сообщение отправлено!', true];
 }
Exemplo n.º 2
0
 public function handleRequest(ChainContainer $chain)
 {
     $action = $chain->getRequest()['action'];
     if (!isset($this->actionsMap[$action])) {
         RespondError::make($chain->getFrom());
         return;
     }
     $this->{$this->actionsMap[$action]}($chain);
 }
Exemplo n.º 3
0
 public function run(User $user, $args)
 {
     $args = explode(' ', $args);
     $name = $args[0];
     $users = DI::get()->getUsers();
     if (!($targetUser = $users->getClientByName($name))) {
         RespondError::make($user, ['userId' => "{$name} not found"]);
         return;
     }
     return [$targetUser->getProperties()->getName() . ' ip = ' . $targetUser->getIp(), true];
 }
Exemplo n.º 4
0
 public function validateFields(ChainContainer $chain)
 {
     $request = $chain->getRequest();
     if (empty($this->getFields())) {
         return;
     }
     $user = $chain->getFrom();
     foreach ($this->getFields() as $field) {
         if (!isset($request[$field])) {
             RespondError::make($user, $user->getLang()->getPhrase('RequiredPropertyNotSpecified'));
             return false;
         }
     }
 }
 protected function processRemove(ChainContainer $chain)
 {
     $request = $chain->getRequest();
     $user = $chain->getFrom();
     if (!($unbanUser = UserDAO::create()->getById($request['user_id']))) {
         RespondError::make($user, ['user_id' => $user->getLang()->getPhrase('ThatUserNotFound')]);
         return;
     }
     if ($unbanUser->getId() == $user->getId()) {
         RespondError::make($user, ['user_id' => $user->getLang()->getPhrase('CantDoToYourself')]);
         return;
     }
     $user->getBlacklist()->unbanUserId($unbanUser->getId());
     $user->save();
     $this->unbanResponse($user, $unbanUser);
 }
Exemplo n.º 6
0
 protected function processSave(ChainContainer $chain)
 {
     $request = $chain->getRequest();
     $user = $chain->getFrom();
     if (!($notedUser = UserDAO::create()->getById($request[UserNotesDAO::USER_ID]))) {
         RespondError::make($user, ['user_id' => $user->getLang()->getPhrase('ThatUserNotFound')]);
         return;
     }
     if ($notedUser->getId() == $user->getId()) {
         RespondError::make($user, ['user_id' => $user->getLang()->getPhrase('CantDoToYourself')]);
         return;
     }
     $dao = $user->getUserNotes()->setUserId($user->getId())->setNotedUserId($notedUser->getId())->setNote($this->filterInput($request[UserNotesDAO::NOTE]));
     $dao->save();
     $this->guestResponse($user);
 }
Exemplo n.º 7
0
 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;
 }
Exemplo n.º 8
0
 public function run(User $user, $args)
 {
     $request = explode(' ', $args, 1);
     $name = $request[0];
     if (!($targetUser = PropertiesDAO::create()->getByUserName($name))) {
         RespondError::make($user, ['name' => "{$name} не найден"]);
         return;
     }
     $list = NameChangeDAO::create()->getHistoryByUserId($targetUser->getUserId());
     $html = '<table class="table table-striped">';
     /** @var $row NameChangeDAO */
     foreach ($list as $row) {
         $html .= '<tr>';
         $html .= '<td>' . $row->getDateRaw() . '</td>';
         $html .= '<td>' . $row->getName() . '</td>';
         $html .= '</tr>';
     }
     $html .= '</table>';
     return [$html, true];
 }
 private function handleNameChange(User $user, $request)
 {
     $name = $request[PropertiesDAO::NAME];
     $guestName = $user->getLang()->getPhrase('Guest');
     $nameChangeFreq = DI::get()->getConfig()->nameChangeFreq;
     $isNewbie = mb_strpos($name, $guestName) !== false;
     $changeLog = NameChangeDAO::create()->getLastByUser($user);
     $hasNameChanged = $name != $user->getProperties()->getName();
     if ($isNewbie) {
         $newname = str_replace($guestName, TimEnum::create($request[PropertiesDAO::TIM])->getShortName(), $name);
         $duplUser = PropertiesDAO::create()->getByUserName($newname);
         if (!($duplUser->getId() && $duplUser->getUserId() != $user->getId())) {
             $name = $newname;
         }
     } elseif ($changeLog && $hasNameChanged && !$this->isExpired($changeLog, $nameChangeFreq)) {
         RespondError::make($user, $user->getLang()->getPhrase('NameChangePolicy', date('Y-m-d H:i', $changeLog->getDate() + $nameChangeFreq)));
         return;
     }
     if ($changeLog = NameChangeDAO::create()->getLastByName($name)) {
         if ($changeLog->getUserId() != $user->getId()) {
             if (!$this->isExpired($changeLog, $nameChangeFreq)) {
                 RespondError::make($user, $user->getLang()->getPhrase('NameTakePolicy', date('Y-m-d H:i', $changeLog->getDate() + $nameChangeFreq)));
                 return;
             }
         }
     }
     if ($hasNameChanged && !$isNewbie) {
         NameChangeDAO::create()->setUser($user)->save();
     }
 }
Exemplo n.º 10
0
 private static function checkRestrictions(ChainContainer $chain, UserCollection $users)
 {
     $user = $chain->getFrom();
     $request = $chain->getRequest();
     $lang = $user->getLang();
     if (!isset($request[PropertiesDAO::USER_ID])) {
         RespondError::make($user);
         return;
     }
     if (!($desiredUser = $users->getClientById($request[PropertiesDAO::USER_ID]))) {
         RespondError::make($user, [PropertiesDAO::USER_ID => $lang->getPhrase('ThatUserNotFound')]);
         return;
     }
     if ($desiredUser->getId() == $user->getId()) {
         RespondError::make($user, [PropertiesDAO::USER_ID => $lang->getPhrase('CantDoToYourself')]);
         return;
     }
     if ($desiredUser->isInPrivateChat()) {
         RespondError::make($user, [PropertiesDAO::USER_ID => $lang->getPhrase('UserAlreadyInPrivate')]);
         return;
     }
     if ($user->isInPrivateChat()) {
         RespondError::make($user, [PropertiesDAO::USER_ID => $lang->getPhrase('YouAlreadyInPrivate')]);
         return;
     }
     return $desiredUser;
 }
Exemplo n.º 11
0
 protected function processRegister(ChainContainer $chain)
 {
     $user = $chain->getFrom();
     $request = $chain->getRequest();
     $email = $request['login'];
     $duplUser = UserDAO::create()->getByEmail($email);
     $isSameUser = $duplUser->getId() == $user->getId();
     if ($duplUser->getId() && !$isSameUser) {
         RespondError::make($user, ['email' => $user->getLang()->getPhrase('EmailAlreadyRegistered')]);
         return;
     }
     if (!$user->isRegistered()) {
         $this->checkReferral($user);
     }
     $userDAO = $user->getUserDAO();
     $userDAO->setEmail($email)->setPassword(password_hash($request['password'], PASSWORD_BCRYPT));
     $userDAO->save();
     $this->sendNotifyResponse($user);
 }