Skip to content

Commit 4bbb602

Browse files
Merge pull request #144 from gregorybesson/develop
last login
2 parents 4b735af + a13ba20 commit 4bbb602

File tree

3 files changed

+50
-2
lines changed

3 files changed

+50
-2
lines changed

src/Controller/Frontend/UserController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ public function ajaxauthenticateAction()
351351
if ($user->getState() && $user->getState() === 2) {
352352
$this->getUserService()->getUserMapper()->activate($user);
353353
}
354-
$this->getEventManager()->trigger('login.post', $this, array('user' => $user));
354+
$this->getEventManager()->trigger('authenticate.post', $this, array('user' => $user));
355355
return true;
356356
}
357357

@@ -442,7 +442,7 @@ public function authenticateAction()
442442
}
443443

444444
$user = $this->zfcUserAuthentication()->getIdentity();
445-
$this->getEventManager()->trigger('login.post', $this, array('user' => $user));
445+
$this->getEventManager()->trigger('authenticate.post', $this, array('user' => $user));
446446

447447
if ($this->getOptions()->getUseRedirectParameterIfPresent() && $redirect) {
448448
return $this->redirect()->toUrl($redirect);

src/Entity/User.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,11 @@ class User implements \ZfcUser\Entity\UserInterface, ProviderInterface, InputFil
160160
*/
161161
protected $updated_at;
162162

163+
/**
164+
* @ORM\Column(name="last_login",type="datetime", nullable=true)
165+
*/
166+
protected $lastLogin;
167+
163168
/**
164169
* @ORM\Column(name="registration_source", type="string", length=255, nullable=true)
165170
*/
@@ -762,6 +767,24 @@ public function setUpdatedAt($updated_at)
762767
return $this;
763768
}
764769

770+
/**
771+
* @return the unknown_type
772+
*/
773+
public function getLastLogin()
774+
{
775+
return $this->lastLogin;
776+
}
777+
778+
/**
779+
* @param unknown_type $lastLogin
780+
*/
781+
public function setLastLogin($lastLogin)
782+
{
783+
$this->lastLogin = $lastLogin;
784+
785+
return $this;
786+
}
787+
765788
/**
766789
* Get registration_source
767790
*/

src/Module.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,34 @@ public function onBootstrap($e)
107107
// Redirect strategy associated to BjyAuthorize module
108108
$strategy = new RedirectionStrategy();
109109
$e->getApplication()->getEventManager()->attach(MvcEvent::EVENT_DISPATCH_ERROR, array($strategy, 'onDispatchError'), 200);
110+
111+
$e->getApplication()->getEventManager()->getSharedManager()->attach(
112+
'*',
113+
'authenticate.post',
114+
[$this, 'lastLogin']
115+
);
110116
}
111117
}
112118

119+
/**
120+
* This method updates the last login field of the user
121+
*
122+
* @param MvcEvent $e
123+
* @return array
124+
*/
125+
public function lastLogin(\Zend\EventManager\Event $e)
126+
{
127+
$user = $e->getParam('user');
128+
$user->setLastLogin(new \DateTime());
129+
130+
$userMapper = $e->getTarget()->getServiceManager()->get('zfcuser_user_mapper');
131+
132+
$user = $userMapper->update($user);
133+
134+
return $user;
135+
136+
}
137+
113138
/**
114139
* This method get the cron config for this module an add them to the listener
115140
*

0 commit comments

Comments
 (0)