public function getData() { static $_data; if (!isset($_data) && !$this->isGuest) { $_data = SBAdmin::model()->with('group')->findByPk($this->id); } return $_data; }
/** * Displays the admin page */ public function actionIndex() { $this->layout = '//layouts/column1'; $this->pageTitle = Yii::t('sourcebans', 'controllers.admin.index.title'); $this->breadcrumbs = array(Yii::t('sourcebans', 'controllers.admin.index.title')); $this->menu = array(array('label' => Yii::t('sourcebans', 'controllers.admin.admins.title'), 'url' => array('admin/admins'), 'itemOptions' => array('class' => 'admins'), 'visible' => Yii::app()->user->data->hasPermission('ADD_ADMINS', 'DELETE_ADMINS', 'EDIT_ADMINS', 'LIST_ADMINS')), array('label' => Yii::t('sourcebans', 'controllers.admin.bans.title'), 'url' => array('admin/bans'), 'itemOptions' => array('class' => 'bans'), 'visible' => Yii::app()->user->data->hasPermission('ADD_BANS', 'IMPORT_BANS', 'BAN_APPEALS', 'BAN_REPORTS')), array('label' => Yii::t('sourcebans', 'controllers.admin.groups.title'), 'url' => array('admin/groups'), 'itemOptions' => array('class' => 'groups'), 'visible' => Yii::app()->user->data->hasPermission('ADD_GROUPS', 'DELETE_GROUPS', 'EDIT_GROUPS', 'LIST_GROUPS')), array('label' => Yii::t('sourcebans', 'controllers.admin.servers.title'), 'url' => array('admin/servers'), 'itemOptions' => array('class' => 'servers'), 'visible' => Yii::app()->user->data->hasPermission('ADD_SERVERS', 'DELETE_SERVERS', 'EDIT_SERVERS', 'LIST_SERVERS')), array('label' => Yii::t('sourcebans', 'controllers.admin.games.title'), 'url' => array('admin/games'), 'itemOptions' => array('class' => 'games'), 'visible' => Yii::app()->user->data->hasPermission('ADD_GAMES', 'DELETE_GAMES', 'EDIT_GAMES', 'LIST_GAMES')), array('label' => Yii::t('sourcebans', 'controllers.admin.settings.title'), 'url' => array('admin/settings'), 'itemOptions' => array('class' => 'settings'), 'visible' => Yii::app()->user->data->hasPermission('SETTINGS'))); $demosize = Helpers::getDirectorySize(Yii::getPathOfAlias('webroot.demos')); $this->render('index', array('demosize' => Yii::app()->format->formatSize($demosize['size']), 'total_admins' => SBAdmin::model()->count(), 'total_archived_appeals' => SBAppeal::model()->countByAttributes(array('archived' => true)), 'total_archived_reports' => SBReport::model()->countByAttributes(array('archived' => true)), 'total_bans' => SBBan::model()->count(), 'total_blocks' => SBBlock::model()->count(), 'total_appeals' => SBAppeal::model()->countByAttributes(array('archived' => false)), 'total_servers' => SBServer::model()->count(), 'total_reports' => SBReport::model()->countByAttributes(array('archived' => false)))); }
/** * Authenticates a user. * The example implementation makes sure if the username and password * are both 'demo'. * In practical applications, this should be changed to authenticate * against some persistent user identity storage (e.g. database). * @return boolean whether authentication succeeds. */ public function authenticate() { /** @var SBAdmin $admin */ $admin = SBAdmin::model()->find(array('condition' => 'name = :username OR email = :username', 'params' => array(':username' => $this->username))); if ($admin === null) { $this->errorCode = self::ERROR_USERNAME_INVALID; } else { if (!$admin->validatePassword($this->password)) { $this->errorCode = self::ERROR_PASSWORD_INVALID; } else { $this->errorCode = self::ERROR_NONE; $this->_id = $admin->id; $this->username = $admin->name; } } return !$this->errorCode; }
/** * Resets the user password using the given email in the model. * @return boolean whether reset is successful */ public function reset() { /** @var SBAdmin $admin */ $admin = SBAdmin::model()->findByAttributes(array('email' => $this->email)); if ($admin === null) { return false; } $validationKey = Yii::app()->securityManager->generateRandomString(32, false); Yii::app()->mailer->AddAddress($admin->email); Yii::app()->mailer->Subject = Yii::t('sourcebans', 'models.LostPasswordForm.reset.subject'); Yii::app()->mailer->MsgHtml(Yii::t('sourcebans', 'models.LostPasswordForm.reset.body', array('{name}' => $admin->name, '{link}' => Yii::app()->createAbsoluteUrl('default/lostPassword', array('email' => $admin->email, 'key' => $validationKey))))); if (!Yii::app()->mailer->Send()) { return false; } $admin->validation_key = $validationKey; $admin->save(false); return true; }
public function actionAdmins($id) { $this->pageTitle = Yii::t('sourcebans', 'controllers.servers.admins.title'); $this->breadcrumbs = array(Yii::t('sourcebans', 'controllers.admin.index.title') => array('admin/index'), Yii::t('sourcebans', 'controllers.admin.servers.title') => array('admin/servers'), Yii::t('sourcebans', 'controllers.servers.admins.title')); $this->menu = array(array('label' => Yii::t('sourcebans', 'Back'), 'url' => array('admin/servers'))); $admins = SBAdmin::model()->findAll(array('condition' => 'servers.id = :server_id', 'order' => 't.name', 'params' => array(':server_id' => $id), 'with' => array('server_groups' => array('select' => false), 'server_groups.servers' => array('select' => false)))); $this->render('admins', array('admins' => $admins)); }
/** * 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 $id the ID of the model to be loaded * @return SBAdmin the loaded model * @throws CHttpException */ public function loadModel($id) { $model = SBAdmin::model()->findByPk($id); if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } return $model; }
echo $form->label($model, 'length', array('class' => 'control-label')); ?> <div class="controls"> <?php echo $form->dropDownList($model, 'length', SBBan::getTimes(), array('empty' => '- ' . Yii::t('sourcebans', 'None') . ' -')); ?> </div> </div> <div class="control-group"> <?php echo $form->label($model, 'admin_id', array('class' => 'control-label')); ?> <div class="controls"> <?php echo $form->dropDownList($model, 'admin_id', CHtml::listData(SBAdmin::model()->findAll(array('order' => 'name')), 'id', 'name'), array('empty' => '- ' . Yii::t('sourcebans', 'None') . ' -')); ?> </div> </div> <div class="control-group"> <?php echo $form->label($model, 'server_id', array('class' => 'control-label')); ?> <div class="controls"> <?php echo $form->dropDownList($model, 'server_id', CHtml::listData(SBServer::model()->enabled()->with('game')->findAll(array('order' => 'game.name, t.host, t.port')), 'id', 'address', 'game.name'), array('empty' => '- ' . Yii::t('sourcebans', 'None') . ' -')); ?> </div> </div>
/** * Displays the lost password page */ public function actionLostPassword() { $this->pageTitle = Yii::t('sourcebans', 'controllers.default.lostPassword.title'); $this->breadcrumbs = array(Yii::t('sourcebans', 'controllers.default.lostPassword.title')); $model = new LostPasswordForm(); // if it is ajax validation request if (isset($_POST['ajax']) && $_POST['ajax'] === 'lost-password-form') { echo CActiveForm::validate($model); Yii::app()->end(); } // collect user input data if (isset($_POST['LostPasswordForm'])) { $model->attributes = $_POST['LostPasswordForm']; // validate user input and redirect to the previous page if valid if ($model->validate() && $model->reset()) { $this->redirect(Yii::app()->user->returnUrl); } } $email = Yii::app()->request->getQuery('email'); $validationKey = Yii::app()->request->getQuery('key'); if (!empty($email) && !empty($validationKey)) { /** @var SBAdmin $admin */ $admin = SBAdmin::model()->findByAttributes(array('email' => $email, 'validation_key' => $validationKey)); if ($admin === null) { throw new CHttpException(403, 'The validation key does not match the email address for this reset request.'); } $password = Yii::app()->securityManager->generateRandomString(8, false); Yii::app()->mailer->AddAddress($admin->email); Yii::app()->mailer->Subject = Yii::t('sourcebans', 'controllers.default.lostPassword.subject'); Yii::app()->mailer->MsgHtml(Yii::t('sourcebans', 'controllers.default.lostPassword.body', array('{name}' => $admin->name, '{password}' => $password, '{link}' => CHtml::link(Yii::t('sourcebans', 'controllers.default.account.title'), array('default/account'))))); if (!Yii::app()->mailer->Send()) { throw new CHttpException(500, 'Please try again later or contact your system administrator.'); } $admin->new_password = $password; $admin->validation_key = null; $admin->save(false); $this->redirect(Yii::app()->user->homeUrl); } // display the lost password form $this->render('lostpassword', array('model' => $model)); }