-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontroller.php
87 lines (76 loc) · 2.43 KB
/
controller.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<?php
namespace Concrete\Package\MdNoAccountShare;
use Concrete\Core\Package\Package;
use Concrete\Core\Session\SessionValidator as CoreSessionValidator;
use Concrete\Core\Session\SessionValidatorInterface;
use Concrete\Core\User\Event\User;
use Macareux\NoAccountShare\SessionValidator;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\HttpFoundation\Session\Session;
class Controller extends Package
{
/**
* The minimum concrete5 version compatible with this package.
*
* @var string
*/
protected $appVersionRequired = '8.5.0';
/**
* The handle of this package.
*
* @var string
*/
protected $pkgHandle = 'md_no_account_share';
/**
* The version number of this package.
*
* @var string
*/
protected $pkgVersion = '0.1';
/**
* @see https://documentation.concretecms.org/developers/packages/adding-custom-code-to-packages
*
* @var string[]
*/
protected $pkgAutoloaderRegistries = [
'src' => '\Macareux\NoAccountShare',
];
/**
* Get the translated name of the package.
*
* @return string
*/
public function getPackageName()
{
return t('Macareux Prevent Account Sharing');
}
/**
* Get the translated package description.
*
* @return string
*/
public function getPackageDescription()
{
return t('Prevent each user has more than one active session simultaneously.');
}
public function on_start()
{
$app = $this->app;
$app->bind(SessionValidatorInterface::class, SessionValidator::class);
$app->singleton(CoreSessionValidator::class, SessionValidator::class);
/** @var EventDispatcherInterface $director */
$director = $app->make('director');
$director->addListener('on_user_login', function ($event) use ($app) {
/** @var User $event */
/** @var SessionValidator $sessionValidator */
$sessionValidator = $app->make(CoreSessionValidator::class);
if ($sessionValidator->hasActiveSession()) {
/** @var int $lastLogin Unix Timestamp */
$lastLogin = $event->getUserObject()->getUserInfoObject()->getLastLogin();
/** @var Session $session */
$session = $app->make('session');
$session->set('uLastLogin', $lastLogin);
}
});
}
}