Determines whether the user has unsubscribed from this email type

@param  int    $iUSerId The user ID to check for
@param  string $sType   The type of email to check against

@return boolean
@throws \Nails\Common\Exception\FactoryException
356215
public function userHasUnsubscribed($iUSerId, $sType)
    {
        $oDb = Factory::service('Database');
        $oDb->where('user_id', $iUSerId);
        $oDb->where('type', $sType);
        return (bool) $oDb->count_all_results(NAILS_DB_PREFIX . 'user_email_blocker');
    }
865604
static public function sendActivationEmail( $userID )
    {
        eZDebugSetting::writeNotice( 'kernel-user',  'Sending activation email.', 'user register' );
        $ini = eZINI::instance();

        $tpl = eZTemplate::factory();
        $user = eZUser::fetch( $userID );
        $tpl->setVariable( 'user', $user );
        $object= eZContentObject::fetch( $userID );
        $tpl->setVariable( 'object', $object );
        $hostname = eZSys::hostname();
        $tpl->setVariable( 'hostname', $hostname );

        // Check whether account activation is required.
        $verifyUserType = $ini->variable( 'UserSettings', 'VerifyUserType' );
        $sendUserMail = !!$verifyUserType;

        if ( $verifyUserType === 'email' ) // and if it is email type
        {
            // Disable user account and send verification mail to the user

            // Create enable account hash and send it to the newly registered user
            $hash = md5( mt_rand() . time() . $userID );

            if ( eZOperationHandler::operationIsAvailable( 'user_activation' ) )
            {
                $operationResult = eZOperationHandler::execute( 'user',
                                                                'activation', array( 'user_id'    => $userID,
                                                                                     'user_hash'  => $hash,
                                                                                     'is_enabled' => false ) );
            }
            else
            {
                eZUserOperationCollection::activation( $userID, $hash, false );
            }

            $tpl->setVariable( 'hash', $hash );

            $sendUserMail = true;
        }
        else if ( $verifyUserType )// custom account activation
        {
            $verifyUserTypeClass = false;
            // load custom verify user settings
            if ( $ini->hasGroup( 'VerifyUserType_' . $verifyUserType ) )
            {
                if ( $ini->hasVariable( 'VerifyUserType_' . $verifyUserType, 'File' ) )
                    include_once( $ini->variable( 'VerifyUserType_' . $verifyUserType, 'File' ) );
                $verifyUserTypeClass = $ini->variable( 'VerifyUserType_' . $verifyUserType, 'Class' );
            }
            // try to call the verify user class with function verifyUser
            $user = eZContentObject::fetch( $userID );
            if ( $verifyUserTypeClass && method_exists( $verifyUserTypeClass, 'verifyUser' ) )
                $sendUserMail  = call_user_func( array( $verifyUserTypeClass, 'verifyUser' ), $user, $tpl );
            else
                eZDebug::writeWarning( "Unknown VerifyUserType '$verifyUserType'", 'user/register' );
        }

        // send verification mail to user if email type or custum verify user type returned true
        if ( $sendUserMail )
        {
            $templateResult = $tpl->fetch( 'design:user/registrationinfo.tpl' );
            if ( $tpl->hasVariable( 'content_type' ) )
                $contentType = $tpl->variable( 'content_type' );
            else
                $contentType = $ini->variable( 'MailSettings', 'ContentType' );

            $emailSender = $ini->variable( 'MailSettings', 'EmailSender' );
            if ( $tpl->hasVariable( 'email_sender' ) )
                $emailSender = $tpl->variable( 'email_sender' );
            else if ( !$emailSender )
                $emailSender = $ini->variable( 'MailSettings', 'AdminEmail' );

            if ( $tpl->hasVariable( 'subject' ) )
                $subject = $tpl->variable( 'subject' );
            else
                $subject = ezpI18n::tr( 'kernel/user/register', 'Registration info' );

            $mail = new eZMail();
            $mail->setSender( $emailSender );
            $mail->setContentType( $contentType );
            $user = eZUser::fetch( $userID );
            $receiver = $user->attribute( 'email' );
            $mail->setReceiver( $receiver );
            $mail->setSubject( $subject );
            $mail->setBody( $templateResult );
            $mailResult = eZMailTransport::send( $mail );
        }
        return array( 'status' => eZModuleOperationInfo::STATUS_CONTINUE );
    }
970920
public function mfaTokenGenerate($iUserId)
    {
        $oPasswordModel = Factory::model('UserPassword', 'nails/module-auth');
        $oNow           = Factory::factory('DateTime');
        $oInput         = Factory::service('Input');
        $oDb            = Factory::service('Database');

        $sSalt    = $oPasswordModel->salt();
        $sIp      = $oInput->ipAddress();
        $sCreated = $oNow->format('Y-m-d H:i:s');
        $sExpires = $oNow->add(new \DateInterval('PT10M'))->format('Y-m-d H:i:s');
        $aToken   = [
            'token' => sha1(sha1(APP_PRIVATE_KEY . $iUserId . $sCreated . $sExpires . $sIp) . $sSalt),
            'salt'  => md5($sSalt),
        ];

        //  Add this to the DB
        $oDb->set('user_id', $iUserId);
        $oDb->set('token', $aToken['token']);
        $oDb->set('salt', $aToken['salt']);
        $oDb->set('created', $sCreated);
        $oDb->set('expires', $sExpires);
        $oDb->set('ip', $sIp);

        if ($oDb->insert(NAILS_DB_PREFIX . 'user_auth_two_factor_token')) {
            $aToken['id'] = $oDb->insert_id();
            return $aToken;
        } else {
            $error = lang('auth_twofactor_token_could_not_generate');
            $this->setError($error);
            return false;
        }
    }
597458
static function cleanupSubscription( $email, $contentobjectID, $languageID )
    {
        //2. get subscriber
        $subscriber = ezcomSubscriber::fetchByEmail( $email );
        if ( is_null( $subscriber ) )
        {
            return false;
        }
        $subscriberID = $subscriber->attribute( 'id' );
        //3. clean up subscription
        $querySubscription = "DELETE FROM ezcomment_subscription" . 
                             " WHERE subscriber_id = $subscriberID ".
                             " AND content_id = $contentID" .
                             " AND language_id= $languageID";
        $db->query($querySubscription);
        return true;
    }
751469
public static function delete_stale_subscriptions($userid = 0) {
        global $DB;
        // Get the expiry duration, in days.
        $cutofftime = strtotime("-" . self::INACTIVE_SUBSCRIPTION_LIFESPAN_IN_DAYS . " days", time());

        if (!empty($userid)) {
            // Remove any stale subscriptions for the desired user only.
            $success = $DB->delete_records_select('tool_monitor_subscriptions',
                                                  'userid = ? AND inactivedate < ? AND inactivedate <> 0',
                                                  array($userid, $cutofftime));

        } else {
            // Remove all stale subscriptions.
            $success = $DB->delete_records_select('tool_monitor_subscriptions',
                                                  'inactivedate < ? AND inactivedate <> 0',
                                                  array($cutofftime));
        }
        return $success;
    }
734604
public function userUnreadMessages($userId)
    {
        $messages = $this->messages()->get();

        try {
            $participant = $this->getParticipantFromUser($userId);
        } catch (ModelNotFoundException $e) {
            return collect();
        }

        if (!$participant->last_read) {
            return $messages;
        }

        return $messages->filter(function ($message) use ($participant) {
            return $message->updated_at->gt($participant->last_read);
        });
    }
14188
public function delete($sTable, $iUserId)
    {
        $oDb = Factory::service('Database');
        $oDb->where('user_id', $iUserId);
        if (!$oDb->delete($sTable)) {
            return false;
        }

        $this->unsetCache('user-meta-' . $sTable . '-' . $iUserId);
        return true;
    }
1159403
public function unsubscribe($destination, $subscriptionId = null, array $header = [])
    {
        return $this->client->sendFrame(
            $this->getProtocol()->getUnsubscribeFrame($destination, $subscriptionId)->addHeaders($header)
        );
    }
435838
public function removeUser(OneClickRemoveUserInput $removeUserInput)
    {
        $removeUser = new RemoveUser();
        $removeUser->arg0 = $removeUserInput;
        return $this->callSoapMethod('removeUser', $removeUser);
    }
687343
protected function isAllowed($what, $user = null, $contenttype = null, $contentid = null)
    {
        /** @var Token $sessionAuth */
        if ($user === null && $sessionAuth = $this->session()->get('authentication')) {
            $user = $sessionAuth->getUser()->toArray();
        }

        return $this->app['permissions']->isAllowed($what, $user, $contenttype, $contentid);
    }
446909
public function asUser($iUserId)
    {
        return $this
            ->setHeader(Testing::TEST_HEADER_NAME, Testing::TEST_HEADER_VALUE)
            ->setHeader(Testing::TEST_HEADER_USER_NAME, $iUserId);
    }
218587
public function emailDelete($mEmailId, $iUserId = null)
    {
        $oDb = Factory::service('Database');
        if (is_numeric($mEmailId)) {
            $oDb->where('id', $mEmailId);
        } else {
            $oDb->where('email', $mEmailId);
        }

        if (!empty($iUserId)) {
            $oDb->where('user_id', $iUserId);
        }

        $oDb->where('is_primary', false);
        $oDb->delete($this->tableEmail);

        if ((bool) $oDb->affected_rows()) {

            if (is_numeric($iUserId)) {
                $this->unsetCacheUser($iUserId);
            }
            return true;

        } else {
            return false;
        }
    }
112580
private function handleSubscriptionUid(ConnectionInterface $from, $data) {
    if ($data['action'] === 'subscribe') {
      // Client is subscribing to a UID.
      if (!key_exists($data['uid'], $this->uidSubs)) {
        $this->uidSubs[$data['uid']] = new \SplObjectStorage();
      }
      $this->uidSubs[$data['uid']][$from] = [
        'count' => !!$data['count']
      ];
      $this->logger->notice(
          "Client subscribed to a UID! ".
            "({$data['uid']}, {$from->resourceId})"
      );

      if (Server::$config['broadcast_counts']) {
        // Notify clients of the subscription count.
        $count = count($this->uidSubs[$data['uid']]);
        foreach ($this->uidSubs[$data['uid']] as $key) {
          $curData = $this->uidSubs[$data['uid']][$key];
          if ($curData['count']) {
            $key->send(json_encode([
              'uid' => $data['uid'],
              'count' => $count
            ]));
          }
        }
      }
    }

    if ($data['action'] === 'unsubscribe') {
      // Client is unsubscribing from a UID.
      if (!key_exists($data['uid'], $this->uidSubs)) {
        return;
      }
      if (!$this->uidSubs[$data['uid']]->contains($from)) {
        return;
      }
      unset($this->uidSubs[$data['uid']][$from]);
      $this->logger->notice(
          "Client unsubscribed from a UID! ".
            "({$data['uid']}, {$from->resourceId})"
      );

      $count = count($this->uidSubs[$data['uid']]);

      if ($count === 0) {
        // No more subscribed clients.
        unset($this->uidSubs[$data['uid']]);
        return;
      }

      if (Server::$config['broadcast_counts']) {
        // Notify clients of the subscription count.
        $count = count($this->uidSubs[$data['uid']]);
        foreach ($this->uidSubs[$data['uid']] as $key) {
          $curData = $this->uidSubs[$data['uid']][$key];
          if ($curData['count']) {
            $key->send(json_encode([
              'uid' => $data['uid'],
              'count' => $count
            ]));
          }
        }
      }
    }
  }
1198888
public function unsubscribe(string $guid)
    {
        $userList = $this->fields(['isSubscriber'])
            ->filter(['guid' => [FilterOperators::EQUAL => $guid]])
            ->limit(1)
            ->all();

        if (!isset($userList[0]) || !(new IsUserSubscriber())->isSatisfiedBy($userList[0])) {
            return null;
        }

        return $this->update($userList[0]->id, ['isSubscriber' => 0]);
    }
243242
public function isUserActivated($userId): bool
    {
        $ngUserSetting = $this->findOneBy(['userId' => $userId]);

        if ($ngUserSetting instanceof NgUserSetting) {
            return $ngUserSetting->getIsActivated();
        }

        return false;
    }
1120437
static function removeUser( $userID )
    {
        $user = eZUser::fetch( $userID );
        if ( !$user )
        {
            eZDebug::writeError( "unable to find user with ID $userID", __METHOD__ );
            return false;
        }

        eZUser::removeSessionData( $userID );

        eZSubtreeNotificationRule::removeByUserID( $userID );
        eZCollaborationNotificationRule::removeByUserID( $userID );
        eZUserSetting::removeByUserID( $userID );
        eZUserAccountKey::removeByUserID( $userID );
        eZForgotPassword::removeByUserID( $userID );
        eZWishList::removeByUserID( $userID );
        eZGeneralDigestUserSettings::removeByUserId( $userID );

        eZPersistentObject::removeObject( eZUser::definition(),
                                          array( 'contentobject_id' => $userID ) );
        return true;
    }
1261476
public function isExpired($iUserId)
    {
        if (empty($iUserId)) {
            return false;
        }

        $oDb = Factory::service('Database');
        $oDb->select('u.password_changed,ug.password_rules');
        $oDb->where('u.id', $iUserId);
        $oDb->join(NAILS_DB_PREFIX . 'user_group ug', 'ug.id = u.group_id');
        $oDb->limit(1);
        $oResult = $oDb->get(NAILS_DB_PREFIX . 'user u');

        if ($oResult->num_rows() !== 1) {
            return false;
        }

        //  Decode the password rules
        $oGroupPwRules = json_decode($oResult->row()->password_rules);

        if (empty($oGroupPwRules->expiresAfter)) {
            return false;
        }

        $sChanged = $oResult->row()->password_changed;

        if (is_null($sChanged)) {

            return true;

        } else {

            $oThen     = new \DateTime($sChanged);
            $oNow      = new \DateTime();
            $oInterval = $oNow->diff($oThen);

            return $oInterval->days >= $oGroupPwRules->expiresAfter;
        }
    }