Skip to content

Commit

Permalink
Merge pull request #2114 from LuckyCyborg/4.0
Browse files Browse the repository at this point in the history
Overall improvements
  • Loading branch information
LuckyCyborg authored Sep 9, 2018
2 parents a41ec6f + 474d032 commit 140a51c
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 61 deletions.
2 changes: 1 addition & 1 deletion app/Platform/Bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
// Define The Application Version
//--------------------------------------------------------------------------

define('VERSION', '4.0.91');
define('VERSION', '4.0.92');

//--------------------------------------------------------------------------
// Set PHP Error Reporting Options
Expand Down
60 changes: 5 additions & 55 deletions modules/Users/Controllers/Admin/Users.php
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ public function store(Request $request)

// Update the Custom Fields.
foreach ($items as $item) {
$value = Arr::get($input, $name = $item->name);
$value = Arr::get($input, $name = $item->getAttribute('name'));

$field = Field::create(array(
'name' => $name,
Expand Down Expand Up @@ -393,9 +393,11 @@ public function update(Request $request, $id)

// Update the Custom Fields.
foreach ($items as $item) {
$value = Arr::get($input, $name = $item->name);
$value = Arr::get($input, $name = $item->getAttribute('name'));

if (! is_null($field = $user->fields->findBy('name', $name))) {
$field = $user->fields->findBy('name', $name);

if (! is_null($field)) {
$field->value = $value;

$field->save();
Expand Down Expand Up @@ -451,56 +453,4 @@ public function destroy($id)
return Redirect::to('admin/users')
->with('success', __d('users', 'The User <b>{0}</b> was successfully deleted.', $user->username));
}

public function search()
{
// Authorize the current User.
if (Gate::denies('lists', User::class)) {
throw new AuthorizationException();
}

// Validation rules
$rules = array(
'query' => 'required|min:4|valid_query'
);

$messages = array(
'valid_query' => __d('users', 'The :attribute field is not a valid query string.'),
);

$attributes = array(
'query' => __('Search Query'),
);

// Add the custom Validation Rule commands.
Validator::extend('valid_query', function($attribute, $value, $parameters)
{
return (preg_match('/^[\p{L}\p{N}_\-\s]+$/', $value) === 1);
});

// Validate the Input data.
$input = Input::only('query');

$validator = Validator::make($input, $rules, $messages, $attributes);

if($validator->fails()) {
return Redirect::back()->withErrors($validator->errors());
}

// Search the Records on Database.
$search = $input['query'];

$users = User::where('username', 'LIKE', '%' .$search .'%')
->orWhere('email', 'LIKE', '%' .$search .'%')
->orWhere('realname', 'LIKE', '%' .$search .'%')
->paginate(15);

// Prepare the Query for displaying.
$search = htmlentities($search);

return $this->createView()
->shares('title', __d('users', 'Searching Users for: {0}', $search))
->with('search', $search)
->with('users', $users);
}
}
2 changes: 1 addition & 1 deletion modules/Users/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class User extends BaseModel implements UserInterface, RemindableInterface
/**
* @var array
*/
protected $fillable = array('username', 'password', 'email', 'remember_token', 'api_token');
protected $fillable = array('username', 'realname', 'password', 'email', 'remember_token', 'api_token');

/**
* @var array
Expand Down
3 changes: 0 additions & 3 deletions modules/Users/Routes/Web.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@
Route::post('users/fields/{id}', 'FieldItems@update');
Route::post('users/fields/{id}/destroy', 'FieldItems@destroy');

// The Users Search.
Route::get('users/search', 'Users@search');

// Server Side Processor for Users DataTable.
Route::post('users/data', 'Users@data');

Expand Down
2 changes: 1 addition & 1 deletion themes/AdminLite/Views/Layouts/Backend.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@
<!-- sidebar: style can be found in sidebar.less -->
<section class="sidebar">
<!-- search form -->
<form action="<?= site_url('admin/users/search'); ?>" method="GET" class="sidebar-form">
<form action="#" method="GET" class="sidebar-form">
<div class="input-group">
<input type="text" name="query" class="form-control" placeholder="<?= __d('admin_lite', 'Search...'); ?>">
<span class="input-group-btn">
Expand Down

0 comments on commit 140a51c

Please sign in to comment.