/** * Agent for activate temporary disabled users OTP * * @return string */ public static function onRecheckDeactivate() { $users = UserTable::query()->addFilter('<DEACTIVATE_UNTIL', new Type\DateTime())->addFilter('=ACTIVE', 'N')->addSelect('USER_ID')->addSelect('SKIP_MANDATORY')->addSelect('SECRET')->setLimit(100)->exec()->fetchAll(); foreach ($users as $user) { if ($user['SKIP_MANDATORY'] === 'Y' && !$user['SECRET']) { UserTable::update($user['USER_ID'], array('SKIP_MANDATORY' => 'N', 'DEACTIVATE_UNTIL' => null)); } else { UserTable::update($user['USER_ID'], array('ACTIVE' => 'Y', 'SKIP_MANDATORY' => 'N', 'DEACTIVATE_UNTIL' => null)); } } return sprintf('%s();', __METHOD__); }
/** * Save all OTP data to DB * * @throws OtpException * @return bool */ public function save() { $fields = array('ACTIVE' => $this->isActivated() ? 'Y' : 'N', 'TYPE' => $this->getType(), 'ATTEMPTS' => $this->getAttempts(), 'SECRET' => $this->getHexSecret(), 'INITIAL_DATE' => $this->getInitialDate() ?: new Type\DateTime(), 'PARAMS' => $this->getParams(), 'SKIP_MANDATORY' => $this->isMandatorySkipped() ? 'Y' : 'N', 'DEACTIVATE_UNTIL' => $this->getDeactivateUntil()); if ($this->regenerated) { if (!$this->isInitialized()) { throw new OtpException('Missing OTP params, forgot to call syncParameters?'); } // Clear recovery codes when we connect new device RecoveryCodesTable::clearByUser($this->getUserId()); } if ($this->isDbRecordExists()) { $result = UserTable::update($this->getUserId(), $fields); } else { $fields += array('USER_ID' => $this->getUserId()); $result = UserTable::add($fields); } $this->clearGlobalCache(); return $result->isSuccess(); }