Exemplo n.º 1
0
 public function updateSessionId(User $user, $oldUserId)
 {
     SessionDAO::create()->dropByUserId($oldUserId);
     $session = SessionDAO::create()->getByUserId($user->getId());
     $session->setSessionId($user->getWSRequest()->getCookie('token'))->setAccessTime(date(self::TIMESTAMP))->setUserId($user->getId());
     $session->save();
     PropertiesDAO::create()->dropByUserId($oldUserId);
     UserBlacklistDAO::create()->dropByUserId($oldUserId);
     NameChangeDAO::create()->dropByUserId($oldUserId);
     UserDAO::create()->dropById($oldUserId);
 }
Exemplo n.º 2
0
 private function setMsgTimer(User $user)
 {
     $config = DI::get()->getConfig();
     $loop = $this->getLoop();
     $timeout = $config->ads->msgTimeOut;
     $timerCallback = function () use($user) {
         unset($this->msgTimers[$user->getId()]);
     };
     if (isset($this->msgTimers[$user->getId()])) {
         $loop->cancelTimer($this->msgTimers[$user->getId()]);
     }
     $timer = $loop->addTimer($timeout, $timerCallback);
     $this->msgTimers[$user->getId()] = $timer;
 }
Exemplo n.º 3
0
 public static function uploadHistory(User $user, $clear = null)
 {
     $channel = ChannelsCollection::get()->getChannelById($user->getChannelId());
     if (!$channel) {
         $channel = new Channel($user->getChannelId(), 'Приват_' . $user->getChannelId());
         $channel->setOwnerId($user->getId());
         ChannelsCollection::get()->addChannel($channel);
     }
     $log = $channel->getHistory($user->getLastMsgId());
     $client = (new UserCollection())->attach($user);
     $historyResponse = (new HistoryResponse())->setChannelId($user->getChannelId());
     if (!$user->getLastMsgId()) {
         $historyResponse->setClear($clear);
     }
     foreach ($log as $response) {
         if ($user->getBlacklist()->isBanned($response[Channel::FROM_USER_ID])) {
             continue;
         }
         if (isset($response[Channel::TO_NAME])) {
             if ($response[Channel::FROM_USER_ID] == $user->getId() || $response[Channel::TO_NAME] == $user->getProperties()->getName()) {
                 $historyResponse->addResponse($response);
             }
             continue;
         }
         $historyResponse->addResponse($response);
     }
     $historyResponse->setLastMsgId($channel->getLastMsgId());
     $client->setResponse($historyResponse)->notify(false);
 }
Exemplo n.º 4
0
 /**
  * @param User $user
  * @param array $timers
  * @return array
  */
 private function setTimer(User $user, array &$timers)
 {
     $container = DI::get()->container();
     $loop = $container->get('eventloop');
     $config = $container->get('config');
     $timeout = $config->flood->timeout;
     $penalty = $config->flood->penalty;
     $timerCallback = function () use($user, &$timers) {
         unset($timers[$user->getId()]);
     };
     if (isset($timers[$user->getId()])) {
         $loop->cancelTimer($timers[$user->getId()]);
         $timeout += $penalty;
     }
     $timer = $loop->addTimer($timeout, $timerCallback);
     $timers[$user->getId()] = $timer;
 }
Exemplo n.º 5
0
 public function run(User $user, $args)
 {
     $users = DI::get()->getUsers()->getAll();
     $logger = DI::get()->getLogger();
     /** @var User $user */
     foreach ($users as $user) {
         $user->save(true);
         $logger->info('User data for ' . $user->getId() . ' is saved.');
     }
     return ['User data has flushed to disk!', true];
 }
Exemplo n.º 6
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.º 7
0
 public function setEvaluator(User $user)
 {
     $this[self::EVALUATOR_ID] = $user->getId();
     return $this;
 }
 public function setUserProps(User $user)
 {
     $properties = $user->getProperties();
     $dir = DI::get()->getConfig()->uploads->avatars->wwwfolder . DIRECTORY_SEPARATOR;
     $this->setId($user->getId())->setEmail($user->getUserDAO()->getEmail())->setSex($properties->getSex()->getId())->setTim($properties->getTim()->getId())->setName($properties->getName())->setAbout($properties->getAbout())->setAvatarImg($properties->getAvatarImg() ? $dir . $properties->getAvatarImg() : null)->setAvatarThumb($properties->getAvatarThumb() ? $dir . $properties->getAvatarThumb() : null)->setYear($properties->getBirthday())->setCity($properties->getCity())->setCensor($properties->hasCensor())->setNotifyVisual($properties->hasNotifyVisual())->setNotifySound($properties->hasNotifySound())->setLineBreakType($properties->getLineBreakType())->setOnlineNotifyLimit($properties->getOnlineNotificationLimit())->setSubscription($properties->hasSubscription())->setMsgAnimationType($properties->getMessageAnimationType());
     return $this;
 }
Exemplo n.º 9
0
 private function traitGuestInfo(Response $response, User $user)
 {
     if ($guests = $response->getGuests()) {
         foreach ($guests as &$guest) {
             if ($user->getBlacklist()->isBanned($guest[PropertiesDAO::USER_ID])) {
                 $guest += ['banned' => $user->getId()];
             }
             if ($note = $user->getUserNotes()->getNote($guest[PropertiesDAO::USER_ID])) {
                 $guest += ['note' => $note];
             }
         }
         $response->setGuestsRaw($guests);
     }
 }
Exemplo n.º 10
0
 /**
  * @param User $user
  * @throws WrongArgumentException
  * @return array
  */
 private function &getDualQueue(User $user)
 {
     $sex = $user->getProperties()->getSex()->getId();
     if ($sex == SexEnum::FEMALE) {
         return $this->boysQueue;
     } elseif ($sex == SexEnum::MALE) {
         return $this->girlsQueue;
     }
     throw new WrongArgumentException('User sex cannot be anonymous here! UserId = ' . $user->getId());
 }
Exemplo n.º 11
0
 protected function getToken(User $userInviter, User $desiredUser)
 {
     return $userInviter->getId() < $desiredUser->getId() ? $userInviter->getId() . '.' . $desiredUser->getId() : $desiredUser->getId() . '.' . $userInviter->getId();
 }
Exemplo n.º 12
0
 /**
  * @param User $user
  * @return $this
  */
 public function getLastByUser(User $user)
 {
     $list = $this->getListByQuery("SELECT * FROM {$this->dbTable} WHERE " . self::USER_ID . " = :user_id ORDER BY " . self::DATE_CHANGE . " DESC LIMIT 1", ['user_id' => $user->getId()]);
     return !empty($list) ? $list[0] : null;
 }
 private function checkIfAlreadyRegisteredName($userName, User $user)
 {
     $duplUser = PropertiesDAO::create()->getByUserName($userName);
     if ($duplUser->getId() && $duplUser->getUserId() != $user->getId()) {
         RespondError::make($user, [PropertiesDAO::NAME => $user->getLang()->getPhrase('NameAlreadyRegistered', $userName)]);
         $this->propertiesResponse($user);
         return;
     }
     return true;
 }
Exemplo n.º 14
0
 private function checkReferral(User $user)
 {
     $ref = ReferralDAO::create()->getFirstRefByUserId($user->getId());
     if (!$ref) {
         return;
     }
     $users = DI::get()->getUsers();
     if ($refUserOnline = $users->getClientById($ref->getRefUserId())) {
         $refUser = $refUserOnline->getUserDAO();
     } else {
         $refUser = UserDAO::create()->getById($ref->getRefUserId());
     }
     if (!$refUser->getId()) {
         return;
     }
     $mark = UserKarmaDAO::create()->setUserId($refUser->getId())->setEvaluator($user)->setMark(5)->setDateRegister(DbQueryHelper::timestamp2date());
     $mark->save();
     $props = $refUser->getPropeties();
     $props->setKarma($props->getKarma() + 5);
     if ($refUserOnline) {
         $refUserOnline->save();
         $response = (new MessageResponse())->setGuests($users->getUsersByChatId($refUserOnline->getChannelId()))->setChannelId($refUserOnline->getChannelId())->setTime(null);
         $users->setResponse($response)->notify();
         $response = (new MessageResponse())->setMsg(MsgToken::create('profile.referralKarma'))->setChannelId($refUserOnline->getChannelId())->setTime(null);
         (new UserCollection())->attach($refUserOnline)->setResponse($response)->notify(false);
     } else {
         $props->save(false);
     }
     DI::get()->getLogger()->info('Added karma to referral userId ' . $props->getUserId());
 }