/** * Send password change link * @param string $login * @return bool|string * @throws \Difra\Exception */ public static function send($login) { if (is_null($login) or $login === '' or $login === false) { return User::LOGIN_NOTFOUND; } $db = DB::getInstance(Users::getDB()); $data = $db->fetchRow('SELECT `id`,`email`,`active`,`banned` FROM `user` WHERE `email`=:login OR `login`=:login LIMIT 1', ['login' => $login]); if (empty($data)) { return User::LOGIN_NOTFOUND; } if (!$data['active']) { return User::LOGIN_INACTIVE; } if ($data['banned']) { return User::LOGIN_BANNED; } do { $key = bin2hex(openssl_random_pseudo_bytes(12)); $d = $db->fetchOne('SELECT count(*) FROM `user_recover` WHERE `recover`=\'' . $key . "'"); } while ($d); $db->query("INSERT INTO `user_recover` (`recover`,`user`) VALUES (?,?)", [$key, $data['id']]); $db->query("DELETE FROM `user_recover` WHERE `date_requested`<DATE_SUB(NOW(),INTERVAL 1 YEAR)"); Mailer::getInstance()->CreateMail($data['email'], 'mail_recover', ['code' => $key, 'ttl' => Users::getRecoverTTL()]); return true; }
/** * If page rendered too long, report to developers * @throws Exception */ public static function checkSlow() { // TODO: merge this method with Exception::sendNotification() $time = self::getTimer(); if (!$time <= 1) { return; } // don't send notifications on development environment if (!Envi::isProduction()) { return; } $notificationMail = self::getNotificationMail(); // no notification mail is set if (!$notificationMail) { return; } $output = '<pre>'; foreach (self::$output as $line) { if (!isset($line['type'])) { $line['type'] = null; } $output .= "{$line['timer']}\t{$line['class']}\t{$line['type']}\t{$line['message']}\n"; } $date = date('r'); $server = print_r($_SERVER, true); $post = print_r($_POST, true); $cookie = print_r($_COOKIE, true); $host = Envi::getHost(); $uri = Envi::getUri(); $user = Auth::getInstance()->getEmail(); $output .= <<<MSG Page:\t{$uri} Time:\t{$date} Host:\t{$host} User:\t{$user} \$_SERVER: {$server} \$_POST: {$post} \$_COOKIE: {$cookie} MSG; $output .= '</pre>'; Mailer::getInstance()->sendMail(self::getNotificationMail(), 'Slow script', print_r($output, true)); }
public function autoActivation() { switch ($method = Users::getActivationMethod()) { case 'email': $mailData = ['username' => $this->login ?: $this->email, 'ttl' => Users::ACTIVATE_TTL, 'code' => $this->activation, 'confirm' => $method]; Mailer::getInstance()->createMail($this->email, 'mail_registration', $mailData); break; default: throw new Exception('Unknown activation method: ' . $method); } }
private function sendMail() { $db = \Difra\MySQL::getInstance(); // определяем кто владелец родительского элемента switch ($this->module) { case 'albums': $query = "SELECT a.`name` AS `title`, a.`link`, a.`group_id`, g.`domain`, g.`owner`\n\t\t\t\t\t\tFROM `albums` a\n\t\t\t\t\t\tLEFT JOIN `groups` AS `g` ON g.`id`=a.`group_id`\n\t\t\t\t\t\tWHERE a.`id`='" . $this->moduleId . "'"; break; case 'catalog': // TODO: замутить отправку письма если это ответ на коммент юзера // XXX: есть ведь уже? //nap return; case 'blogs': default: $query = "SELECT b.`user`, g.`owner`, bp.`title`, g.`domain`, bp.`link`\n\t\t\t\t\tFROM `blogs_posts` bp\n\t\t\t\t\tLEFT JOIN `blogs` AS `b` ON b.`id`=bp.`blog`\n\t\t\t\t\tLEFT JOIN `groups` AS `g` ON g.`id`=b.`group`\n\t\t\t\t\tWHERE bp.`id`='" . $this->moduleId . "'"; break; } $res = $db->fetchRow($query); if (empty($res)) { return; } if (isset($res['user']) && $res['user'] != '') { $elementOwner = $res['user']; } else { $elementOwner = $res['owner']; } // смотрим можно ли юзеру отправить email $userAdditionals = \Difra\Additionals::getAdditionals('users', $elementOwner); if (!isset($userAdditionals['unsubscribe']) || $userAdditionals['unsubscribe'] == 0) { // отправляем письмо владельцу родительского элемента $query = "SELECT `email`, `activation` FROM `users` WHERE `id`='" . intval($elementOwner) . "' AND `banned`=0 AND `active`=1"; $replyText = []; if ($this->replyId) { // это ответ на чужой коммент. // забираем данные об ответе $query = "SELECT c.`text`, c.`user` FROM `" . $this->module . "_comments` c WHERE c.`id`='" . $this->replyId . "'"; $replyText = $db->fetchRow($query); $query = "SELECT `email`, `activation` FROM `users` WHERE `id`='" . intval($replyText['user']) . "' AND `banned`=0 AND `active`=1"; } $userData = $db->fetchRow($query); if (!empty($userData)) { // получаем никнейм отправителя: $replyUser = \Difra\Additionals::getAdditionalValue('users', $this->user, 'nickname'); // ссылка на родительский элемент $elementLink = ''; if ($this->module == 'albums') { // если альбом $elementLink = 'http://' . $res['domain'] . '.' . \Difra\Site::getInstance()->getMainhost() . '/album/' . rawurlencode($res['link']) . '/'; } elseif ($this->module == 'blogs') { if (isset($res['domain']) && $res['domain'] != '') { // если пост в блоге группы $elementLink = 'http://' . $res['domain'] . '.' . \Difra\Site::getInstance()->getMainhost() . '/' . $this->moduleId . '/' . rawurlencode($res['link']) . '/'; } else { // если пост в личном блоге юзера $ownerNickname = \Difra\Additionals::getAdditionalValue('users', $elementOwner, 'nickname'); $elementLink = 'http://' . \Difra\Site::getInstance()->getMainhost() . '/blogs/' . $ownerNickname . '/' . $this->moduleId . '/' . rawurlencode($res['link']) . '/'; } } $unsubscribeLink = 'http://' . \Difra\Site::getInstance()->getMainhost() . '/unsubscribe/' . $userData['activation'] . '/'; $sendData = ['unsubscribe' => $unsubscribeLink, 'message' => $this->text, 'module' => $this->module, 'link' => $elementLink, 'reply_nickname' => $replyUser, 'mainHost' => \Difra\Site::getInstance()->getMainhost(), 'title' => $res['title']]; if ($this->replyId) { $sendData['replay'] = 1; $sendData['original'] = $replyText['text']; } \Difra\Mailer::getInstance()->CreateMail($userData['email'], 'mail_newcomment', $sendData); } } }