2016-03-28 08:26:48 +00:00
|
|
|
<?php
|
2017-06-15 22:56:12 +00:00
|
|
|
|
|
|
|
namespace LoginNotify;
|
|
|
|
|
2018-08-05 17:44:58 +00:00
|
|
|
use EchoEvent;
|
2017-06-15 22:56:12 +00:00
|
|
|
use EchoEventPresentationModel;
|
|
|
|
use Message;
|
|
|
|
use SpecialPage;
|
|
|
|
|
|
|
|
class PresentationModel extends EchoEventPresentationModel {
|
2016-03-28 08:26:48 +00:00
|
|
|
|
|
|
|
/**
|
2017-03-17 20:26:31 +00:00
|
|
|
* Show an user avatar.
|
2016-03-28 08:26:48 +00:00
|
|
|
*
|
2017-06-16 00:11:58 +00:00
|
|
|
* @return string Name of icon
|
2016-03-28 08:26:48 +00:00
|
|
|
*/
|
|
|
|
public function getIconType() {
|
2017-03-17 20:26:31 +00:00
|
|
|
return 'LoginNotify-user-avatar';
|
2016-03-28 08:26:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-04-27 22:00:48 +00:00
|
|
|
* Link to help page on mediawiki
|
2016-03-28 08:26:48 +00:00
|
|
|
*
|
2017-06-16 00:11:58 +00:00
|
|
|
* @return array URL to link to
|
2016-03-28 08:26:48 +00:00
|
|
|
*/
|
|
|
|
public function getPrimaryLink() {
|
2017-04-27 22:00:48 +00:00
|
|
|
return [
|
2017-08-11 03:55:11 +00:00
|
|
|
'url' => 'https://mediawiki.org/wiki/Help:Login_notifications',
|
2017-04-28 18:41:18 +00:00
|
|
|
'label' => $this->msg( 'loginnotify-primary-link' )->text()
|
2017-04-27 22:00:48 +00:00
|
|
|
];
|
2016-03-28 08:26:48 +00:00
|
|
|
}
|
|
|
|
|
2017-04-28 18:41:18 +00:00
|
|
|
/**
|
|
|
|
* Define the email subject string
|
|
|
|
*
|
2017-06-16 01:12:39 +00:00
|
|
|
* @return Message Email subject
|
2017-04-28 18:41:18 +00:00
|
|
|
*/
|
|
|
|
public function getSubjectMessage() {
|
|
|
|
switch ( $this->event->getType() ) {
|
|
|
|
case 'login-fail-known':
|
|
|
|
case 'login-fail-new':
|
|
|
|
$msg = $this->msg( 'notification-loginnotify-login-fail-email-subject' );
|
|
|
|
$msg->params( $this->getUser()->getName() );
|
|
|
|
$msg->params( $this->event->getExtraParam( 'count', 0 ) );
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
$msg = $this->msg( 'notification-loginnotify-login-success-email-subject' );
|
|
|
|
$msg->params( $this->getUser()->getName() );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return $msg;
|
|
|
|
}
|
|
|
|
|
2016-03-28 08:26:48 +00:00
|
|
|
/**
|
2017-04-26 17:59:48 +00:00
|
|
|
* Include the number of attempts in the message if needed
|
2016-03-28 08:26:48 +00:00
|
|
|
*
|
|
|
|
* @return Message
|
|
|
|
*/
|
|
|
|
public function getHeaderMessage() {
|
2017-04-20 18:14:04 +00:00
|
|
|
switch ( $this->event->getType() ) {
|
2017-07-11 22:01:21 +00:00
|
|
|
// Known IP? Don't bundle because we issue notifications after every 5 attempts anyway
|
2017-04-20 18:14:04 +00:00
|
|
|
case 'login-fail-known':
|
2017-04-26 17:59:48 +00:00
|
|
|
$msg = $this->msg( 'notification-known-header-login-fail' );
|
|
|
|
$msg->params( $this->event->getExtraParam( 'count', 0 ) );
|
2017-04-20 18:14:04 +00:00
|
|
|
break;
|
2017-07-11 22:01:21 +00:00
|
|
|
// New IP?
|
2017-04-20 18:14:04 +00:00
|
|
|
case 'login-fail-new':
|
2017-07-11 22:01:21 +00:00
|
|
|
// If it's a bundle, pass it the bundle count as param
|
2017-04-26 17:59:48 +00:00
|
|
|
if ( $this->isBundled() ) {
|
2017-04-20 18:14:04 +00:00
|
|
|
$msg = $this->msg( 'notification-new-bundled-header-login-fail' );
|
2018-08-05 17:44:58 +00:00
|
|
|
$totalAttempts = array_reduce( $this->getBundledEvents(), function ( $sum, EchoEvent $event ) {
|
|
|
|
return $sum + $event->getExtraParam( 'count', 0 );
|
|
|
|
}, 0 );
|
|
|
|
$msg->params( $totalAttempts );
|
2017-04-20 18:14:04 +00:00
|
|
|
} else {
|
2017-07-11 22:01:21 +00:00
|
|
|
// If the bundle is read or user goes to Special:Notifications, show
|
|
|
|
// one notification per attempt (aligned with how unbundled bundles work)
|
2017-04-26 17:59:48 +00:00
|
|
|
$msg = $this->msg( 'notification-new-unbundled-header-login-fail' );
|
|
|
|
$msg->params( $this->event->getExtraParam( 'count', 0 ) );
|
2017-04-20 18:14:04 +00:00
|
|
|
}
|
|
|
|
break;
|
2017-04-26 17:59:48 +00:00
|
|
|
default:
|
2017-07-10 17:41:49 +00:00
|
|
|
$msg = $this->msg( 'notification-header-login-success', $this->getUser()->getName() );
|
2017-04-07 21:48:57 +00:00
|
|
|
}
|
2017-04-20 18:14:04 +00:00
|
|
|
return $msg;
|
2016-03-28 08:26:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-03-17 20:26:31 +00:00
|
|
|
* Get links to be used in the notification
|
|
|
|
*
|
|
|
|
* @return array Link to Special:ChangePassword
|
2016-03-28 08:26:48 +00:00
|
|
|
*/
|
|
|
|
public function getSecondaryLinks() {
|
2017-03-17 20:26:31 +00:00
|
|
|
$changePasswordLink = [
|
|
|
|
'url' => SpecialPage::getTitleFor( 'ChangePassword' )->getFullURL(),
|
|
|
|
'label' => $this->msg( 'changepassword' )->text(),
|
|
|
|
'description' => '',
|
|
|
|
'icon' => 'lock',
|
|
|
|
'prioritized' => true,
|
|
|
|
];
|
|
|
|
|
|
|
|
return [ $changePasswordLink ];
|
2016-03-28 08:26:48 +00:00
|
|
|
}
|
2018-08-05 17:44:58 +00:00
|
|
|
|
2016-03-28 08:26:48 +00:00
|
|
|
}
|