148 lines
4.2 KiB
PHP
148 lines
4.2 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
class UsuarioModule extends CWebModule {
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @var string
|
||
|
|
* @desc hash method (md5,sha1 or algo hash function http://www.php.net/manual/en/function.hash.php)
|
||
|
|
*/
|
||
|
|
public $hash = 'md5';
|
||
|
|
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @var boolean
|
||
|
|
* @desc enviar un mail con una URL de activación cuando un usuario se registre
|
||
|
|
*/
|
||
|
|
public $enviarMailActivacion = true;
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @var boolean
|
||
|
|
* @desc activar automáticamente los usuario que se registren
|
||
|
|
* sin necesidad de realizar la activación
|
||
|
|
* (sólo si $enviarMailActivacion = false)
|
||
|
|
*/
|
||
|
|
public $activarAutomaticamente = false;
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @var boolean
|
||
|
|
* @desc Permitir entrar a un usuario registrado aunque no esté activado
|
||
|
|
*/
|
||
|
|
public $loginSinActivacion = false;
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @var boolean
|
||
|
|
* @desc entrar en el sistema después del registro de un usuario
|
||
|
|
* (sólo si $loginSinActivacion = true o $activarAutomaticamente = true)
|
||
|
|
*/
|
||
|
|
public $autoLogin = true;
|
||
|
|
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @var boolean
|
||
|
|
* @desc allow auth for is not active user
|
||
|
|
*/
|
||
|
|
public $loginNotActiv = false;
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @var boolean
|
||
|
|
* @desc activate user on registration (only $sendActivationMail = false)
|
||
|
|
*/
|
||
|
|
public $activeAfterRegister = false;
|
||
|
|
|
||
|
|
|
||
|
|
public $tablaUsuarios = 'tbl_usuarios';
|
||
|
|
public $tablaPerfiles = 'tbl_perfiles';
|
||
|
|
public $tablaCamposPerfiles = 'tbl_perfiles_campos';
|
||
|
|
|
||
|
|
public $defaultScope = array(
|
||
|
|
'with' => array('perfil'),
|
||
|
|
);
|
||
|
|
|
||
|
|
public $captcha = array('registration' => true);
|
||
|
|
|
||
|
|
public $fieldsMessage = '';
|
||
|
|
|
||
|
|
public $nombreRemitenteEMail = 'admin@admin.com';
|
||
|
|
|
||
|
|
public $urlLogin = "/usuario/logout";
|
||
|
|
public $urlPerfil = "/usuario/perfil";
|
||
|
|
public $urlRegistro = "/usuario/registro";
|
||
|
|
public $urlRecuperar = "/usuario/registro/recuperar";
|
||
|
|
public $urlActivar = "/usuario/registro/activar";
|
||
|
|
public $returnUrl = array();
|
||
|
|
|
||
|
|
public $relations = array();
|
||
|
|
|
||
|
|
static private $_esAdmin;
|
||
|
|
static private $_listaUsuarios = array();
|
||
|
|
|
||
|
|
public function init() {
|
||
|
|
$this->setImport(array(
|
||
|
|
'usuario.models.*',
|
||
|
|
'usuario.models.formularios.*',
|
||
|
|
'usuario.components.*',
|
||
|
|
));
|
||
|
|
}
|
||
|
|
|
||
|
|
public static function t($str = '', $params = array(), $dic = 'usuario') {
|
||
|
|
if (Yii::t("UsuarioModule", $str) == $str)
|
||
|
|
return Yii::t("UsuarioModule." . $dic, $str, $params);
|
||
|
|
else
|
||
|
|
return Yii::t("UsuarioModule", $str, $params);
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @return hash string.
|
||
|
|
*/
|
||
|
|
public static function cifrar($string = "") {
|
||
|
|
$hash = Yii::app()->getModule('usuario')->hash;
|
||
|
|
if ($hash == "md5")
|
||
|
|
return md5($string);
|
||
|
|
if ($hash == "sha1")
|
||
|
|
return sha1($string);
|
||
|
|
else
|
||
|
|
return hash($hash, $string);
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Return safe user data.
|
||
|
|
* @param user id not required
|
||
|
|
* @return user object or false
|
||
|
|
*/
|
||
|
|
public static function usuario($id = 0, $clearCache = false) {
|
||
|
|
if (!$id && !Yii::app()->user->isGuest)
|
||
|
|
$id = Yii::app()->user->id;
|
||
|
|
if ($id) {
|
||
|
|
if (!isset(self::$_listaUsuarios[$id]) || $clearCache)
|
||
|
|
self::$_listaUsuarios[$id] = Usuario::model()->with(array('perfil'))->findbyPk($id);
|
||
|
|
return self::$_listaUsuarios[$id];
|
||
|
|
}
|
||
|
|
else
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
|
||
|
|
public static function doCaptcha($place = '') {
|
||
|
|
// if (!extension_loaded('gd'))
|
||
|
|
// return false;
|
||
|
|
// if (in_array($place, Yii::app()->getModule('usuario')->captcha))
|
||
|
|
// return Yii::app()->getModule('usuario')->captcha[$place];
|
||
|
|
// return false;
|
||
|
|
}
|
||
|
|
|
||
|
|
public static function esAdmin() {
|
||
|
|
if (Yii::app()->user->isGuest)
|
||
|
|
return false;
|
||
|
|
else {
|
||
|
|
if (!isset(self::$_esAdmin)) {
|
||
|
|
if (self::usuario()->esSuperusuario)
|
||
|
|
self::$_esAdmin = true;
|
||
|
|
else
|
||
|
|
self::$_esAdmin = false;
|
||
|
|
}
|
||
|
|
return self::$_esAdmin;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
}
|