Files
sysPass/inc/UserLdap.class.php
nuxsmin 50ea4e0f28 * [FIX] Fixed issue on copy password to clipboard on Chrome browser. Related #140. Thanks to @basil-twisleton
* [FIX] Fixed English translation. Related #140.Thanks to @basil-twisleton
* [FIX] Fixed displaying required field when it is a select tag. Related #140.Thanks to @basil-twisleton
* [FIX] Fixed issue when adding an user from LDAP when no group/profile is set (disabled by default). Fixes #157
* [MOD] Modified behavior when adding a new customer from account page. Related #140.Thanks to @basil-twisleton
* [MOD] Updated German translation. Thanks to @wagnst
2015-10-26 00:31:23 +01:00

149 lines
4.7 KiB
PHP

<?php
/**
* sysPass
*
* @author nuxsmin
* @link http://syspass.org
* @copyright 2012-2015 Rubén Domínguez nuxsmin@syspass.org
*
* This file is part of sysPass.
*
* sysPass 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.
*
* sysPass 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 sysPass. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace SP;
defined('APP_ROOT') || die(_('No es posible acceder directamente a este archivo'));
/**
* Class UserLdap
*
* @package SP
*/
class UserLdap
{
/**
* Crear un nuevo usuario en la BBDD con los datos de LDAP.
* Esta función crea los usuarios de LDAP en la BBDD para almacenar infomación del mismo
* y utilizarlo en caso de fallo de LDAP
*
* @param User $User
* @return bool
*/
public static function newUserLDAP(User $User)
{
$passdata = UserPass::makeUserPassHash($User->getUserPass());
$groupId = Config::getValue('ldap_defaultgroup', 0);
$profileId = Config::getValue('ldap_defaultprofile', 0);
$query = 'INSERT INTO usrData SET '
. 'user_name = :name,'
. 'user_groupId = :groupId,'
. 'user_login = :login,'
. 'user_pass = :pass,'
. 'user_hashSalt = :hashSalt,'
. 'user_email = :email,'
. 'user_notes = :notes,'
. 'user_profileId = :profileId,'
. 'user_isLdap = 1,'
. 'user_isDisabled = :isDisabled';
$data['name'] = $User->getUserName();
$data['login'] = $User->getUserLogin();
$data['pass'] = $passdata['pass'];
$data['hashSalt'] = $passdata['salt'];
$data['email'] = $User->getUserEmail();
$data['notes'] = _('Usuario de LDAP');
$data['groupId'] = $groupId;
$data['profileId'] = $profileId;
$data['isDisabled'] = ($groupId === 0 || $profileId === 0) ? 1 : 0;
if (DB::getQuery($query, __FUNCTION__, $data) === false) {
return false;
}
if (!$groupId || !$profileId) {
$Log = new Log(_('Activación Cuenta'));
$Log->addDescription(_('Su cuenta está pendiente de activación.'));
$Log->addDescription(_('En breve recibirá un email de confirmación.'));
$Log->writeLog();
Email::sendEmail($Log, $User->getUserEmail(), false);
}
Log::writeNewLogAndEmail(_('Nuevo usuario de LDAP'), sprintf("%s (%s)", $User->getUserName(), $User->getUserLogin()));
return true;
}
/**
* Actualiza los datos de los usuarios de LDAP en la BBDD.
*
* @return bool
*/
public static function updateLDAPUserInDB(User $User)
{
$passdata = UserPass::makeUserPassHash($User->getUserPass());
$query = 'UPDATE usrData SET '
. 'user_pass = :pass,'
. 'user_hashSalt = :hashSalt,'
. 'user_name = :name,'
. 'user_email = :email,'
. 'user_lastUpdate = NOW(),'
. 'user_isLdap = 1 '
. 'WHERE user_id = :id LIMIT 1';
$data['pass'] = $passdata['pass'];
$data['hashSalt'] = $passdata['salt'];
$data['name'] = $User->getUserName();
$data['email'] = $User->getUserEmail();
$data['id'] = UserUtil::getUserIdByLogin($User->getUserLogin());
return DB::getQuery($query, __FUNCTION__, $data);
}
/**
* Comprobar si un usuario autentifica mediante LDAP
* .
*
* @param string $userLogin con el login del usuario
* @return bool
*/
public static function checkUserIsLDAP($userLogin)
{
$query = 'SELECT BIN(user_isLdap) AS user_isLdap FROM usrData WHERE user_login = :login LIMIT 1';
$data['login'] = $userLogin;
$queryRes = DB::getResults($query, __FUNCTION__, $data);
return ($queryRes !== false && intval($queryRes->user_isLdap) === 1);
}
/**
* Comprobar si los datos del usuario de LDAP están en la BBDD.
*
* @return bool
*/
public static function checkLDAPUserInDB($userId)
{
$query = 'SELECT user_login FROM usrData WHERE user_login = :login LIMIT 1';
$data['login'] = $userId;
return (DB::getQuery($query, __FUNCTION__, $data) === true && DB::$lastNumRows === 1);
}
}