Authentification refactor
This commit is contained in:
@@ -28,9 +28,22 @@ class Auth
|
||||
{
|
||||
protected $container;
|
||||
|
||||
protected $authentication;
|
||||
|
||||
protected $config;
|
||||
|
||||
protected $entityManager;
|
||||
|
||||
public function __construct(\Espo\Core\Container $container)
|
||||
{
|
||||
$this->container = $container;
|
||||
|
||||
$this->entityManager = $this->container->get('entityManager');
|
||||
$this->config = $this->container->get('config');
|
||||
|
||||
$authenticationMethod = $this->config->get('authenticationMethod', 'Espo');
|
||||
$authenticationClassName = "\\Espo\\Core\\Utils\\Authentication\\" . $authenticationMethod;
|
||||
$this->authentication = new $authenticationClassName($this->config, $this->entityManager);
|
||||
}
|
||||
|
||||
public function useNoAuth($isAdmin = false)
|
||||
@@ -49,24 +62,14 @@ class Auth
|
||||
|
||||
public function login($username, $password)
|
||||
{
|
||||
$GLOBALS['log']->debug('AUTH: Try to authenticate');
|
||||
$GLOBALS['log']->debug('AUTH: Try to authenticate');
|
||||
|
||||
$hash = md5($password);
|
||||
|
||||
$entityManager = $this->container->get('entityManager');
|
||||
$entityManager = $this->entityManager;
|
||||
|
||||
$authToken = $entityManager->getRepository('AuthToken')->where(array('token' => $password))->findOne();
|
||||
if ($authToken) {
|
||||
$hash = $authToken->get('hash');
|
||||
}
|
||||
|
||||
$user = $entityManager->getRepository('User')->findOne(array(
|
||||
'whereClause' => array(
|
||||
'userName' => $username,
|
||||
'password' => $hash
|
||||
),
|
||||
));
|
||||
|
||||
|
||||
$user = $this->authentication->login($username, $password, $authToken);
|
||||
|
||||
if ($user) {
|
||||
$entityManager->setUser($user);
|
||||
$this->container->setUser($user);
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM - Open Source CRM application.
|
||||
* Copyright (C) 2014 Yuri Kuznetsov, Taras Machyshyn, Oleksiy Avramenko
|
||||
* Website: http://www.espocrm.com
|
||||
*
|
||||
* EspoCRM is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* EspoCRM is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with EspoCRM. If not, see http://www.gnu.org/licenses/.
|
||||
************************************************************************/
|
||||
|
||||
namespace Espo\Core\Utils\Authentication;
|
||||
|
||||
use \Espo\Core\Exceptions\Error;
|
||||
use \Espo\Core\Utils\Config;
|
||||
use \Espo\Core\ORM\EntityManager;
|
||||
|
||||
class Espo
|
||||
{
|
||||
protected $config;
|
||||
|
||||
protected $entityManager;
|
||||
|
||||
public function __construct(Config $config, EntityManager $entityManager)
|
||||
{
|
||||
$this->config = $config;
|
||||
$this->entityManager = $entityManager;
|
||||
}
|
||||
|
||||
|
||||
public function login($username, $password, \Espo\Entities\AuthToken $authToken = null)
|
||||
{
|
||||
if ($authToken) {
|
||||
$hash = $authToken->get('hash');
|
||||
} else {
|
||||
$hash = md5($password);
|
||||
}
|
||||
|
||||
$user = $this->entityManager->getRepository('User')->findOne(array(
|
||||
'whereClause' => array(
|
||||
'userName' => $username,
|
||||
'password' => $hash
|
||||
),
|
||||
));
|
||||
|
||||
return $user;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -74,6 +74,7 @@ return array (
|
||||
'isRotate' => true, /** rotate log files every day */
|
||||
'maxRotateFiles' => 30, /** max number of rotate files */
|
||||
),
|
||||
'authenticationMethod' => 'Espo',
|
||||
'globalSearchEntityList' =>
|
||||
array (
|
||||
0 => 'Account',
|
||||
|
||||
Reference in New Issue
Block a user