Page MenuHomeMnkras Phabricator

No OneTemporary

diff --git a/controller.php b/controller.php
new file mode 100644
index 0000000..8abeec5
--- /dev/null
+++ b/controller.php
@@ -0,0 +1,67 @@
+<?php
+namespace Concrete\Package\LoginNotification;
+
+use Concrete\Core\Logging\Logger;
+use Detection\MobileDetect;
+use Request;
+
+class Controller extends \Package
+{
+
+ protected $pkgHandle = 'login_notification';
+ protected $appVersionRequired = '5.7.4';
+ protected $pkgVersion = '0.9.1';
+
+ public function getPackageDescription()
+ {
+ return t("Get notifications when users login.");
+ }
+
+ public function getPackageName()
+ {
+ return t("Login Notification");
+ }
+
+ public function install()
+ {
+ parent::install();
+
+ // Make sure we load everything.
+ $this->on_start();
+ }
+
+ public function on_start()
+ {
+ \Events::addListener('on_user_login', function ($event) {
+ /* @type \Concrete\Core\User\Event\User $event */
+ //\Log::addInfo(print_r($ue, true));
+ /* @type \User $ue */
+ $ue = $event->getUserObject();
+ $ui = \UserInfo::getByID($ue->getUserID());
+
+ $ip_s = \Core::make('ip');
+ $ip_addr = $ip_s->getRequestIP();
+ $ip_formatted = $ip_addr->getIp($ip_addr::FORMAT_IP_STRING);
+ $req = Request::getInstance();
+ $user_agent = $req->headers->get('User-Agent');
+
+ $mail = \Core::make('mail');
+
+ if (\Config::get('concrete.user.registration.email_registration')) {
+ $mail->addParameter('uName', $ui->getUserEmail());
+ } else {
+ $mail->addParameter('uName', $ui->getUserName());
+ }
+ $mail->addParameter('ip_address', $ip_formatted);
+ $mail->addParameter('user_agent', $user_agent);
+ $mail->addParameter('date_time', date('F j, Y, g:i A T'));
+ $mail->addParameter('sitename', \Config::get('concrete.site'));
+
+ $mail->to($ui->getUserEmail());
+ $mail->load('login_notification', 'login_notification');
+ @$mail->sendMail();
+ });
+
+ }
+
+}
diff --git a/mail/login_notification.php b/mail/login_notification.php
new file mode 100644
index 0000000..f50db64
--- /dev/null
+++ b/mail/login_notification.php
@@ -0,0 +1,53 @@
+<?php
+defined('C5_EXECUTE') or die("Access Denied.");
+
+$subject = t("%s - Login from a new computer", $sitename);
+
+/**
+ * HTML BODY START
+ */
+ob_start();
+?>
+ <h2><?php echo t('Login Notification'); ?></h2>
+ <?php echo t('Dear %s,', $uName); ?><br />
+ <br />
+ <?php echo t('Your account on %s as been logged in on a new computer.', $sitename); ?><br />
+ <br />
+ <?php echo t('Date and Time: %s', $date_time);?><br />
+ <?php echo t('User Agent: %s', $user_agent);?><br />
+ <br />
+ <?php echo t('If the information above looks familiar, you can disregard this email.'); ?><br />
+ <br />
+ <?php echo t('If you have not signed in to %s recently and believe someone may have accessed your account,
+ login to %s and change your password as soon as possible.', $sitename, $sitename); ?><br />
+
+<?php
+$bodyHTML = ob_get_clean();
+/**
+ * HTML BODY END
+ *
+ * ======================
+ *
+ * PLAIN TEXT BODY START
+ */
+ob_start();
+
+ echo t('Login Notification');
+
+ echo t('Dear %s,', $uName);
+
+ echo t('Your account on %s as been logged in on a new computer.', $sitename);
+
+ echo t('Date and Time: %s', $date_time);
+ echo t('User Agent: %s', $user_agent);
+
+ echo t('If the information above looks familiar, you can disregard this email.');
+
+ echo t('If you have not signed in to %s recently and believe someone may have accessed your account,
+ login to %s and change your password as soon as possible.', $sitename, $sitename);
+
+$body = ob_get_clean();
+ob_end_clean();
+/**
+ * PLAIN TEXT BODY END
+ */
\ No newline at end of file

File Metadata

Mime Type
text/x-diff
Expires
Sat, Nov 23, 7:22 AM (1 d, 15 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
264790

Event Timeline