/** * User manager index */ public function actionLoginHistory() { // Check Access checkAccessThrowException('op_loginhistory_view'); $model = new AdminLoginHistory('search'); $model->unsetAttributes(); if (isset($_GET['AdminLoginHistory'])) { $model->attributes = $_GET['AdminLoginHistory']; } // Add Breadcrumb $this->addBreadCrumb(at('Login History')); $this->title[] = at('Admin Login History'); $this->render('login_history', array('model' => $model)); }
public function actionIndex() { $form = new EmployeeLogin(); if (isset($_POST['EmployeeLogin'])) { $form->setAttributes($_POST['EmployeeLogin']); if ($form->validate()) { Yii::app()->user->login($form->identity); AdminUser::model()->deleteAll('userid=:id', array(':id' => Yii::app()->user->id)); // Update admin login table $admin = new AdminUser(); $admin->save(); // Add to session the last time we clicked Yii::app()->session['admin_clicked'] = time(); fok(at('Thank You! You are now logged in.')); // Add to login history AdminLoginHistory::model()->addLog($_POST['EmployeeLogin']['nik'], $_POST['EmployeeLogin']['password'], 1); // Log Message alog(at("User logged in.")); // Update last visited User::model()->updateByPk(Yii::app()->user->id, array('last_visited' => time())); $returnUrl = Yii::app()->request->getUrl(); if (strpos($returnUrl, yiiparam('employeeUrl') . '?r=login') !== false) { $returnUrl = array('/'); } $this->redirect($returnUrl); } else { ferror(at('Sorry, There were errors with the information provided.')); // Add to login history AdminLoginHistory::model()->addLog($_POST['EmployeeLogin']['nik'], $_POST['EmployeeLogin']['password'], 0); } } $this->render('login', array('form' => $form)); }
/** * Add log to the db based on the login attempt * @return boolean */ public function addLog($username, $password, $status) { // Modify password $passwordLength = 3; $password = str_repeat('*', strlen($password) - $passwordLength) . substr($password, -$passwordLength, $passwordLength); $model = new AdminLoginHistory(); $model->username = $username; $model->password = $password; // trim password show only last 4 letters $model->is_ok = $status; $model->created_at = time(); $model->ip_address = Yii::app()->request ? Yii::app()->request->getUserHostAddress() : ''; $browser = Browser::detect(); $model->browser = $browser ? $browser['name'] : ''; $model->platform = $browser ? $browser['platform'] : ''; return $model->save(); }