本文整理汇总了PHP中Sentry::group方法的典型用法代码示例。如果您正苦于以下问题:PHP Sentry::group方法的具体用法?PHP Sentry::group怎么用?PHP Sentry::group使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Sentry
的用法示例。
在下文中一共展示了Sentry::group方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: action_delete
public function action_delete($id = null)
{
if (!Sentry::user()->has_access('groups_delete')) {
self::no_access();
}
if (Sentry::group(intval($id))->delete()) {
Session::set_flash('success', 'Group successfuly deleted');
Response::redirect('groups');
} else {
Session::set_flash('error', 'Could not delete the group');
}
Response::redirect('groups');
}
示例2: up
public function up()
{
\Config::load('sentry', true);
try {
// create groups
$this->create_group('users', 1);
$this->create_group('moderators', 50);
$this->create_group('administrators', 100, true);
// create user data
$user_id = $this->create_user('admin', 'logica');
\Sentry::user($user_id)->add_to_group(\Sentry::group('administrators')->get('id'));
$group_mod = \Sentry::group('moderators')->get('id');
$group_user = \Sentry::group('users')->get('id');
for ($i = 1; $i <= 100; $i++) {
$user_id = $this->create_user('user' . $i, 'password');
$group = $i % 3 ? $group_mod : $group_user;
$user = \Sentry::user($user_id);
$user->add_to_group($group);
}
} catch (SentryUserException $e) {
echo $e->getMessage();
return false;
}
}
示例3: action_edit
public function action_edit($id = null)
{
// redirect if no right access
if (!Sentry::user()->has_access('users_edit') && $this->current_user->id != $id) {
Session::set_flash('error', 'You don\'t have the right to edit a user');
Response::redirect('users');
}
$user = Sentry::user(intval($id));
$group = $user->groups();
View::set_global('user', $user);
View::set_global('groups', Sentry::group()->all());
View::set_global('user_group', $group);
// if receive a post update the user
if (Input::method() == 'POST') {
$val = Model_Users::validate('edit');
if (!$val->run()) {
// the data are not valid
Session::set_flash('error', implode(', ', $val->error()));
} else {
// valid data
if (Input::post('email') && Input::post('group')) {
// remove the user from is actual group
if (!empty($group[0]['name'])) {
$remove = $user->remove_from_group($group[0]['name']);
if (!$remove) {
Session::set_flash('error', 'Couldn\'t remove the user from his group.');
}
}
// set a new group for the user
$add = $user->add_to_group(Input::post('group'));
if (!$add) {
Session::set_flash('error', 'Couldn\'t add the user to the new group.');
}
// update the other informations
$update = $user->update(array('email' => Input::post('email'), 'metadata' => array('first_name' => Input::post('first_name'), 'last_name' => Input::post('last_name'), 'department' => Input::post('department'))));
if (!$update) {
Session::set_flash('error', 'Couldn\'t update the user.');
} else {
Session::set_flash('success', 'Successfully updated ' . $user->username . '.');
Response::redirect('users');
}
} else {
if (Input::post('new_password') || Input::post('c_new_password') || Input::post('old_password')) {
if (Input::post('new_password') != Input::post('c_new_password')) {
Session::set_flash('error', 'Please repeat the same password');
} else {
if (Input::post('old_password') == '') {
Session::set_flash('error', 'Please enter your previous password');
} else {
if (!$user->check_password(Input::post('old_password'))) {
Session::set_flash('error', 'Old password is incorrect');
} else {
$user->change_password(Input::post('new_password'), Input::post('old_password'));
Session::set_flash('success', $user->username . ' password has been successfuly changed');
}
}
}
}
}
}
}
$this->template->h2 = $this->template->title = isset($user['username']) ? 'Editing ' . ucwords($user['username']) . '\'s profile' : 'User not found';
$this->template->js .= Asset::js(array('mylibs/jquery.validate.js', 'script.js'));
$this->template->content = View::forge('users/edit');
}
示例4: create_user
public function create_user()
{
// Get groups
$groups = \Sentry::group()->all('front');
if (\Input::post()) {
// Get POST values
$insert = \Input::post();
$register_type = 'register';
if (\Input::post('register')) {
$register_type = $insert['register'];
}
$ship_to = 'billing';
if ($insert['ship'] == 'other') {
$ship_to = 'shipping';
}
$val = \User\Controller_Validate::forge($register_type == 'register' ? 'create' : 'guest', false, $ship_to == 'shipping' ? 'shipping' : false);
if ($val->run()) {
array_walk($insert, create_function('&$val', '$val = trim($val);'));
try {
// Generate random username
$email = $insert['email'];
$user_group = 3;
if ($register_type == 'guest') {
$username = 'user' . \Str::random('numeric', 16);
$insert['guest'] = 1;
$random_password = 'random' . \Str::random(unique);
$password = $random_password;
} else {
$username = $email;
$insert['guest'] = 0;
$password = $insert['password'];
}
unset($insert['email'], $insert['password'], $insert['confirm_password'], $insert['user_group'], $insert['details'], $insert['save'], $insert['update']);
$only_billing = array('email');
$billing_data = \Arr::filter_prefixed($insert, "billing_");
// Set shipping data to be same as billing by default
if ($ship_to_billing) {
foreach ($billing_data as $key => $value) {
if (!in_array($key, $only_billing)) {
$insert['shipping_' . $key] = $value;
}
}
}
$metadata = \Arr::remove_prefixed($insert, "billing_") + $billing_data;
$table = \DB::table_prefix('users_metadata');
$columns = \DB::list_columns($table);
$insert = array_intersect_key($metadata, $columns);
// create the user - no activation required
$vars = array('username' => $username, 'email' => $email, 'password' => $password, 'metadata' => $insert);
$user_id = \Sentry::user()->create($vars);
$user = \Sentry::user($user_id);
// Add user to 'customer' group (id = 3)
if ($user_id and $user->add_to_group($user_group)) {
if ($register_type == 'account') {
\Messages::success('User successfully created.');
}
if ($register_type == 'guest') {
\Messages::success('You register as a guest.');
}
$login_column = \Config::get('sentry.login_column', 'email');
if (\Sentry::login(${$login_column}, $password, true)) {
\Response::redirect(\Uri::create('order/checkout/cost'));
} else {
if ($register_type == 'account') {
\Messages::error('There was an error while trying to create account. Please try to create new account.');
}
if ($register_type == 'guest') {
\Messages::error('There was an error. Please try to login with your account details.');
}
}
} else {
// show validation errors
\Messages::error('There was an error while trying to create account.');
}
} catch (\Sentry\SentryException $e) {
// show validation errors
\Messages::error('There was an error while trying to create user.');
$errors = $e->getMessage();
\Messages::error($errors);
}
} else {
if ($val->error() != array()) {
// show validation errors
\Messages::error('There was an error while trying to create user.');
foreach ($val->error() as $e) {
\Messages::error($e->get_message());
}
}
}
}
}
示例5: action_users
/**
* Users
*
* @access public
* @return void
*/
public function action_users()
{
\View::set_global('title', 'Users');
// Get current user
$user = \Sentry::user();
$master_user = false;
if (isset($user['metadata']['master']) && $user['metadata']['master']) {
$master_user = true;
}
if (!$master_user) {
\Messages::error("You don't have permssion to view this page.");
\Response::redirect(\Uri::front_create('user/account'));
}
$user_group = $user->groups();
$user_group = $user_group[0];
$users = \Sentry::group($user_group['id'])->users();
// Reset to empty array if there are no result found by query
if (is_null($users)) {
$users = array();
}
// Remove current user
foreach ($users as $key => $group_user) {
if ($group_user['id'] == $user->id) {
unset($users[$key]);
}
}
// Initiate pagination
$pagination = \Hybrid\Pagination::make(array('total_items' => count($users), 'per_page' => \Input::get('per_page', 10), 'uri_segment' => null));
// Remove unwanted items, and show only required ones
$users = array_slice($users, $pagination->offset, $pagination->per_page);
\Theme::instance()->set_partial('content', $this->view_dir . 'users')->set('user', $user, false)->set('user_group', $user_group, false)->set('users', $users, false)->set('pagination', $pagination, false);
}
示例6: array
<?php
}
?>
<?php
if (in_array('user_group_admin', $options)) {
?>
<div class="filter_width <?php
echo $margin();
?>
">
<?php
echo \Form::label('User Group', null, array('class' => 'm_r_15'));
?>
<?php
echo \Form::select('user_group', \Input::get('user_group', isset($values['user_group']) ? $values['user_group'] : false), array('false' => 'Select') + \User\Model_Group::fetch_pair('id', 'name', array(), false, \Sentry::group()->all('admin')), array('class' => 'select_init filter_width'));
?>
</div>
<?php
}
?>
<?php
if (in_array('country', $options)) {
?>
<div class="filter_width <?php
echo $margin();
?>
">
<?php
echo \Form::label('Country');
?>
示例7: get_search_customers
public function get_search_customers($group_id = false)
{
// Override group_id if its a search
$group_id = \Input::get('user_group', $group_id);
$activated = \Input::get('activated', false);
if (\Input::get()) {
if ($group_id && \Sentry::group_exists((int) $group_id)) {
// Get only group users
\View::set_global('group', \Sentry::group((int) $group_id));
$items = \Sentry::group((int) $group_id)->users();
} else {
// Get all users and remove admin users from array
$items = \Sentry::user()->all('front');
}
}
// Reset to empty array if there are no result found by query
if (empty($items)) {
$items = array();
}
// Get user objects
if (!empty($items)) {
foreach ($items as $key => $item) {
$items[$key] = \Sentry::user((int) $item['id']);
}
// Get search filters
foreach (\Input::get() as $key => $value) {
if (!empty($value) || $value == '0') {
switch ($key) {
case 'title':
foreach ($items as $number => $item) {
if (empty($item['metadata'])) {
unset($items[$number]);
continue;
}
$full_name = $item->get('metadata.first_name') . ' ' . $item->get('metadata.last_name');
$customer_id = $item->get('metadata.user_id');
if (stripos($full_name, $value) === false && stripos($customer_id, $value) === false) {
unset($items[$number]);
}
}
break;
case 'email':
foreach ($items as $number => $item) {
if (stripos($item->email, $value) === false) {
unset($items[$number]);
}
}
break;
case 'country':
if ($value && $value !== 'false') {
foreach ($items as $number => $item) {
if (empty($item['metadata'])) {
unset($items[$number]);
continue;
}
if (stripos($item->get('metadata.country'), $value) === false) {
unset($items[$number]);
}
}
}
break;
case 'postcode_from':
foreach ($items as $number => $item) {
if (empty($item['metadata'])) {
unset($items[$number]);
continue;
}
if ($item->get('metadata.postcode') < $value) {
unset($items[$number]);
}
}
break;
case 'postcode_to':
foreach ($items as $number => $item) {
if (empty($item['metadata'])) {
unset($items[$number]);
continue;
}
if ($item->get('metadata.postcode') > $value) {
unset($items[$number]);
}
}
break;
case 'activated':
if ($value !== 'false') {
foreach ($items as $number => $item) {
if ($item->activated != $value) {
unset($items[$number]);
}
}
}
break;
}
}
}
}
// Reset to empty array if there are no result found by query
if (empty($items)) {
$items = array();
}
//.........这里部分代码省略.........
示例8: foreach
<?php
if (!$group && empty($groups)) {
?>
<div class="wide"><span class="req">Note: </span> There are no user groups yet.</div>
<?php
} else {
?>
<ul class="treeview" id="tree">
<?php
if (!empty($groups)) {
foreach ($groups as $key => $group_item) {
$group_item = (object) $group_item;
$users = Sentry::group($group_item->id)->users();
?>
<li>
<div class="radio_link_holder">
<a href="<?php
echo \Uri::create('admin/user/list/' . $group_item->id);
?>
" <?php
echo $selected == $group_item->id ? 'class="active"' : '';
?>
>
<?php
echo $group_item->name;
?>
<?php
echo $users ? '<span class="tree_count">(' . count($users) . ')</span>' : '';
示例9: foreach
<th scope="col">Customer Groups</th>
<th scope="col" class="center" style="width: 40px;">Users</th>
<th scope="col" class="center" style="width: 40px;">Edit</th>
<th scope="col" class="center" style="width: 40px;">Delete</th>
</tr>
</thead>
<tbody>
<?php
foreach ($items as $item) {
?>
<?php
$item = (object) $item;
?>
<?php
$users = \Sentry::group($item->id)->users();
?>
<tr>
<td><?php
echo $item->name;
?>
</td>
<td class="center">
<a href="<?php
echo \Uri::create('admin/user/list/' . $item->id);
?>
">
<strong><?php
echo count($users) == 0 ? '/' : count($users);
?>
</strong>
示例10: isset
?>
</div>
</div>
<div class="formRow">
<label>Email</label>
<div>
<?php
echo Form::input('email', $user_data['email'] ? $user_data['email'] : \Input::post('email'));
?>
</div>
</div>
<div class="formRow">
<label>User Group</label>
<div>
<?php
echo \Form::select('user_group', \Input::get('user_group', isset($user_data['user_group']) ? $user_data['user_group'] : false), \User\Model_Group::fetch_pair('id', 'name', array(), false, \Sentry::group()->all('admin')), array('style' => 'height: 28px; width:97%;'));
?>
</div>
</div>
<div class="formRow">
<label>New Password</label>
<div>
<?php
echo Form::password('password', \Input::post('password'));
?>
</div>
</div>
<div class="formRow">
<label>Repeat New Password</label>
<div>
<?php
示例11: action_update
public function action_update($id = false)
{
if (!is_numeric($id)) {
\Response::redirect('admin/user/list');
}
// Get user to edit
if (!\Sentry::user_exists((int) $id)) {
\Response::redirect('admin/user/list');
}
\View::set_global('title', 'Edit User');
// Get groups
$groups = \Sentry::group()->all('front');
// Update group details
if (\Input::post('details', false)) {
$item = new \Sentry_User((int) $id);
$val = \User\Controller_Admin_Validate::forge('update', $item['id']);
if ($val->run()) {
// Get POST values
$insert = \Input::post();
array_walk($insert, create_function('&$val', '$val = trim($val);'));
try {
// Generate random username
//$username = 'user' . \Str::random('numeric', 16);
$username = $insert['email'];
$email = $insert['email'];
$password = $insert['password'];
$user_group = $insert['user_group'];
$activated = $insert['activated'];
$email_client = $insert['email_client'];
$insert['guest'] = $user_group == 3 ? 1 : 0;
unset($insert['email'], $insert['password'], $insert['confirm_password'], $insert['user_group'], $insert['details'], $insert['save'], $insert['exit'], $insert['activated'], $insert['email_client']);
$only_billing = array('business_name', 'purchase_limit_value', 'purchase_limit_period', 'master', 'note', 'credit_account', 'guest');
// Set shipping data to be same as billing by default
/*foreach($insert as $key => $value)
{
if(!in_array($key, $only_billing) && strpos($key, 'shipping_') === false)
{
if(empty($insert['shipping_'.$key]))
$insert['shipping_'.$key] = $value;
}
}*/
// create the user - no activation required
$vars = array('username' => $username, 'email' => $email, 'password' => $password, 'metadata' => $insert, 'activated' => $activated);
// Send email to user with new password
if ($email_client == 1 && !empty($vars['password'])) {
$email_data = array('site_title' => \Config::get('site_title'), 'customer_identity' => ucwords($item->get('metadata.first_name') . ' ' . $item->get('metadata.last_name')), 'new_password' => $vars['password']);
$this->autoresponder($item, $email_data);
}
if (empty($vars['password'])) {
unset($vars['password']);
}
if ($item->update($vars)) {
//Change user group if needed
$user_groups = $item->groups();
if (!empty($user_groups)) {
// Remove user from all other groups...
foreach ($user_groups as $value) {
$item->remove_from_group((int) $value['id']);
}
}
$item = new \Sentry_User((int) $id);
// ...and add it to selected one
$item->add_to_group((int) $user_group);
\Messages::success('User successfully updated.');
\Response::redirect(\Input::post('exit', false) ? \Uri::create('admin/user/list/') : \Uri::admin('current'));
} else {
// show validation errors
\Messages::error('<strong>' . 'There was an error while trying to update user' . '</strong>');
}
} catch (\Sentry\SentryException $e) {
// show validation errors
\Messages::error('<strong>' . 'There was an error while trying to update user' . '</strong>');
$errors = $e->getMessage();
\Messages::error($errors);
}
} else {
if ($val->error() != array()) {
// show validation errors
\Messages::error('<strong>' . 'There was an error while trying to update user' . '</strong>');
foreach ($val->error() as $e) {
\Messages::error($e->get_message());
}
}
}
}
$user = new \Sentry_User((int) $id);
// Get single user group
$user_group = $user->groups();
$user_group = current($user_group);
$user->group = $user_group;
\Theme::instance()->set_partial('content', $this->view_dir . 'update')->set('user', $user)->set('groups', $groups);
}
示例12: action_delete
public function action_delete($id = false)
{
if (is_numeric($id)) {
// Get news item to edit
if ($item = \Sentry::group((int) $id)) {
// Some groups are not del
if ($item->deletable) {
if (!$item->users()) {
// Delete item
try {
// Delete group
$item->delete();
\Messages::success('Group successfully deleted.');
} catch (\Sentry\SentryGroupException $e) {
// show validation errors
\Messages::error('<strong>There was an error while trying to delete group</strong>');
// Uncomment lines below to show database errors
$errors = $e->getMessage();
\Messages::error($errors);
}
} else {
// show validation errors
\Messages::error('<strong>There was an error while trying to delete group</strong>');
\Messages::error('In order to delete this group first remove all members from it.');
}
} else {
// show validation errors
\Messages::error('<strong>There was an error while trying to delete group</strong>');
\Messages::error('This group can\'t be deleted.');
}
}
}
\Response::redirect(\Input::referrer());
}
示例13: isset
<?php
// Get all groups and remove admin groups from array
$groups = \Sentry::group()->all('front');
$group = isset($group) ? $group : false;
$link = isset($link) ? $link : 'update';
$selected = isset($selected) ? $selected : false;
?>
<div class="side_tree_holder" style="display:none;">
<div class="tree_heading">
<h4>User Groups</h4>
<div id="sidetreecontrol" class="sidetreecontrol"><a href="#">Collapse All</a><a href="#">Expand All</a></div>
</div>
<div class="tree_content">
<div id="sidetree">
<?php
if (!$group && empty($groups)) {
?>
<div class="wide"><span class="req">Note: </span> There are no user groups yet.</div>
<?php
} else {
?>
<ul class="treeview" id="tree">
<?php
if (!empty($groups)) {
foreach ($groups as $key => $group_item) {
$group_item = (object) $group_item;
?>
示例14: remove_base_rule_from_group
public function remove_base_rule_from_group($group_id, $rule_id)
{
try {
$group = Sentry::group($group_id);
$rule = Rule::find($rule_id);
$permissions = array();
if (isset($group['permissions'])) {
$permissions = json_decode($group['permissions'], true);
}
if (isset($permissions[$rule->rule])) {
unset($permissions[$rule->rule]);
DB::table('config_user_groups')->where('id', '=', $group_id)->update(array('permissions' => json_encode($permissions)));
return true;
}
return false;
} catch (Sentry\SentryException $e) {
throw new Sentry\SentryException($e->getMessage);
}
}
示例15: get_search_items
public function get_search_items($group_id = false)
{
// Override group_id if its a search
$group_id = \Input::get('user_group', $group_id);
if ($group_id && \Sentry::group_exists((int) $group_id)) {
// Get only group users
\View::set_global('group', \Sentry::group((int) $group_id));
$items = \Sentry::group((int) $group_id)->users();
} else {
$items = \Sentry::user()->all('admin');
}
// Reset to empty array if there are no result found by query
if (is_null($items)) {
$items = array();
}
// Get user objects
if (!empty($items)) {
foreach ($items as $key => $item) {
$items[$key] = \Sentry::user((int) $item['id']);
}
// Get search filters
foreach (\Input::get() as $key => $value) {
if (!empty($value) || $value == '0') {
switch ($key) {
case 'title':
foreach ($items as $number => $item) {
if (empty($item['metadata'])) {
unset($items[$number]);
continue;
}
$full_name = $item->get('metadata.first_name') . ' ' . $item->get('metadata.last_name');
if (stripos($full_name, $value) === false) {
unset($items[$number]);
}
}
break;
case 'email':
foreach ($items as $number => $item) {
if (stripos($item->email, $value) === false) {
unset($items[$number]);
}
}
break;
case 'country':
if ($value && $value !== 'false') {
foreach ($items as $number => $item) {
if (empty($item['metadata'])) {
unset($items[$number]);
continue;
}
if (stripos($item->get('metadata.country'), $value) === false) {
unset($items[$number]);
}
}
}
break;
case 'postcode_from':
foreach ($items as $number => $item) {
if (empty($item['metadata'])) {
unset($items[$number]);
continue;
}
if ($item->get('metadata.postcode') < $value) {
unset($items[$number]);
}
}
break;
case 'postcode_to':
foreach ($items as $number => $item) {
if (empty($item['metadata'])) {
unset($items[$number]);
continue;
}
if ($item->get('metadata.postcode') > $value) {
unset($items[$number]);
}
}
break;
}
}
}
}
// Reset to empty array if there are no result found by query
if (is_null($items)) {
$items = array();
}
// Initiate pagination
$pagination = \Hybrid\Pagination::make(array('total_items' => count($items), 'per_page' => \Input::get('per_page', 10), 'uri_segment' => null));
// Remove unwanted items, and show only required ones
$items = array_slice($items, $pagination->offset, $pagination->per_page);
return array('items' => $items, 'pagination' => $pagination);
}