/** * Logs in the user using the given username and password in the model. * @return boolean whether login is successful */ public function login() { if ($this->_identity === null) { $this->_identity = new UserIdentity($this->username, $this->password); $this->_identity->authenticate(); } if ($this->_identity->errorCode === UserIdentity::ERROR_NONE) { $duration = $this->rememberMe ? 3600 * 24 * 30 : 0; // 30 days Yii::app()->user->login($this->_identity, $duration); $userInfo = UserModel::model()->find('username=:username', array(':username' => $this->username)); Yii::app()->session['userInfo'] = array('uid' => $userInfo->uid, 'username' => $userInfo->username, 'nickname' => $userInfo->nickname, 'group_id' => $userInfo->group_id); //log $log = new ActiveRecordLog(); $log->description = Yii::t('admin/activeLog', 'User {username} login', array('username' => Yii::app()->user->Name)); $log->action = 'LOGIN'; $log->model = __CLASS__; $log->idModel = $userInfo->uid; $log->field = ''; $log->created_at = new CDbExpression('NOW()'); $log->username = Yii::app()->user->id; $log->save(); return true; } else { return false; } }
/** * @param $event */ public function afterDelete($event) { $log = new ActiveRecordLog(); $log->description = Yii::t('admin/activeLog', 'User {username} deleted {className}[{id}]', array('username' => Yii::app()->user->Name, 'className' => get_class($this->Owner), 'id' => $this->Owner->getPrimaryKey())); $log->action = 'DELETE'; $log->model = get_class($this->Owner); $log->idModel = $this->Owner->getPrimaryKey(); $log->field = ''; $log->created_at = new CDbExpression('NOW()'); $log->username = Yii::app()->user->id; $log->save(); }
public function actionIndex() { $dataProvider = new CActiveDataProvider('ActiveRecordLog', ['sort' => ['defaultOrder' => 'creationdate DESC, id DESC']]); $model = new ActiveRecordLog('search'); if (!Yii::app()->request->isAjaxRequest && !Yii::app()->request->getParam('ajax')) { $this->render('list', ['dataProvider' => $dataProvider, 'model' => $model]); } else { $model->setAttributes(Yii::app()->request->getParam('ActiveRecordLog')); $dataProvider = $model->search(); $dataProvider->setSort(['defaultOrder' => 'creationdate DESC, id DESC']); $this->renderPartial('_list', ['dataProvider' => $dataProvider, 'model' => $model]); } }
public function afterDelete($event) { $log = new ActiveRecordLog(); $log->description = 'EL usuario ' . Yii::app()->user->Name . ' ha borrado ' . get_class($this->Owner) . '[' . $this->Owner->getPrimaryKey() . '].'; $log->action = 'BORRADO'; $log->model = get_class($this->Owner); $log->idModel = $this->Owner->getPrimaryKey(); $log->idModelReal = $this->Owner->getPrimaryKey() . ''; $log->field = ''; $log->creationdate = new CDbExpression('NOW()'); $log->userid = Yii::app()->user->id; $log->save(); }
public function afterDelete($event) { if (!Yii::app() instanceof CConsoleApplication) { $log = new ActiveRecordLog(); $log->description = 'User ' . Yii::app()->user->name . ' deleted ' . get_class($this->owner) . '[' . $this->owner->getPrimaryKey() . '].'; $log->action = 'DELETE'; $log->model = get_class($this->owner); $log->idModel = $this->owner->getPrimaryKey(); $log->field = ''; $log->creationdate = date("Y-m-d H:i:s"); $log->userid = Yii::app()->user->isGuest ? null : Yii::app()->user->id; $log->save(); } }
public function safeUp() { /** @var ActiveRecordLog $log */ foreach (ActiveRecordLog::model()->findAll('`description` LIKE :text', [':text' => '%Guest%']) as $log) { $log->userid = null; $log->save(); } }
public function safeUp() { $this->addColumn('{{group_replace}}', 'owner', 'string NOT NULL'); $replaces = GroupReplace::model()->findAll(); foreach ($replaces as $replace) { $log = ActiveRecordLog::model()->findByAttributes(['model' => 'GroupReplace', 'idModel' => $replace->id, 'action' => 'CREATE']); if ($log) { $log = explode(' ', $log->description); $replace->owner = $log[1]; $replace->save(); } } }
public function run() { $this->widget('zii.widgets.grid.CGridView', array('id' => 'alkardex-grid', 'dataProvider' => ActiveRecordLog::model()->search_por_modelo($this->modeloapintar, $this->clave), 'itemsCssClass' => 'table table-striped table-bordered table-hover', 'columns' => array(array('name' => 'action', 'header' => 'Accion'), array('name' => 'Usuario', 'header' => 'Usuario', 'value' => 'Yii::app()->user->um->loadUserById($data->userid)->username'), array('name' => 'nombrecampo', 'header' => 'Campo afectado'), array('name' => 'creationdate', 'header' => 'Fecha'), array('name' => 'oldvalue', 'header' => 'Valor anterior'), array('name' => 'newvalue', 'header' => 'Valor actualizado')))); }