本文整理汇总了PHP中Roles::model方法的典型用法代码示例。如果您正苦于以下问题:PHP Roles::model方法的具体用法?PHP Roles::model怎么用?PHP Roles::model使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Roles
的用法示例。
在下文中一共展示了Roles::model方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: authenticate
public function authenticate()
{
$record = Usuario::model()->findByAttributes(array('nombre' => $this->username));
$conexion = Yii::app()->db;
$consulta = "SELECT nombre, clave FROM usuario ";
$consulta .= "WHERE nombre='" . $this->username . "' AND ";
$consulta .= "clave='" . $this->password . "'";
$resultado = $conexion->createCommand($consulta)->query();
$resultado->bindColumn(1, $this->username);
$resultado->bindColumn(2, $this->password);
while ($resultado->read() !== false) {
$this->errorCode = self::ERROR_NONE;
$this->_id = $record->id;
//bien
$role = Roles::model()->findByPk($record->IdRol);
//bien
$this->setState('role', $role->NOMBRE);
//bien
return !$this->errorCode;
}
/*$users=array(
// username => password
'demo'=>'demo',
'admin'=>'admin',
);
if(!isset($users[$this->username]))
$this->errorCode=self::ERROR_USERNAME_INVALID;
elseif($users[$this->username]!==$this->password)
$this->errorCode=self::ERROR_PASSWORD_INVALID;
else
$this->errorCode=self::ERROR_NONE;
return !$this->errorCode;*/
}
示例2: actionGroup
/**
* @Author: bb - recopy ANH DUNG May 12, 2014
* @Todo: phân quyền cho group
*/
public function actionGroup($id)
{
if (in_array($id, Roles::$aRoleRestrict)) {
$this->redirect(Yii::app()->createAbsoluteUrl('admin/roles'));
}
$this->pageTitle = Yii::app()->params['title'] . ' - Group Privilege';
$mGroup = Roles::model()->findByPk($id);
try {
if (isset($_POST['submit'])) {
foreach ($this->aControllers as $keyController => $aController) {
$mController = Controllers::getByName($keyController);
if ($mController) {
$mController->addGroupRoles($this->postArrayCheckBoxToAllowDenyValue($keyController), $id);
$this->setNotifyMessage(NotificationType::Success, 'Successful Update');
}
}
$this->refresh();
}
$this->render('group', array('id' => $id, 'mGroup' => $mGroup, 'actions' => $this->listActionsCanAccess));
} catch (Exception $exc) {
Yii::log("Uid: " . Yii::app()->user->id . " Exception " . $exc->getMessage(), 'error');
$code = 404;
if (isset($exc->statusCode)) {
$code = $exc->statusCode;
}
if ($exc->getCode()) {
$code = $exc->getCode();
}
throw new CHttpException($code, $exc->getMessage());
}
}
示例3: authenticate
/**
* 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()
{
$user = User::model()->findByAttributes(array('user_id' => $this->username));
if ($user === null) {
$this->errorCode = self::ERROR_USERNAME_INVALID;
}
if (Yii::app()->getModule('admin')->encrypting($this->password) !== $user->password) {
$this->errorCode = self::ERROR_PASSWORD_INVALID;
} else {
if ($user->status == 0 && Yii::app()->getModule('admin')->loginNotActiv == false) {
$this->errorCode = self::ERROR_STATUS_NOTACTIV;
} else {
if ($user->status == -1) {
$this->errorCode = self::ERROR_STATUS_BAN;
} else {
$role = $user->user_role;
$role_model = Roles::model()->findByPk($role);
if ($role_model->role == "admin") {
$this->_id = $user->id;
$this->username = $user->agency_name;
$this->errorCode = self::ERROR_NONE;
$this->setState('user_role', $role_model->role);
} else {
$this->errorCode = self::ERROR_USERNAME_INVALID;
}
}
}
}
return !$this->errorCode;
}
示例4: loadModel
public function loadModel($id)
{
$model = Roles::model()->findByPk($id);
if ($model === null) {
throw new CHttpException(404, 'The requested page does not exist.');
}
return $model;
}
示例5: roleValidator
/**
* @param string $attribute the name of the attribute to be validated
* @param array $params options specified in the validation rule
*/
public function roleValidator($attribute, $params)
{
$roles = Roles::model()->registration_roles()->findAll();
foreach ($roles as $role) {
if ($role->name === $this->{$attribute}) {
return true;
}
}
$this->addError($attribute, 'Specify a right role!');
}
示例6: array
<?php
$account_id;
?>
<div>
<div>
Module:
<?php
$modelModule = Roles::model()->getRoles();
echo CHtml::dropDownList('assign_roles_account', '', CHtml::listData($modelModule, 'lb_record_primary_key', 'role_name'), array());
echo CHtml::button('add', array('onclick' => 'add_roles_account();return false;', 'class' => 'btn btn-default', 'style' => 'margin-bottom: 10px;margin-left:10px;'));
?>
</div>
<div id="contentai-account-role">
<?php
$this->renderPartial('permission.views.account._form_account_role', array('account_id' => $account_id));
?>
</div>
</div>
<script type="text/javascript">
function add_roles_account()
{
var account_id = <?php
echo $account_id;
?>
;
var role_id = $('#assign_roles_account').val();
$.ajax({
type:'POST',
示例7: actionShowAttributes
public function actionShowAttributes($role)
{
$criteria = new CDbCriteria();
$criteria->condition = 'role='.$role;
$dataProvider = new CActiveDataProvider('RoleAttribute', array(
'criteria'=>$criteria,
));
$model = Roles::model()->findByPk($role);
$this->render('showRoleAttributes',array(
'model'=>$model,
'dataProvider'=>$dataProvider,
));
}
示例8: getNameRoleById
public static function getNameRoleById($role_id)
{
$model = Roles::model()->findByPk($role_id);
if ($model) {
return $model->role_name;
}
return '';
}
示例9: actionGetRole
/**
* Echo out a series of inputs for a role editor page.
*
* This method is called via AJAX from the "Edit Role" portion of the "Manage Roles"
* page. Upon selection of a role in the dropdown on that page, this method
* finds all relevant information about the role and echoes it back as a form
* to allow for editing of the role.
*/
public function actionGetRole()
{
if (isset($_POST['Roles'])) {
$id = $_POST['Roles']['name'];
$role = Roles::model()->findByAttributes(array('name' => $id));
if (!$role) {
echo "";
exit;
}
$id = $role->id;
$roles = RoleToUser::model()->findAllByAttributes(array('roleId' => $id));
$users = array();
foreach ($roles as $link) {
if ($link->type == 'user') {
$user = User::model()->findByPk($link->userId);
if (isset($user)) {
$users[] = $user->username;
}
} else {
$group = Groups::model()->findByPk($link->userId);
if (isset($group)) {
$users[] = $group->id;
}
}
/* end x2temp */
}
$allUsers = User::model()->findAll('status="1"');
$selected = array();
$unselected = array();
foreach ($users as $user) {
$selected[] = $user;
}
foreach ($allUsers as $user) {
$unselected[CHtml::encode($user->username)] = CHtml::encode($user->firstName . " " . $user->lastName);
}
/* x2temp */
$groups = Groups::model()->findAll();
foreach ($groups as $group) {
$unselected[$group->id] = CHtml::encode($group->name);
}
/* end x2temp */
unset($unselected['admin']);
$sliderId = 'editTimeoutSlider';
$textfieldId = 'editTimeout';
if (isset($_GET['mode']) && in_array($_GET['mode'], array('edit', 'exception'))) {
// Handle whether this was called from editRole or roleException, they
// need different IDs to work on the same page.
$sliderId .= "-" . $_GET['mode'];
$textfieldId .= "-" . $_GET['mode'];
}
$timeoutSet = $role->timeout !== null;
echo "\n <div class='row' id='set-session-timeout-row'>\n <input id='set-session-timeout' type='checkbox' class='left' " . ($timeoutSet ? 'checked="checked"' : '') . ">\n <label>" . Yii::t('admin', 'Enable Session Timeout') . "</label>\n </div>\n ";
echo "<div id='timeout-row' class='row' " . ($timeoutSet ? '' : "style='display: none;'") . ">";
echo Yii::t('admin', 'Set role session expiration time (in minutes).');
echo "<br />";
$this->widget('zii.widgets.jui.CJuiSlider', array('value' => $role->timeout / 60, 'options' => array('min' => 5, 'max' => 1440, 'step' => 5, 'change' => "js:function(event,ui) {\n \$('#" . $textfieldId . "').val(ui.value);\n \$('#save-button').addClass('highlight');\n }", 'slide' => "js:function(event,ui) {\n \$('#" . $textfieldId . "').val(ui.value);\n }"), 'htmlOptions' => array('style' => 'width:340px;margin:10px 9px;', 'id' => $sliderId)));
echo CHtml::activeTextField($role, 'timeout', array('id' => $textfieldId, 'disabled' => $role->timeout !== null ? '' : 'disabled'));
echo "</div>";
Yii::app()->clientScript->registerScript('timeoutScript', "\n \$('#set-session-timeout').change (function () {\n if (\$(this).is (':checked')) {\n \$('#timeout-row').slideDown ();\n \$('#" . $textfieldId . "').removeAttr ('disabled');\n } else {\n \$('#timeout-row').slideUp ();\n \$('#" . $textfieldId . "').attr ('disabled', 'disabled');\n }\n });\n \$('#" . $textfieldId . "').val( \$('#" . $sliderId . "').slider('value') );\n ", CClientScript::POS_READY);
echo "<script>";
Yii::app()->clientScript->echoScripts();
echo "</script>";
echo "<div id='users'><label>Users</label>";
echo CHtml::dropDownList('users[]', $selected, $unselected, array('class' => 'multiselect', 'multiple' => 'multiple', 'size' => 8));
echo "</div>";
$fields = Fields::model()->findAllBySql("SELECT * FROM x2_fields ORDER BY modelName ASC");
$viewSelected = array();
$editSelected = array();
$fieldUnselected = array();
$fieldPerms = RoleToPermission::model()->findAllByAttributes(array('roleId' => $role->id));
foreach ($fieldPerms as $perm) {
if ($perm->permission == 2) {
$viewSelected[] = $perm->fieldId;
$editSelected[] = $perm->fieldId;
} else {
if ($perm->permission == 1) {
$viewSelected[] = $perm->fieldId;
}
}
}
foreach ($fields as $field) {
$fieldUnselected[$field->id] = X2Model::getModelTitle($field->modelName) . " - " . $field->attributeLabel;
}
echo "<br /><label>View Permissions</label>";
echo CHtml::dropDownList('viewPermissions[]', $viewSelected, $fieldUnselected, array('class' => 'multiselect', 'multiple' => 'multiple', 'size' => 8));
echo "<br /><label>Edit Permissions</label>";
echo CHtml::dropDownList('editPermissions[]', $editSelected, $fieldUnselected, array('class' => 'multiselect', 'multiple' => 'multiple', 'size' => 8));
}
}
示例10: array
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "Powered by
* X2Engine" logo. If the display of the logo is not reasonably feasible for
* technical reasons, the Appropriate Legal Notices must display the words
* "Powered by X2Engine".
*****************************************************************************************/
LoginThemeHelper::init();
Yii::app()->clientScript->registerCssFile($this->module->assetsUrl . '/css/users.css');
$groups = array();
foreach (Groups::model()->findAll() as $group) {
$groups[$group->id] = $group->name;
}
$roles = array();
foreach (Roles::model()->findAll() as $role) {
$roles[$role->id] = $role->name;
}
?>
<!--<div class="page-title icon users"><h2>
<?php
echo Yii::t('users', 'Create {user}', array('{user}' => Modules::displayName(false)));
?>
</h2></div> -->
<div id="container">
<div id="login-box-outer">
<div id="login-box">
<?php
echo $this->renderPartial('_form', array('update' => false, 'model' => $user, 'roles' => $roles, 'groups' => $groups, 'selectedGroups' => array(), 'selectedRoles' => array(), 'flag' => true, 'create' => true, 'status' => false));
?>
</div>
示例11: actionEdit
public function actionEdit($id)
{
$typeAccount = Yii::app()->user->hasState('typeAccountCurrent') ? Yii::app()->user->getState('typeAccountCurrent') : null;
$this->pageTitle = $typeAccount != null ? 'Edit Account Of ' . $typeAccount : 'Edit Account';
$model = $this->loadModel($id);
$passwordOld = $model->s_password;
$storeOld = $model->s_store_id;
$store = Store::model()->findAll('i_account_manager = 0');
$model->s_password = 'posNail@2015';
if (isset($_POST['User'])) {
$flagSave = false;
$flagChangeImage = false;
$model->attributes = $_POST['User'];
$levelAccount = Yii::app()->user->level;
$role = Roles::model()->findByPk($model->i_user_role);
if ($model->s_store_id != $storeOld) {
$checkStore = Store::model()->find('pk_s_id = :pk_s_id', array(':pk_s_id' => $model->s_store_id));
if ($checkStore == null) {
$model->s_store_id = $storeOld;
$model->addError('s_store_id', 'Store invalid');
}
$storeManager = $checkStore->userManager();
if ($storeManager != null) {
$model->addError('i_user_role', 'The store has managed. Please select user type other or stores other');
}
}
$model->i_manager = 0;
$model->i_device_max = intval($model->i_device_max);
$model->i_flag_sync = 1;
if ($model->i_user_role == 3) {
$model->i_manager = 1;
}
if ($role == null) {
$model->addError('i_user_role', 'Type not exist');
} elseif ($levelAccount < $role->level) {
$model->addError('i_user_role', 'Your are not authorized to make this type of account');
}
if ($model->s_password != '' && $model->s_password != 'posNail@2015' && $model->s_password != $passwordOld) {
$password = sha1($model->s_secret_code . sha1($model->s_password . $model->s_secret_code));
$model->s_password = $password;
} else {
$model->s_password = $passwordOld;
}
$image = CUploadedFile::getInstance($model, 's_image_server');
if ($image != null) {
if ($image->saveAs(Yii::app()->basePath . '/../data/users/' . $model->s_image_server)) {
$imgthumb = Yii::app()->phpThumb->create(Yii::app()->basePath . '/../data/users/' . $model->s_image_server);
$imgthumb->resize(240, 240);
$imgthumb->save(Yii::app()->basePath . '/../data/users/240x240_' . $model->s_image_server);
$imgthumb->resize(120, 120);
$imgthumb->save(Yii::app()->basePath . '/../data/users/120x120_' . $model->s_image_server);
$flagChangeImage = true;
} else {
$model->addError('s_image_server', 'Upload image fail');
}
}
if (count($model->errors) == 0) {
if ($model->save()) {
$flagSave = true;
} elseif ($flagChangeImage == true) {
$flagSave = false;
@unlink(Yii::app()->basePath . '/../data/users/' . $model->s_image_server);
@unlink(Yii::app()->basePath . '/../data/users/240x240_' . $model->s_image_server);
@unlink(Yii::app()->basePath . '/../data/users/120x120_' . $model->s_image_server);
}
if ($flagSave == true) {
$this->redirect(array('index'));
}
}
}
$this->render('create', array('model' => $model, 'store' => $store, 'typeAccount' => $typeAccount));
}
示例12: array
<?php
echo CHtml::link('Advanced Search', '#', array('class' => 'search-button'));
?>
<div class="search-form" style="display:none">
<?php
$this->renderPartial('_search', array('model' => $model));
?>
</div><!-- search-form -->
</br>
<div class="form" style="padding-left: 0px;">
<div class="row">
<label class="required" for="UsersActions_user_id">Role: <span class="required">*</span></label>
<?php
echo CHtml::dropDownList('roles', 1, CHtml::listData(Roles::model()->findAll(), 'id', 'role_name'));
?>
<?php
//echo $form->error($model,'user_id');
?>
</div>
</div>
<?php
$this->widget('zii.widgets.grid.CGridView', array('id' => 'controllers-grid', 'dataProvider' => $model->search(), 'columns' => array(array('header' => 'S/N', 'type' => 'raw', 'value' => '$row+1', 'headerHtmlOptions' => array('width' => '30px', 'style' => 'text-align:center;'), 'htmlOptions' => array('style' => 'text-align:center;')), array('class' => 'CButtonColumn', 'template' => ControllerActionsName::createIndexButtonRoles($actions, array('update'))), 'controller_name', 'module_name', 'actions')));
?>
<div id="re"></div>
<script type="text/javascript">
示例13: hasRole
public static function hasRole($user, $role)
{
if (is_numeric($role)) {
$lookup = RoleToUser::model()->findByAttributes(array('userId' => $user, 'roleId' => $role));
return isset($lookup);
} else {
$roleRecord = Roles::model()->findByAttributes(array('name' => $role));
if (isset($roleRecord)) {
$lookup = RoleToUser::model()->findByAttributes(array('userId' => $user, 'roleId' => $roleRecord->id));
return isset($lookup);
} else {
return false;
}
}
}
示例14: array
echo $form->labelEx($model, 'tbl_user_email');
?>
<?php
echo $form->textField($model, 'tbl_user_email', array('size' => 60, 'maxlength' => 255));
?>
<?php
echo $form->error($model, 'tbl_user_email');
?>
</div>
<div class="row">
<?php
echo $form->labelEx($model, 'tbl_roles_idtbl_role');
?>
<?php
$models = Roles::model()->findAll(array('order' => 'tbl_role_title'));
$list = CHtml::listData($models, 'idtbl_role', 'tbl_role_title');
echo CHtml::dropDownList('Users[tbl_roles_idtbl_role]', $model->tblRolesIdtblRole, $list);
?>
<?php
echo $form->error($model, 'tbl_roles_idtbl_role');
?>
</div>
<div class="row">
<?php
echo $form->labelEx($model, 'tbl_user_notifications');
?>
<?php
echo $form->checkBox($model, 'tbl_user_notifications', array('Yes', 'No'));
?>
示例15: array
$this->breadcrumbs = array('Usuarios');
?>
<title><?php
echo Yii::app()->controller->module->getName() . " >> " . $this->pageTitle;
?>
</title>
<?php
$this->widget('zii.widgets.CBreadcrumbs', array('links' => $this->breadcrumbs, 'htmlOptions' => array('class' => 'breadcrumb')));
?>
<div class="page-header">
<h1>Catálogo Usuarios </h1>
</div>
<?php
echo TbHtml::linkButton('Crear Registro', array('color' => TbHtml::BUTTON_COLOR_PRIMARY, 'method' => 'post', 'submit' => array('usuarios/create')));
?>
<br /><br />
<?php
$this->widget('zii.widgets.grid.CGridView', array('id' => 'usuarios-grid', 'dataProvider' => $model->search(), 'filter' => $model, 'summaryText' => "Mostrando {start} – {end} de {count} resultados", 'pager' => array('header' => 'Ir a la pagina:', 'firstPageLabel' => '< <', 'prevPageLabel' => 'Anterior', 'nextPageLabel' => 'Siguiente', 'lastPageLabel' => '>>'), 'htmlOptions' => array('style' => 'word-wrap:break-word; width:1250px; font-family:"Times New Roman"'), 'columns' => array(array('name' => 'IdUsuario', 'htmlOptions' => array('width' => '50')), array('name' => 'username', 'htmlOptions' => array('width' => '50')), array('name' => 'NumeroDocumento', 'htmlOptions' => array('width' => '50', 'align' => 'right'), 'value' => function ($model) {
return Yii::app()->format->formatNumber($model->NumeroDocumento);
}), array('name' => 'PrimerNombre', 'htmlOptions' => array('width' => '50')), array('name' => 'SegundoNombre', 'htmlOptions' => array('width' => '50')), array('name' => 'PrimerApellido', 'htmlOptions' => array('width' => '50')), array('name' => 'SegundoApellido', 'htmlOptions' => array('width' => '100')), array('name' => 'EmailUsuario', 'htmlOptions' => array('width' => '100')), 'IdRol' => array('name' => 'IdRol', 'htmlOptions' => array('width' => '100'), 'value' => function ($model) {
return Roles::getNombreRol($model->IdRol);
}, 'filter' => CHtml::listData(Roles::model()->findAll(array('order' => 'NombreRol')), 'IdRol', 'NombreRol')), 'IdEstadoRegistro' => array('name' => 'IdEstadoRegistro', 'htmlOptions' => array('width' => '80'), 'value' => function ($model) {
return EstadosRegistro::getNombreEstado($model->IdEstadoRegistro);
}, 'filter' => CHtml::listData(EstadosRegistro::model()->findAll(array('order' => 'NombreEstadoRegistro')), 'IdEstadoRegistro', 'NombreEstadoRegistro')), array('class' => 'CButtonColumn', 'htmlOptions' => array('width' => '120')))));