public function authenticate()
{
if ($this->is_admin || !empty($this->username)) {
$params = array('username' => $this->username);
} elseif (!empty($this->email)) {
$params = array('email' => $this->email);
}
$user = isset($params) ? $this->em->getRepository('Newscoop\\Entity\\User')->findOneBy($params) : null;
if (empty($user)) {
return new \Zend_Auth_Result(\Zend_Auth_Result::FAILURE_IDENTITY_NOT_FOUND, NULL);
}
if (!$user->isActive()) {
return new \Zend_Auth_Result(\Zend_Auth_Result::FAILURE_UNCATEGORIZED, NULL);
}
if ($this->is_admin && !$user->isAdmin()) {
return new \Zend_Auth_Result(\Zend_Auth_Result::FAILURE_UNCATEGORIZED, NULL);
}
if (!$this->is_external && !$user->checkPassword($this->password)) {
return new \Zend_Auth_Result(\Zend_Auth_Result::FAILURE_CREDENTIAL_INVALID, NULL);
}
$user->setLastLogin(new \DateTime());
$this->em->flush();
// store updated password
return new \Zend_Auth_Result(\Zend_Auth_Result::SUCCESS, $user->getId());
}