Add possibility to limit users
This commit is contained in:
parent
4bf8c98fcc
commit
b2bd7e0d25
@ -196,6 +196,14 @@ $dolibarr_main_force_https='0';
|
||||
# $dolibarr_main_prod='1';
|
||||
|
||||
|
||||
# dolibarr_main_limit_users
|
||||
# Can set a limit on the number of users it will be possible to create
|
||||
# (the superadmin not included), can be used for a restricted mode.
|
||||
# Default value: 0 (unlimited)
|
||||
# Examples:
|
||||
# $dolibarr_main_limit_users='0';
|
||||
|
||||
|
||||
# This is an development feature to allow external components to overwrite
|
||||
# some Dolibarr kernel files to be overwritten by versions provided by
|
||||
# third parties modules.
|
||||
|
||||
@ -107,4 +107,5 @@ ConfirmCreateLogin=Are you sure you want to create a Dolibarr account for this m
|
||||
ConfirmCreateThirdParty=Are you sure you want to create a third party for this member ?
|
||||
LoginToCreate=Login to create
|
||||
NameToCreate=Name of third party to create
|
||||
YourRole=Your roles
|
||||
YourRole=Your roles
|
||||
YourQuotaOfUsersIsReached=Your quota of users is reached !
|
||||
@ -107,4 +107,5 @@ ConfirmCreateLogin=Êtes-vous sûr de vouloir créer un compte Dolibarr pour cet
|
||||
ConfirmCreateThirdParty=Êtes-vous sûr de vouloir créer un tiers pour cet adhérent ?
|
||||
LoginToCreate=Login à créer
|
||||
NameToCreate=Nom du tiers à créer
|
||||
YourRole=Vos rôles
|
||||
YourRole=Vos rôles
|
||||
YourQuotaOfUsersIsReached=Votre quota d'utilisateurs est atteint !
|
||||
@ -162,6 +162,8 @@ if (empty($dolibarr_main_db_encryption)) $dolibarr_main_db_encryption=0;
|
||||
$conf->db->dolibarr_main_db_encryption = $dolibarr_main_db_encryption;
|
||||
if (empty($dolibarr_main_db_cryptkey)) $dolibarr_main_db_cryptkey='';
|
||||
$conf->db->dolibarr_main_db_cryptkey = $dolibarr_main_db_cryptkey;
|
||||
if (empty($dolibarr_main_limit_users)) $dolibarr_main_limit_users=0;
|
||||
$conf->file->main_limit_users = $dolibarr_main_limit_users;
|
||||
if (defined('TEST_DB_FORCE_TYPE')) $conf->db->type=constant('TEST_DB_FORCE_TYPE'); // For test purpose
|
||||
// Identifiant autres
|
||||
$conf->file->main_authentication = empty($dolibarr_main_authentication)?'':$dolibarr_main_authentication;
|
||||
|
||||
@ -4,7 +4,7 @@
|
||||
* Copyright (c) 2004-2010 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||
* Copyright (C) 2004 Sebastien Di Cintio <sdicintio@ressource-toi.org>
|
||||
* Copyright (C) 2004 Benoit Mortier <benoit.mortier@opensides.be>
|
||||
* Copyright (C) 2005-2009 Regis Houssin <regis@dolibarr.fr>
|
||||
* Copyright (C) 2005-2010 Regis Houssin <regis@dolibarr.fr>
|
||||
* Copyright (C) 2005 Lionel Cousteix <etm_ltd@tiscali.co.uk>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
@ -23,16 +23,9 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
\file htdocs/user.class.php
|
||||
\brief Fichier de la classe utilisateur
|
||||
\author Rodolphe Quiedeville
|
||||
\author Jean-Louis Bergamo
|
||||
\author Laurent Destailleur
|
||||
\author Sebastien Di Cintio
|
||||
\author Benoit Mortier
|
||||
\author Regis Houssin
|
||||
\author Lionel Cousteix
|
||||
\version $Id$
|
||||
* \file htdocs/user.class.php
|
||||
* \brief Fichier de la classe utilisateur
|
||||
* \version $Id$
|
||||
*/
|
||||
|
||||
require_once(DOL_DOCUMENT_ROOT ."/core/class/commonobject.class.php");
|
||||
@ -1799,6 +1792,36 @@ class User extends CommonObject
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Return number of existing users
|
||||
* \param limitToActive limit to active users
|
||||
* \return int Number of users
|
||||
*/
|
||||
function getNbOfUsers($limitToActive=0)
|
||||
{
|
||||
global $conf;
|
||||
|
||||
$sql = "SELECT count(rowid) as nb";
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX."user";
|
||||
$sql.= " WHERE entity = ".$conf->entity;
|
||||
if ($limitToActive) $sql.= " AND statut = 1";
|
||||
|
||||
$resql=$this->db->query($sql);
|
||||
if ($resql)
|
||||
{
|
||||
$obj = $this->db->fetch_object($resql);
|
||||
$nb=$obj->nb;
|
||||
|
||||
$this->db->free($resql);
|
||||
return $nb;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->error=$this->db->error();
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
* Copyright (C) 2002-2003 Jean-Louis Bergamo <jlb@j1b.org>
|
||||
* Copyright (C) 2004-2010 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||
* Copyright (C) 2004 Eric Seigne <eric.seigne@ryxeo.com>
|
||||
* Copyright (C) 2005-2009 Regis Houssin <regis@dolibarr.fr>
|
||||
* Copyright (C) 2005-2010 Regis Houssin <regis@dolibarr.fr>
|
||||
* Copyright (C) 2005 Lionel Cousteix <etm_ltd@tiscali.co.uk>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
@ -150,11 +150,21 @@ if ($_POST["action"] == 'add' && $canadduser)
|
||||
$message='<div class="error">'.$langs->trans("LoginNotDefined").'</div>';
|
||||
$action="create"; // Go back to create page
|
||||
}
|
||||
|
||||
$edituser = new User($db);
|
||||
|
||||
if (!empty($conf->file->main_limit_users))
|
||||
{
|
||||
$nb = $edituser->getNbOfUsers(1);
|
||||
if ($nb >= $conf->file->main_limit_users)
|
||||
{
|
||||
$message='<div class="error">'.$langs->trans("YourQuotaOfUsersIsReached").'</div>';
|
||||
$action="create"; // Go back to create page
|
||||
}
|
||||
}
|
||||
|
||||
if (! $message)
|
||||
{
|
||||
$edituser = new User($db);
|
||||
|
||||
$edituser->nom = $_POST["nom"];
|
||||
$edituser->prenom = $_POST["prenom"];
|
||||
$edituser->login = $_POST["login"];
|
||||
|
||||
Loading…
Reference in New Issue
Block a user