/** The constructor * @access public * @param array $options * @return void */ public function __construct(array $options = null) { parent::__construct($options); $roles = new Roles(); $role_options = $roles->getRoles(); $inst = new Institutions(); $inst_options = $inst->getInsts(); $projecttypes = new ProjectTypes(); $projectype_list = $projecttypes->getTypes(); $this->setName('emailsearch'); ZendX_JQuery::enableForm($this); $message = new Zend_Form_Element_Textarea('messageToUser'); $message->setLabel('Message to user: '******'StringTrim', 'WordChars', 'BasicHtml', 'EmptyParagraph'))->setAttribs(array('rows' => 10))->addFilter('BasicHtml')->addErrorMessage('You must enter a message to your recipient.'); $fullname = new Zend_Form_Element_Text('fullname'); $fullname->setLabel('Send this to: ')->addFilters(array('StringTrim', 'StripTags', 'Purifier'))->setAttrib('size', 30); $email = $this->addElement('text', 'email', array('label' => 'Their email Address', 'size' => '30'))->email; $email->addValidator('EmailAddress')->addFilters(array('StringTrim', 'StripTags', 'StringToLower'))->setRequired(true)->addErrorMessage('Please enter a valid address!'); //Submit button $submit = new Zend_Form_Element_Submit('submit'); $hash = new Zend_Form_Element_Hash('csrf'); $hash->setValue($this->_salt)->setTimeout(60); $this->addElement($hash); $this->addElements(array($fullname, $submit, $message)); $this->addDisplayGroup(array('fullname', 'email', 'messageToUser'), 'details'); $this->details->setLegend('Details: '); $this->addDisplayGroup(array('submit'), 'buttons'); parent::init(); }
function __construct($role_id, $locale_code = "en-us", $config = null, $restricted = null) { // TODO: finish changing this into a params array being passed in // $this->role_id = $params['role_id']; // $this->locale_code = $params['locale_code']; $this->role_id = $role_id; $this->locale_code = $locale_code; if (is_array($this->role_id)) { $all_roles = $this->role_id; } else { $all_roles = array($this->role_id); } $roles_table = new Roles(); foreach ($all_roles as $role) { $all_roles = array_merge($all_roles, $roles_table->getAllAncestors($role)); } $this->all_roles = array_unique($all_roles); return parent::__construct($config); }
static function isAllowed($resource, $module = "default", $username = null) { $users_roles_table = new UsersRoles(); $user_roles = array(); $roles_table = new Roles(); if (!is_null($username)) { $users_roles_db = $users_roles_table->fetchAll($users_roles_table->select()->where("username = ?", $username)); $user_roles = array(); if (count($users_roles_db) > 0) { foreach ($users_roles_db as $role) { $user_roles[] = $role->role_id; } } } else { $user_roles = array($roles_table->getIdByShortname("guest")); } $resource_name = $module . "-@@EXTRA-" . $resource; $out = false; if (Zend_Registry::isRegistered('acl')) { $acl = Zend_Registry::get('acl'); if ($acl->has($resource_name)) { foreach ($user_roles as $role) { if ($acl->isAllowed($role, $resource_name)) { $out = true; } } } } return $out; }
public function __construct($options = null) { parent::__construct($options); $roles = new Roles(); $role_options = $roles->getRoles(); $inst = new Institutions(); $inst_options = $inst->getInsts(); $projecttypes = new ProjectTypes(); $projectype_list = $projecttypes->getTypes(); $this->setName('emailsearch'); ZendX_JQuery::enableForm($this); $decorators = array(array('ViewHelper'), array('Description', array('placement' => 'append', 'class' => 'info')), array('Errors', array('placement' => 'append', 'class' => 'error', 'tag' => 'li')), array('Label'), array('HtmlTag', array('tag' => 'li'))); $message = new Zend_Form_Element_Textarea('messageToUser'); $message->setLabel('Message to user: '******'StringTrim', 'WordChars', 'BasicHtml', 'EmptyParagraph'))->setAttribs(array('rows' => 10))->addFilter('BasicHtml')->addErrorMessage('You must enter a message to your recipient.'); $fullname = new Zend_Form_Element_Text('fullname'); $fullname->setLabel('Send this to: ')->addFilters(array('StringTrim', 'StripTags'))->addValidator('Alnum', false, array('allowWhiteSpace' => true))->setAttrib('size', 30)->setDecorators($decorators); $email = $this->addElement('text', 'email', array('label' => 'Their email Address', 'size' => '30'))->email; $email->addValidator('EmailAddress')->addFilters(array('StringTrim', 'StripTags', 'StringToLower'))->setRequired(true)->addErrorMessage('Please enter a valid address!'); $email->setDecorators($decorators); //Submit button $submit = new Zend_Form_Element_Submit('submit'); $submit->setAttrib('id', 'submit')->setAttrib('class', 'large')->removeDecorator('DtDdWrapper')->removeDecorator('HtmlTag')->setLabel('Send to a friend'); $hash = new Zend_Form_Element_Hash('csrf'); $hash->setValue($this->_config->form->salt)->removeDecorator('DtDdWrapper')->removeDecorator('HtmlTag')->removeDecorator('label')->setTimeout(60); $this->addElement($hash); $this->addElements(array($fullname, $submit, $message)); $this->addDisplayGroup(array('fullname', 'email', 'messageToUser'), 'details')->removeDecorator('HtmlTag'); $this->details->addDecorators(array('FormElements', array('HtmlTag', array('tag' => 'ul')))); $this->details->removeDecorator('DtDdWrapper'); $this->details->removeDecorator('HtmlTag'); $this->details->setLegend('Details: '); $this->addDisplayGroup(array('submit'), 'submit'); }
/** Edit a system role */ public function editsystemroleAction() { $form = new SystemRoleForm(); $this->view->form = $form; if ($this->_request->isPost()) { $formData = $this->_request->getPost(); if ($form->isValid($formData)) { $roles = new Roles(); $updateData = array('role' => $form->getValue('role'), 'description' => $form->getValue('description'), 'updated' => $this->getTimeForForms(), 'updatedBy' => $this->getIdentityForForms()); $where = array(); $where[] = $roles->getAdapter()->quoteInto('id = ?', $this->_getParam('id')); $update = $roles->update($updateData, $where); $this->_flashMessenger->addMessage($form->getValue('role') . '\'s details updated.'); $this->_redirect('/admin/systemroles/'); } else { $form->populate($formData); } } else { // find id is expected in $params['id'] $id = (int) $this->_request->getParam('id', 0); if ($id > 0) { $roles = new Roles(); $roles = $roles->fetchRow('id=' . $id); $form->populate($roles->toArray()); } } }
/** Initialise the form * @access public * @return void */ public function init() { $roles = new Roles(); $role_options = $roles->getRoles(); $inst = new Institutions(); $inst_options = $inst->getInsts(); $username = $this->addElement('text', 'username', array('label' => 'Username: '******'StripTags', 'StringTrim'))->setRequired(true); $firstName = $this->addElement('text', 'first_name', array('label' => 'First Name', 'size' => '30'))->first_name; $firstName->setRequired(true)->addFilters(array('StripTags', 'StringTrim', 'Purifier'))->addErrorMessage('You must enter a firstname'); $lastName = $this->addElement('text', 'last_name', array('label' => 'Last Name', 'size' => '30'))->last_name; $lastName->setRequired(true)->addFilters(array('StripTags', 'StringTrim', 'Purifier'))->addErrorMessage('You must enter a surname'); $preferred_name = $this->addElement('text', 'preferred_name', array('label' => 'Preferred Name: ', 'size' => '30'))->preferred_name; $preferred_name->setRequired(true)->addFilters(array('StripTags', 'StringTrim', 'Purifier'))->addErrorMessage('You must enter your preferred name'); $fullname = $this->addElement('text', 'fullname', array('label' => 'Full name: ', 'size' => '30'))->fullname; $fullname->setRequired(true)->addFilters(array('StripTags', 'StringTrim', 'Purifier'))->addErrorMessage('You must enter your preferred name'); $email = $this->addElement('text', 'email', array('label' => 'Email Address', 'size' => '30'))->email; $email->addValidator('EmailAddress')->addFilters(array('StripTags', 'StringTrim', 'StringToLower'))->setRequired(true)->addErrorMessage('Please enter a valid address!'); $password = $this->addElement('password', 'password', array('label' => 'Change password: '******'size' => '30'))->password; $password->setRequired(false); $institution = $this->addElement('select', 'institution', array('label' => 'Recording institution: '))->institution; $institution->addMultiOptions(array(null => 'Choose institution', 'Available institutions' => $inst_options))->setAttrib('class', 'input-xlarge selectpicker show-menu-arrow'); $canRecord = $this->addElement('checkbox', 'canRecord', array('label' => 'Allowed to record: '))->canRecord; $role = $this->addElement('select', 'role', array('label' => 'Site role: '))->role; $role->addMultiOptions(array(null => 'Choose a role', 'Available roles' => $role_options))->setAttrib('class', 'input-medium selectpicker show-menu-arrow'); $person = $this->addElement('text', 'person', array('label' => 'Personal details attached: '))->person; $peopleID = $this->addElement('hidden', 'peopleID', array())->peopleID; $submit = new Zend_Form_Element_Submit('submit'); $this->addElement($submit); $this->addDisplayGroup(array('username', 'first_name', 'last_name', 'fullname', 'preferred_name', 'email', 'institution', 'role', 'password', 'person', 'peopleID', 'canRecord'), 'userdetails'); $this->addDisplayGroup(array('submit'), 'buttons'); $this->setLegend('Edit account details: '); parent::init(); }
public function init() { $required = true; $roles = new Roles(); $role_options = $roles->getRoles(); $inst = new Institutions(); $inst_options = $inst->getInsts(); $this->setAction($this->_actionUrl)->setMethod('post')->setAttrib('id', 'accountform'); $this->clearDecorators(); $this->addElementPrefixPath('Pas_Validate', 'Pas/Validate/', 'validate'); $this->addPrefixPath('Pas_Form_Element', 'Pas/Form/Element/', 'element'); $decorators = array(array('ViewHelper'), array('Description', array('placement' => 'append', 'class' => 'info')), array('Errors', array('placement' => 'prepend', 'class' => 'error', 'tag' => 'li')), array('Label', array('separator' => ' ', 'requiredSuffix' => ' *', 'class' => 'leftalign')), array('HtmlTag', array('tag' => 'li'))); $username = $this->addElement('text', 'username', array('label' => 'Username: '******'StripTags', 'StringTrim'))->setRequired(true); $firstName = $this->addElement('text', 'first_name', array('label' => 'First Name', 'size' => '30'))->first_name; $firstName->setRequired(true)->addFilters(array('StripTags', 'StringTrim'))->addValidator('Alnum', false, array('allowWhiteSpace' => true))->addErrorMessage('You must enter a firstname'); $firstName->setDecorators($decorators); $lastName = $this->addElement('text', 'last_name', array('label' => 'Last Name', 'size' => '30'))->last_name; $lastName->setRequired(true)->addFilters(array('StripTags', 'StringTrim'))->addValidator('Alnum', false, array('allowWhiteSpace' => true))->addErrorMessage('You must enter a surname'); $lastName->setDecorators($decorators); $fullname = $this->addElement('text', 'fullname', array('label' => 'Preferred Name: ', 'size' => '30'))->fullname; $fullname->setRequired(true)->addFilters(array('StripTags', 'StringTrim'))->addValidator('Alnum', false, array('allowWhiteSpace' => true))->addErrorMessage('You must enter your preferred name'); $fullname->setDecorators($decorators); $email = $this->addElement('text', 'email', array('label' => 'Email Address', 'size' => '30'))->email; $email->addValidator('EmailAddress')->addFilters(array('StripTags', 'StringTrim', 'StringToLower'))->setRequired(true)->addErrorMessage('Please enter a valid address!'); $email->setDecorators($decorators); $password = $this->addElement('password', 'password', array('label' => 'Change password: '******'size' => '30'))->password; $password->setRequired(false); $password->setDecorators($decorators); $institution = $this->addElement('select', 'institution', array('label' => 'Recording institution: '))->institution; $institution->setDecorators($decorators); $institution->addMultiOptions(array(NULL => NULL, 'Choose institution' => $inst_options)); $role = $this->addElement('select', 'role', array('label' => 'Site role: '))->role; $role->setDecorators($decorators); $role->addMultiOptions(array(NULL => NULL, 'Choose role' => $role_options)); $person = $this->addElement('text', 'person', array('label' => 'Personal details attached: '))->person; $person->setDecorators($decorators); $peopleID = $this->addElement('hidden', 'peopleID', array())->peopleID; $peopleID->setDecorators($decorators); $submit = new Zend_Form_Element_Submit('submit'); $submit->clearDecorators(); $submit->addDecorators(array(array('ViewHelper'), array('HtmlTag', array('tag' => 'div', 'class' => 'submit')))); $submit->setAttrib('class', 'large'); $this->addElement($submit); $hash = new Zend_Form_Element_Hash('csrf'); $hash->setValue($this->_config->form->salt)->removeDecorator('DtDdWrapper')->removeDecorator('HtmlTag')->removeDecorator('label')->setTimeout(60); $this->addElement($hash); $this->addDisplayGroup(array('username', 'first_name', 'last_name', 'fullname', 'email', 'institution', 'role', 'password', 'person', 'peopleID'), 'userdetails'); $this->addDecorator('FormElements')->addDecorator(array('ListWrapper' => 'HtmlTag'), array('tag' => 'div'))->addDecorator('FieldSet')->addDecorator('Form'); $this->userdetails->removeDecorator('DtDdWrapper'); $this->userdetails->removeDecorator('FieldSet'); $this->userdetails->addDecorator(array('DtDdWrapper' => 'HtmlTag'), array('tag' => 'ul')); $this->addDisplayGroup(array('submit'), 'submit'); $this->setLegend('Edit account details: '); }
public function __construct($options = null) { parent::__construct($options); $roles = new Roles(); $role_options = $roles->getRoles(); $inst = new Institutions(); $inst_options = $inst->getInsts(); $projecttypes = new ProjectTypes(); $projectype_list = $projecttypes->getTypes(); $this->setName('acceptupgrades'); ZendX_JQuery::enableForm($this); $decorators = array(array('ViewHelper'), array('Description', array('placement' => 'append', 'class' => 'info')), array('Errors', array('placement' => 'append', 'class' => 'error', 'tag' => 'li')), array('Label'), array('HtmlTag', array('tag' => 'li'))); $level = new Zend_Form_Element_Select('level'); $level->setLabel('Level of research: ')->setRequired(true)->addMultiOptions(array(NULL => NULL, 'Choose type of research' => $projectype_list))->setDecorators($decorators)->addFilter('StripTags')->addFilter('StringTrim')->addErrorMessage('You must set the level of research'); $title = new Zend_Form_Element_Text('title'); $title->setLabel('Project title: ')->setRequired(true)->addFilter('StripTags')->addFilter('StringTrim')->setAttrib('size', 60)->addErrorMessage('This project needs a title.')->setDecorators($decorators); $researchOutline = new Pas_Form_Element_RTE('researchOutline'); $researchOutline->setLabel('Research outline: ')->setRequired(true)->setAttrib('rows', 10)->setAttrib('cols', 40)->setAttrib('Height', 400)->setAttrib('ToolbarSet', 'Finds')->addFilter('StringTrim')->addFilter('BasicHtml')->addFilter('EmptyParagraph')->addFilter('WordChars')->addErrorMessage('Outline must be present.'); $reference = new Zend_Form_Element_Text('reference'); $reference->setLabel('Referee\'s name: ')->setAttrib('size', 30)->addFilter('StringTrim')->addFilter('StripTags')->setDecorators($decorators); $referenceEmail = new Zend_Form_Element_Text('referenceEmail'); $referenceEmail->setLabel('Referee\'s email address: ')->setAttrib('size', 30)->addValidator('EmailAddress')->addFilter('StringToLower')->addFilter('StringTrim')->addFilter('StripTags')->setDecorators($decorators); $message = new Pas_Form_Element_RTE('message'); $message->setLabel('Message to user: '******'rows', 10)->setAttrib('cols', 40)->setAttrib('Height', 400)->setAttrib('ToolbarSet', 'Finds')->addFilter('StringTrim')->addFilter('BasicHtml')->addFilter('EmptyParagraph')->addFilter('WordChars')->addErrorMessage('You must enter a message for the user to know they have been approved.'); $fullname = new Zend_Form_Element_Text('fullname'); $fullname->setLabel('Fullname: ')->setAttrib('size', 30)->addFilter('StringTrim')->addFilter('StripTags')->setDecorators($decorators); $institution = $this->addElement('select', 'institution', array('label' => 'Recording institution: '))->institution; $institution->setDecorators($decorators)->addMultiOptions(array(NULL => NULL, 'Choose institution' => $inst_options)); $role = $this->addElement('select', 'role', array('label' => 'Site role: '))->role; $role->setDecorators($decorators); $role->addMultiOptions(array(NULL => NULL, 'Choose role' => $role_options)); $role->removeMultiOption('admin'); $startDate = new ZendX_JQuery_Form_Element_DatePicker('startDate'); $startDate->setLabel('Start date of project: ')->setAttrib('size', 12)->setJQueryParam('dateFormat', 'yy-mm-dd')->addFilter('StringTrim')->addFilter('StripTags')->addValidator('Date')->setRequired(false)->addErrorMessage('You must enter a valid start date for this project'); $endDate = new ZendX_JQuery_Form_Element_DatePicker('endDate'); $endDate->setLabel('End date of project: ')->addValidator('Date')->addFilter('StringTrim')->addFilter('StripTags')->setJQueryParam('dateFormat', 'yy-mm-dd')->setAttrib('size', 12)->setRequired(false)->addErrorMessage('You must enter a valid end date for this project'); $email = $this->addElement('text', 'email', array('label' => 'Email Address', 'size' => '30'))->email; $email->addValidator('emailAddress')->setRequired(true)->addFilter('StringToLower')->addErrorMessage('Please enter a valid address!')->setDecorators($decorators); $already = new Zend_Form_Element_Radio('already'); $already->setLabel('Is your topic already listed on our research register?: ')->addMultiOptions(array(1 => 'Yes it is', 0 => 'No it isn\'t'))->setRequired(true)->setOptions(array('separator' => ''))->setDecorators($decorators); $insert = new Zend_Form_Element_Checkbox('insert'); $insert->setLabel('Insert details into research register: ')->setCheckedValue(1)->setDecorators($decorators); $valid = new Zend_Form_Element_Radio('higherLevel'); $valid->setLabel('Approve?: ')->addMultiOptions(array(1 => 'Unauthorised', 0 => 'Authorised'))->setRequired(true)->setOptions(array('separator' => ''))->setDecorators($decorators); $submit = new Zend_Form_Element_Submit('submit'); $submit->setAttrib('id', 'submit')->setAttrib('class', 'large')->removeDecorator('DtDdWrapper')->removeDecorator('HtmlTag'); $this->addElements(array($reference, $referenceEmail, $researchOutline, $startDate, $endDate, $fullname, $valid, $level, $title, $submit, $already, $insert, $message)); $this->addDisplayGroup(array('fullname', 'username', 'email', 'institution', 'level', 'role', 'reference', 'referenceEmail', 'message', 'researchOutline', 'title', 'startDate', 'endDate', 'already', 'higherLevel', 'insert'), 'details')->removeDecorator('HtmlTag'); $this->details->addDecorators(array('FormElements', array('HtmlTag', array('tag' => 'ul')))); $this->details->removeDecorator('DtDdWrapper'); $this->details->removeDecorator('HtmlTag'); $this->details->setLegend('Details: '); $this->addDisplayGroup(array('submit'), 'submit'); }
/** * A method to set a controller * @param Role $role * @return Object Role */ public function setRole(Role $role = null) { if ($this->role !== null) { $this->role->removeResource($this); } if ($role !== null) { $role->addResource($this); } $this->role = $role; return $this; }
public function getRoles() { $data = array(); $roles = new Roles(); foreach ($roles->findAll(array('select' => 'code, id')) as $value_r) { foreach (Yii::app()->authManager->roles as $value) { if (strtolower(trim($value->name)) == strtolower(trim($value_r->code))) { $data[$value_r->id] = $value_r->code; } } } return $data; }
/** * Static function to display the data in detail view * @param string $value */ public static function display_value($value) { if ($value != '') { $do_roles = new Roles(); $roles_data = $do_roles->get_role_detail($value); if (is_array($roles_data) && count($roles_data) > 0) { return $roles_data["rolename"]; } else { return ''; } } else { return $value; } }
public function authenticate() { $exception = null; $result = array('code' => Zend_Auth_Result::FAILURE, 'identity' => $this->Identity, 'messages' => array()); $userInfo = array(); if (empty($this->Identity)) { $exception = 'You must provide a identity to authenticate'; throw new Zend_Auth_Adapter_Exception('Please verify your username'); } else { if (empty($this->Credential)) { $exception = 'You must provide a credential to authenticate'; } elseif ($this->Rows) { if (is_array($this->Rows)) { $this->Rows = $this->array2object($this->Rows); } $userInfo[0]['user_id'] = isset($this->Rows->user_id) && !empty($this->Rows->user_id) ? $this->Rows->user_id : ''; $userInfo[0]['username'] = isset($this->Rows->username) && !empty($this->Rows->username) ? $this->Rows->username : ''; $userInfo[0]['firstname'] = isset($this->Rows->firstname) && !empty($this->Rows->firstname) ? $this->Rows->firstname : ''; $userInfo[0]['lastname'] = isset($this->Rows->lastname) && !empty($this->Rows->lastname) ? $this->Rows->lastname : ''; $userInfo[0]['location'] = isset($this->Rows->location) && !empty($this->Rows->location) ? $this->Rows->location : ''; $userInfo[0]['email'] = isset($this->Rows->email) && !empty($this->Rows->email) ? $this->Rows->email : ''; $userInfo[0]['role_id'] = isset($this->Rows->role_id) && !empty($this->Rows->role_id) ? $this->Rows->role_id : ''; $userInfo[0]['active'] = isset($this->Rows->active) && !empty($this->Rows->active) ? $this->Rows->active : ''; $userInfo[0]['publisher_id'] = isset($this->Rows->publisher_id) && !empty($this->Rows->publisher_id) ? $this->Rows->publisher_id : ''; $found = true; if (!empty($userInfo[0]['role_id'])) { $role = new Roles(); $roleid = $role->fetchROW(" role_id='" . $userInfo[0]['role_id'] . "'"); $userInfo[0]['rolename'] = $roleid->role_name; } else { $userInfo[0]['rolename'] = ''; } if (isset($userInfo) && !empty($userInfo)) { $result['code'] = Zend_Auth_Result::SUCCESS; $result['messages'][] = 'Authentication success'; $this->RowsIdent = $userInfo; } else { //$exception = 'You must provide a credential to authenticate'; $result['code'] = Zend_Auth_Result::FAILURE_IDENTITY_NOT_FOUND; $result['messages'][] = 'Authentication failed'; } } } if (null != $exception) { throw new Zend_Auth_Adapter_Exception($exception); } return new Zend_Auth_Result($result['code'], $result['identity'], $result['messages'], $userInfo); }
function __construct($role_id, $locale_code = "en-us", $config = null, $restricted = null) { $this->locale_code = $locale_code; $this->role_id = $role_id; if (is_array($this->role_id)) { $all_roles = $this->role_id; } else { $all_roles = array($this->role_id); } $roles_table = new Roles(); foreach ($all_roles as $role) { $all_roles = array_merge($all_roles, $roles_table->getAllAncestors($role)); } $this->all_roles = array_unique($all_roles); return parent::__construct($config); }
/** * @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()); } }
/** * Retrieves roles for the user */ public function getRoles() { if (!isset($this->_roles)) { $this->_roles = Roles::getUserRoles($this->getId()); } return $this->_roles; }
function generate_inner_html() { switch ($this->mode) { default: $inner_template = dirname(__FILE__) . '/center_inner_private.tpl'; } $inner_html_gen =& new Template($inner_template); $role = new Roles(); $this->links = $role->get_multiple(); $inner_html_gen->set('links', $this->links); $inner_html_gen->set('display', @$this->display); $inner_html_gen->set('super_user_and_mothership', @$this->super_user_and_mothership); $inner_html_gen->set('config_navigation_url', network_config_navigation('manage_roles')); $inner_html = $inner_html_gen->fetch(); return $inner_html; }
/** * [emailToUser Send Email to user for report user status] * @param [type] $email [user email] * @param [type] $name [user name] * @param [type] $status [user status] * @return [type] [description] */ public function emailToUser($email, $name, $status, $group, $role) { if ($status == 'yes') { $status = 'เปิดใช้งาน'; } else { $status = 'ปิดการใช้งาน'; } $role_obj = new Roles(); $_role = $role_obj->getRoleName($role); $grp_obj = new Usergroup(); $_grp = $grp_obj->getGrpName($group); //var_dump($_grp);exit; Mail::send('userlist.email', array("name" => $name, "status" => $status, "group" => $_grp->grp_nameth, "role" => $_role->role_name), function ($message) use($email) { $message->to($email, 'Admin@NHC')->subject('Your status @NHC'); }); }
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;*/ }
public function submitAction() { // Disable view $this->view->disable(); // Check and get POSTED data if ($this->request->isPost() && !empty($login_name = $this->request->getPost("username")) && !empty($password = $this->request->getPost("password"))) { $user = Users::findFirst(array("login_name = :login_name: AND active = true", "bind" => array("login_name" => $login_name))); if (empty($user)) { echo json_encode(array("success" => false, "errorType" => "username", "errorMessage" => "Username tidak dikenal")); return; } else { if ($user->isBanned()) { echo json_encode(array("success" => false, "errorType" => "username", "errorMessage" => "Username ini tidak dapat digunakan kembali")); return; } else { if ($user->isSuspended()) { echo json_encode(array("success" => false, "errorType" => "username", "errorMessage" => "Untuk sementara, username ini tidak dapat digunakan")); return; } } } if (!$this->security->checkHash($password, $user->getPassword())) { echo json_encode(array("success" => false, "errorType" => "password", "errorMessage" => "Password yang anda masukkan salah")); return; } $this->session->set("auth", array("user" => $user, "role" => Roles::findFirstByIdRole($user->getIdRole()))); echo json_encode(array("success" => true)); } }
function UserAclRoles($user_id = '') { $show_box['title'] = '获取用户全部角色'; $return_value = ''; $roles_idname = array(); $roles_id = array(); $sp_roles = Q::ini('appini/sp_role'); // 第一步:直接从中间表获得用户的全部角色ID $user_roles = UsersHaveRoles::find('user_id = ?', intval($user_id))->asArray()->getAll(); //dump($user_roles); // 取出有用的ID,去除deny的ID foreach ($user_roles as $value) { if ($value['is_include']) { $roles_id[] = $value['role_id']; } } //dump ( $roles_id); $roles_arr = Roles::find('role_id in (?)', Q::normalize($roles_id, ","))->asArray()->getAll(); foreach ($roles_arr as $value) { $roles_idname[$value['role_id']] = $value['rolename']; } //dump($roles_idname); if (in_array($sp_roles['REPEAL'], $roles_idname)) { $return_value = array($value['role_id'] => $sp_roles['REPEAL']); return $return_value; } elseif (in_array($sp_roles['FREEZE'], $roles_idname)) { $return_value = array($value['role_id'] => $sp_roles['FREEZE']); return $return_value; } elseif (in_array($sp_roles['UNCHECKED'], $roles_idname)) { $return_value = array($value['role_id'] => $sp_roles['UNCHECKED']); return $return_value; } else { return $roles_idname; } }
public function login() { $email = Input::get('email'); $password = Input::get('password'); $user = Users::where('email', '=', $email)->first(); if ($user != null && Hash::check($password, $user->password)) { Session::set('logged', true); Session::set('email', $email); Session::set('time_zone', $user->time_zone); Session::set('lid', $user->language_id); Session::set('user_id', $user->id); $userRole = Roles::getUserRole($user->role_id); Session::set('role', $userRole); // getting car_id if its a driver if ($user->role_id == Roles::DRIVER_ROLE_ID) { $driver = Driver::where('user_id', '=', $user->id)->firstOrFail(); Session::set('car_id', $driver->car_id); } $result = array('success' => true, 'message' => 'logged in successfully', 'payload' => array('role' => $userRole)); } else { Session::flush(); $result = array('success' => false, 'message' => 'invalid email or password'); } return $result; }
/** * 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; }
public function addRole($role) { if (!Roles::isValid($role)) { throw new \InvalidArgumentException("The role {$role} is invalid. Please refer to Roles class or documentation"); } $this->roles[] = $role; return $this; }
public function loadModel($id) { $model = Roles::model()->findByPk($id); if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } return $model; }
static function isAllowed($resource,$module = "default",$username = null,$controller = null){ $users_roles_table = new UsersRoles(); $roles_table = new Roles(); if(!is_null($username)){ $users_roles_db = $users_roles_table->fetchAll($users_roles_table->select()->where("username = ?",$username)); if(count($users_roles_db) > 0){ $user_roles = array(); $users_roles_db = $users_roles_db->toArray(); foreach($users_roles_db as $role){ $ancs = $roles_table->getAllAncestors($role['role_id']); foreach ($ancs as $anc => $value) { $user_roles[] = $value; } array_push($user_roles, $role['role_id']); } $user_roles = array_unique($user_roles); } } else { $user_roles = array($roles_table->getIdByShortname("guest")); } if (is_null($controller)) { $controller = "@@EXTRA"; } $resource_name = $module ."-". $controller ."-". $resource; $out = array(); if(Zend_Registry::isRegistered('acl')){ $acl = Zend_Registry::get('acl'); if($acl->has($resource_name)){ foreach($user_roles as $role){ if($acl->isAllowed($role, $resource_name)){ $out[] = $role; } } } } return $out; }
/** * Return role * * @param void * @return Role */ function getRole() { if ($this->role === false) { $role_id = $this->getRoleId(); $this->role = $role_id ? Roles::findById($this->getRoleId()) : null; } // if return $this->role; }
/** * [getRoleByKeywork search role] * @param [type] $keywork [description] * @param [type] $perPage [description] * @return [type] [description] */ public function getRoleByKeywork($keywork, $perPage) { if ($keywork != 'all') { $role = Roles::whereRaw('role_name like ?', array('%' . $keywork . '%'))->orderBy('id', 'asc')->paginate($perPage); } else { $role = Roles::where('role_name', '!=', '')->orderBy('id', 'asc')->paginate($perPage); } return $role; }
public function run() { $faker = \Faker\Factory::create(); Roles::truncate(); $roles = [['name' => 'admin', 'display_name' => 'Administrator', 'discription' => 'Administrator', 'created_at' => new DateTime(), 'updated_at' => new DateTime()], ['name' => 'member', 'display_name' => 'Member', 'discription' => 'Member', 'created_at' => new DateTime(), 'updated_at' => new DateTime()]]; foreach ($roles as $role) { Roles::insert($role); } }
/** * Update the specified resource in storage. * * @param int $id * @return Response */ public function update(RolesRequest $roles, $id) { //this is method to saving $roles = Roles::find($id); $roles->name = Input::get('name'); $roles->access = json_encode(Input::get('access')); $roles->save(); Session::flash('message', 'You have successfully added Roles'); return Redirect::to('roles'); }
/** * @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!'); }