From ee57c9223c682945f4d3d86bbd87beeabc67deb1 Mon Sep 17 00:00:00 2001 From: yuri Date: Mon, 2 Feb 2015 12:22:37 +0200 Subject: [PATCH] User:isActive --- application/Espo/Core/Utils/Auth.php | 5 +++++ application/Espo/Entities/User.php | 9 +++++++-- application/Espo/Resources/i18n/en_US/User.json | 4 +++- application/Espo/Resources/layouts/User/detail.json | 5 +++-- application/Espo/Resources/metadata/entityDefs/User.json | 5 +++++ application/Espo/Services/User.php | 6 +++++- 6 files changed, 28 insertions(+), 6 deletions(-) diff --git a/application/Espo/Core/Utils/Auth.php b/application/Espo/Core/Utils/Auth.php index dd6b1f965f..97420983fa 100644 --- a/application/Espo/Core/Utils/Auth.php +++ b/application/Espo/Core/Utils/Auth.php @@ -23,6 +23,7 @@ namespace Espo\Core\Utils; use \Espo\Core\Exceptions\Error; +use \Espo\Core\Exceptions\Forbidden; class Auth { @@ -72,6 +73,10 @@ class Auth $user = $this->authentication->login($username, $password, $authToken); if ($user) { + if (!$user->isActive()) { + $GLOBALS['log']->debug("AUTH: Trying to login as user '".$user->get('userName')."' which is not active."); + return false; + } $entityManager->setUser($user); $this->container->setUser($user); $GLOBALS['log']->debug('AUTH: Result of authenticate is [true]'); diff --git a/application/Espo/Entities/User.php b/application/Espo/Entities/User.php index 1b127da502..6ba843dad7 100644 --- a/application/Espo/Entities/User.php +++ b/application/Espo/Entities/User.php @@ -18,14 +18,19 @@ * * 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\Entities; class User extends \Espo\Core\Entities\Person -{ +{ public function isAdmin() { return $this->get('isAdmin'); } + + public function isActive() + { + return $this->get('isActive'); + } } diff --git a/application/Espo/Resources/i18n/en_US/User.json b/application/Espo/Resources/i18n/en_US/User.json index a75003c9de..82d9f989fe 100644 --- a/application/Espo/Resources/i18n/en_US/User.json +++ b/application/Espo/Resources/i18n/en_US/User.json @@ -13,7 +13,8 @@ "passwordConfirm": "Confirm Password", "newPassword": "New Password", "newPasswordConfirm": "Confirm New Password", - "avatar": "Avatar" + "avatar": "Avatar", + "isActive": "Is Active" }, "links": { "teams": "Teams", @@ -36,6 +37,7 @@ "defaultTeam": "All records created by this user will be related to this team by default.", "userName": "Letters a-z, numbers 0-9 and underscores are allowed.", "isAdmin": "Admin user can access everything.", + "isActive": "If unchecked then user won't be able to login.", "teams": "Teams which this user belongs to. Access control level is inherited from team's roles.", "roles": "Additional access roles. Use it if user doesn't belong to any team or you need to extend access control level only for this user." }, diff --git a/application/Espo/Resources/layouts/User/detail.json b/application/Espo/Resources/layouts/User/detail.json index 4be7752a27..4bfbaa1a92 100644 --- a/application/Espo/Resources/layouts/User/detail.json +++ b/application/Espo/Resources/layouts/User/detail.json @@ -10,8 +10,9 @@ { "label": "Teams and Access Control", "rows": [ - [{"name":"defaultTeam"}, {"name":"isAdmin"}], - [{"name":"teams"}, {"name":"roles"}] + [{"name":"defaultTeam"}, {"name":"isActive"}], + [{"name":"teams"}, {"name":"isAdmin"}], + [{"name":"roles"}, false] ] } ] diff --git a/application/Espo/Resources/metadata/entityDefs/User.json b/application/Espo/Resources/metadata/entityDefs/User.json index f7a103409a..fd0245a19d 100644 --- a/application/Espo/Resources/metadata/entityDefs/User.json +++ b/application/Espo/Resources/metadata/entityDefs/User.json @@ -35,6 +35,11 @@ "required": true, "default":"" }, + "isActive": { + "type": "bool", + "tooltip": true, + "default": true + }, "title": { "type": "varchar", "maxLength": 100 diff --git a/application/Espo/Services/User.php b/application/Espo/Services/User.php index 139a7b8771..d698c75088 100644 --- a/application/Espo/Services/User.php +++ b/application/Espo/Services/User.php @@ -135,7 +135,7 @@ class User extends Record $dt = new \DateTime(); $dt->add(new \DateInterval('PT'. self::PASSWORD_CHANGE_REQUEST_LIFETIME . 'M')); - + $job = $this->getEntityManager()->getEntity('Job'); $job->set(array( @@ -200,6 +200,10 @@ class User extends Record $newPassword = $data['password']; $data['password'] = $this->hashPassword($data['password']); } + + if ($id == $this->getUser()->id) { + unset($data['isActive']); + } $user = parent::updateEntity($id, $data); if (!is_null($newPassword)) {