2012-09-20 19:38:42 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
class EquipoController extends Controller {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @return array action filters
|
|
|
|
|
*/
|
|
|
|
|
public function filters() {
|
|
|
|
|
return array(
|
|
|
|
|
'accessControl', // perform access control for CRUD operations
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Specifies the access control rules.
|
|
|
|
|
* This method is used by the 'accessControl' filter.
|
|
|
|
|
* @return array access control rules
|
|
|
|
|
*/
|
|
|
|
|
public function accessRules() {
|
|
|
|
|
return array(
|
|
|
|
|
array('allow', // allow admin user to perform 'admin' and 'delete' actions
|
|
|
|
|
'actions' => array('index'),
|
|
|
|
|
'users' => array('@'),
|
|
|
|
|
),
|
|
|
|
|
array('deny', // deny all users
|
|
|
|
|
'users' => array('*'),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function actionIndex() {
|
|
|
|
|
$invitacion = new FormularioInvitarAgente;
|
|
|
|
|
|
|
|
|
|
if (isset($_POST['FormularioInvitarAgente'])) {
|
|
|
|
|
$invitacion->attributes = $_POST['FormularioInvitarAgente'];
|
|
|
|
|
|
|
|
|
|
if ($invitacion->validate()) {
|
|
|
|
|
$nuevo_usuario = new Usuario('registrar');
|
|
|
|
|
$nuevo_usuario->id_empresa = Yii::app()->user->id_empresa;
|
2012-09-28 18:30:16 +00:00
|
|
|
$nuevo_usuario->tipo = Usuario::TIPO_USUARIO_AGENTE;
|
2012-09-20 19:38:42 +00:00
|
|
|
$nuevo_usuario->nombre = $invitacion->nombre;
|
|
|
|
|
$nuevo_usuario->email = $invitacion->email;
|
|
|
|
|
$nuevo_usuario->password = $nuevo_usuario->encrypt(microtime());
|
|
|
|
|
$nuevo_usuario->estado = Usuario::ESTADO_NOACTIVO;
|
|
|
|
|
$nuevo_usuario->clave_seguridad = $nuevo_usuario->encrypt(microtime() . $nuevo_usuario->password);
|
|
|
|
|
|
|
|
|
|
if ($nuevo_usuario->save()) {
|
2012-09-28 18:30:16 +00:00
|
|
|
$this->enviarMailRegistroAgente($nuevo_usuario);
|
2012-09-20 19:38:42 +00:00
|
|
|
Yii::app()->user->setFlash('success', Yii::t('profind', 'Se ha enviado la invitación a la dirección') . ' ' . $invitacion->email);
|
|
|
|
|
$invitacion = new FormularioInvitarAgente;
|
|
|
|
|
} else {
|
|
|
|
|
Yii::app()->user->setFlash('error', Yii::t('profind', 'Se ha producido un error al registrar la invitación'));
|
|
|
|
|
}
|
|
|
|
|
} else {
|
2012-09-28 18:30:16 +00:00
|
|
|
Yii::app()->user->setFlash('error', Yii::t('profind', 'Se ha producido un error al validar la invitación'));
|
2012-09-20 19:38:42 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-09-30 17:08:01 +00:00
|
|
|
$agentes = Usuario::model()->equipo()->findAll();
|
|
|
|
|
|
|
|
|
|
if (count($agentes) >= Yii::app()->user->subscripcion->producto->n_agentes)
|
|
|
|
|
$invitacion = NULL;
|
|
|
|
|
|
2012-09-20 19:38:42 +00:00
|
|
|
$this->render('index', array(
|
|
|
|
|
'agentes' => $agentes,
|
|
|
|
|
'invitacion' => $invitacion,
|
|
|
|
|
));
|
|
|
|
|
}
|
|
|
|
|
|
2012-09-28 18:30:16 +00:00
|
|
|
/**
|
|
|
|
|
* Envía un mail de registro a un usuario
|
|
|
|
|
* con una URL de confirmación.
|
|
|
|
|
* @param Usuario $usuario Usuario al que se le enviará el mail de registro
|
|
|
|
|
*/
|
|
|
|
|
private function enviarMailRegistroAgente($usuario) {
|
|
|
|
|
Yii::import('ext.yii-mail.YiiMailMessage');
|
|
|
|
|
|
|
|
|
|
$url_activacion = Yii::app()->params['frontpage'] . '?' . 'key=' . $usuario->clave_seguridad . '&email=' . urlencode($usuario->email) . '&x=1';
|
|
|
|
|
|
|
|
|
|
$mensaje = new YiiMailMessage;
|
|
|
|
|
$mensaje->from = Yii::app()->params['email_remitente'];
|
|
|
|
|
$mensaje->setTo($usuario->email);
|
|
|
|
|
$mensaje->subject = Yii::t('profind', 'Complete su registro de agente en PROFIND');
|
|
|
|
|
$mensaje->view = 'registro_agente';
|
|
|
|
|
$mensaje->setBody(array(
|
|
|
|
|
'url' => $url_activacion,
|
|
|
|
|
'email' => $usuario->email
|
|
|
|
|
), 'text/html'
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
Yii::app()->mail->send($mensaje);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2012-09-20 19:38:42 +00:00
|
|
|
/**
|
|
|
|
|
* Returns the data model based on the primary key given in the GET variable.
|
|
|
|
|
* If the data model is not found, an HTTP exception will be raised.
|
|
|
|
|
* @param integer the ID of the model to be loaded
|
|
|
|
|
*/
|
|
|
|
|
public function loadModel($id) {
|
|
|
|
|
$model = Usuario::model()->findByPk($id);
|
|
|
|
|
if ($model === null)
|
2012-09-24 23:14:37 +00:00
|
|
|
throw new CHttpException(404, Yii::t('profind', 'La página solicitada no existe.'));
|
2012-09-20 19:38:42 +00:00
|
|
|
return $model;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Performs the AJAX validation.
|
|
|
|
|
* @param CModel the model to be validated
|
|
|
|
|
*/
|
|
|
|
|
protected function performAjaxValidation($model) {
|
|
|
|
|
if (isset($_POST['ajax']) && $_POST['ajax'] === 'usuario-form') {
|
|
|
|
|
echo CActiveForm::validate($model);
|
|
|
|
|
Yii::app()->end();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|