/** * Displays the 'admins' admin page */ public function actionAdmins() { $this->pageTitle = Yii::t('sourcebans', 'controllers.admin.admins.title'); $this->breadcrumbs = array(Yii::t('sourcebans', 'controllers.admin.index.title') => array('admin/index'), Yii::t('sourcebans', 'controllers.admin.admins.title')); $this->menu = array(array('label' => Yii::t('sourcebans', 'controllers.admin.admins.menu.list'), 'url' => '#list', 'visible' => Yii::app()->user->data->hasPermission('LIST_ADMINS')), array('label' => Yii::t('sourcebans', 'controllers.admin.admins.menu.add'), 'url' => '#add', 'visible' => Yii::app()->user->data->hasPermission('ADD_ADMINS')), array('label' => Yii::t('sourcebans', 'controllers.admin.admins.menu.import'), 'url' => '#import', 'visible' => Yii::app()->user->data->hasPermission('ADD_ADMINS')), array('label' => Yii::t('sourcebans', 'controllers.admin.admins.menu.overrides'), 'url' => '#overrides', 'visible' => Yii::app()->user->data->hasPermission('OVERRIDES')), array('label' => Yii::t('sourcebans', 'controllers.admin.admins.menu.actions'), 'url' => '#actions')); $admin = new SBAdmin(); $admins = new SBAdmin('search'); $admins->unsetAttributes(); // clear any default values if (isset($_GET['SBAdmin'])) { $admins->attributes = $_GET['SBAdmin']; } $actions = new SBAction('search'); $actions->unsetAttributes(); // clear any default values if (isset($_GET['SBAction'])) { $actions->attributes = $_GET['SBAction']; } $overrides = new SBOverride('search'); $overrides->unsetAttributes(); // clear any default values if (isset($_GET['SBOverride'])) { $overrides->attributes = $_GET['SBOverride']; } $this->render('admins', array('actions' => $actions, 'admin' => $admin, 'admins' => $admins, 'overrides' => $overrides)); }
public function testCreate() { $model = new SBAdmin(); $model->name = 'Local'; $model->auth = SBAdmin::AUTH_IP; $model->identity = '127.0.0.1'; $model->setPassword('localhost'); $this->assertTrue($model->save()); }
public function getData() { static $_data; if (!isset($_data) && !$this->isGuest) { $_data = SBAdmin::model()->with('group')->findByPk($this->id); } return $_data; }
/** * 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)); }
<?php echo $form->textField($model, 'name', array('size' => 60, 'maxlength' => 64)); ?> <?php echo $form->error($model, 'name'); ?> </div> </div> <div class="control-group"> <?php echo $form->label($model, 'auth', array('class' => 'control-label')); ?> <div class="controls"> <?php echo $form->dropDownList($model, 'auth', SBAdmin::getAuthTypes()); ?> <?php echo $form->error($model, 'auth'); ?> </div> </div> <div class="control-group"> <?php echo $form->labelEx($model, 'identity', array('class' => 'control-label')); ?> <div class="controls"> <?php echo $form->textField($model, 'identity', array('size' => 60, 'maxlength' => 64)); ?>
/** * 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)); }
$file = fopen($paths['config'] . '/sourcebans.php', 'w'); fwrite($file, $config); fclose($file); // Setup database require WEB_ROOT . 'api.php'; $queries = file_get_contents(dirname(__FILE__) . '/data/install.sql'); $queries = str_replace('{prefix}', $db['prefix'], $queries); foreach (explode(';', $queries) as $query) { if (($query = trim($query)) != '') { Yii::app()->db->createCommand($query)->execute(); } } // Setup web group $group = new SBGroup(); $group->name = 'Owner'; $group->permissions = array('OWNER'); if (!$group->save()) { throw new CException('Failed to save group "' . $group->name . '"'); } // Setup admin $admin = new SBAdmin(); $admin->attributes = $_POST['SBAdmin']; $admin->group_id = $group->id; $admin->new_password = $admin->password; if (!$admin->save()) { throw new CException('Failed to save admin "' . $admin->name . '"'); } } catch (Exception $e) { exit(json_encode(array('error' => $e->getMessage()))); } exit(json_encode(true));