public function resetPassword($password, $token) { # Get a new Query Builder $Query = \Kanso\Kanso::getInstance()->Database->Builder(); # Validate the user exists $user = $Query->SELECT('*')->FROM('users')->WHERE('kanso_password_key', '=', $token)->ROW(); if (!$user) { return false; } # Change the users password and remove the key from the database $row = []; $row['hashed_pass'] = utf8_encode(\Kanso\Security\Encrypt::hash($password)); $row['kanso_password_key'] = null; $update = $Query->UPDATE('users')->SET($row)->WHERE('id', '=', $user['id'])->QUERY(); if (!$update) { return false; } # Remove the password key from the session \Kanso\Kanso::getInstance()->Session->remove('session_kanso_password_key'); # Reset the user's session \Kanso\Kanso::getInstance()->Session->freshSession(); # Create array of data for email template $website = \Kanso\Kanso::getInstance()->Environment['KANSO_WEBSITE_NAME']; $emailData = ['name' => $user['name'], 'username' => $user['username'], 'website' => $website]; # Get the email template $msg = \Kanso\Templates\Templater::getTemplate($emailData, 'EmailResetPassword'); # Send the email \Kanso\Utility\Mailer::sendHTMLEmail($user['email'], $website, 'no-reply@' . $website, 'Your password was reset at ' . $website, $msg); return true; }
/** * Send comment emails to subscribers where needed * * @param array $articleRow Associative array of article data * @param array $newComment Associative array of comment data * @return bool */ private static function sendCommentEmails($articleRow, $newComment) { # Is this a reply comment $isReply = $newComment['type'] === 'reply'; # Get a new Query builder $Query = self::$Kanso->Database()->Builder(); # Get all the comments from the article into a multi-array $allComments = self::buildCommentTree(self::$Kanso->Query->get_comments((int) $articleRow['id'], false)); # Get all the emails that are subscibed to the entire article $allEmails = self::getAllCommentEmails($allComments); # Get all the admin email address $adminEmails = $Query->SELECT('email')->FROM('users')->WHERE('status', '=', 'confirmed')->AND_WHERE('role', '=', 'administrator')->AND_WHERE('email_notifications', '=', true)->FIND_ALL(); # Get all the emails that are subscribed to the thread $threadEmails = []; $parentComment = []; if ($isReply) { $threadEmails = self::getThreadEmails(self::getTopCommentThread($newComment, $allComments)); $parentComment = self::$Kanso->Query->get_comment($newComment['parent']); } # Build an array with comment variables to send email $website = self::$Kanso->Environment['KANSO_WEBSITE_NAME']; $commentVars = ['name' => $newComment['name'], 'id' => $newComment['id'], 'date' => $newComment['date'], 'articlePermalink' => self::$Kanso->Query->the_permalink($articleRow['id']), 'articleTitle' => $articleRow['title'], 'avatar' => self::$Kanso->Query->get_avatar($newComment['email'], 20, true), 'content' => self::cleanHTMLTags($newComment['html_content']), 'websiteLink' => self::$Kanso->Environment['HTTP_HOST'], 'website' => $website]; # If this is a reply we need the parent comment if ($isReply) { # Append the parent comment to the comment vars array $commentVars['parent'] = ['name' => $parentComment['name'], 'id' => $parentComment['id'], 'date' => $parentComment['date'], 'avatar' => self::$Kanso->Query->get_avatar($parentComment['email'], 20, true), 'content' => self::cleanHTMLTags($parentComment['html_content'])]; } $msg = $isReply ? \Kanso\Templates\Templater::getTemplate($commentVars, 'EmailReplyComment') : \Kanso\Templates\Templater::getTemplate($commentVars, 'EmailStandAloneComment'); # Send emails to thread subscribers if ($isReply && !empty($threadEmails)) { foreach ($threadEmails as $emailAddress => $name) { # Don't send emails to the peson commenting if ($emailAddress === $newComment['email']) { continue; } # Don't send emails to admins if (\Kanso\Utility\Arr::inMulti($emailAddress, $adminEmails)) { continue; } # Send the email \Kanso\Utility\Mailer::sendHTMLEmail($emailAddress, $website, 'no-reply@' . $website, 'Someone just replied to a comment at you made at ' . $website . ' on ' . $articleRow['title'] . '.', $msg); } } # Send email to all subscribers if (!empty($allEmails)) { foreach ($allEmails as $emailAddress => $name) { # Don't send emails to the peson commenting if ($emailAddress === $newComment['email']) { continue; } # Don't send email twice to people who have subscribed to their own comment # as well as the entire article if (isset($threadEmails[$emailAddress])) { continue; } # Don't send emails to admins if (\Kanso\Utility\Arr::inMulti($emailAddress, $adminEmails)) { continue; } \Kanso\Utility\Mailer::sendHTMLEmail($emailAddress, $website, 'no-reply@' . $website, 'A new comment was made at ' . $website . ' on ' . $articleRow['title'], $msg); } } # Send the email to all the admins on the Kanso blog $admins = $Query->SELECT('*')->FROM('users')->WHERE('status', '=', 'confirmed')->AND_WHERE('role', '=', 'administrator')->FIND_ALL(); foreach ($admins as $admin) { # Don't send emails to the peson commenting if ($admin['email'] === $newComment['email']) { continue; } # Add the admin to the comment variables $commentVars['admin'] = $admin; # Reset the email message $msg = \Kanso\Templates\Templater::getTemplate($commentVars, 'EmailAdminComment'); # Send the email \Kanso\Utility\Mailer::sendHTMLEmail($admin['email'], $website, 'no-reply@' . $website, 'A new comment was made at ' . $website . ' on ' . $articleRow['title'], $msg); } }