Skip to content

Commit

Permalink
Merge pull request #144 from gregorybesson/develop
Browse files Browse the repository at this point in the history
last login
  • Loading branch information
gregorybesson authored May 8, 2019
2 parents 4b735af + a13ba20 commit 4bbb602
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Controller/Frontend/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ public function ajaxauthenticateAction()
if ($user->getState() && $user->getState() === 2) {
$this->getUserService()->getUserMapper()->activate($user);
}
$this->getEventManager()->trigger('login.post', $this, array('user' => $user));
$this->getEventManager()->trigger('authenticate.post', $this, array('user' => $user));
return true;
}

Expand Down Expand Up @@ -442,7 +442,7 @@ public function authenticateAction()
}

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

if ($this->getOptions()->getUseRedirectParameterIfPresent() && $redirect) {
return $this->redirect()->toUrl($redirect);
Expand Down
23 changes: 23 additions & 0 deletions src/Entity/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,11 @@ class User implements \ZfcUser\Entity\UserInterface, ProviderInterface, InputFil
*/
protected $updated_at;

/**
* @ORM\Column(name="last_login",type="datetime", nullable=true)
*/
protected $lastLogin;

/**
* @ORM\Column(name="registration_source", type="string", length=255, nullable=true)
*/
Expand Down Expand Up @@ -762,6 +767,24 @@ public function setUpdatedAt($updated_at)
return $this;
}

/**
* @return the unknown_type
*/
public function getLastLogin()
{
return $this->lastLogin;
}

/**
* @param unknown_type $lastLogin
*/
public function setLastLogin($lastLogin)
{
$this->lastLogin = $lastLogin;

return $this;
}

/**
* Get registration_source
*/
Expand Down
25 changes: 25 additions & 0 deletions src/Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,34 @@ public function onBootstrap($e)
// Redirect strategy associated to BjyAuthorize module
$strategy = new RedirectionStrategy();
$e->getApplication()->getEventManager()->attach(MvcEvent::EVENT_DISPATCH_ERROR, array($strategy, 'onDispatchError'), 200);

$e->getApplication()->getEventManager()->getSharedManager()->attach(
'*',
'authenticate.post',
[$this, 'lastLogin']
);
}
}

/**
* This method updates the last login field of the user
*
* @param MvcEvent $e
* @return array
*/
public function lastLogin(\Zend\EventManager\Event $e)
{
$user = $e->getParam('user');
$user->setLastLogin(new \DateTime());

$userMapper = $e->getTarget()->getServiceManager()->get('zfcuser_user_mapper');

$user = $userMapper->update($user);

return $user;

}

/**
* This method get the cron config for this module an add them to the listener
*
Expand Down

0 comments on commit 4bbb602

Please sign in to comment.