Browse Source
Refactor UsersController
Refactor UsersController
Remove UserRepository and UserPresenter class Add author on class docblockpull/1/head
13 changed files with 49 additions and 299 deletions
-
11app/Entities/Users/Event.php
-
9app/Entities/Users/User.php
-
30app/Entities/Users/UserPresenter.php
-
59app/Entities/Users/UsersRepository.php
-
3app/Http/Controllers/Users/AgencyController.php
-
3app/Http/Controllers/Users/ProfileController.php
-
54app/Http/Controllers/Users/UsersController.php
-
30app/Http/Requests/Users/DeleteRequest.php
-
33app/Http/Requests/Users/UpdateRequest.php
-
56resources/views/layouts/app-no-sidebar.blade.php
-
26resources/views/layouts/partials/top-header.blade.php
-
31resources/views/layouts/partials/top-nav.blade.php
-
3tests/Feature/Users/ManageUsersTest.php
@ -1,30 +0,0 @@ |
|||||
<?php |
|
||||
|
|
||||
namespace App\Entities\Users; |
|
||||
|
|
||||
use Laracasts\Presenter\Presenter; |
|
||||
|
|
||||
class UserPresenter extends Presenter |
|
||||
{ |
|
||||
public function displayRoles() |
|
||||
{ |
|
||||
$string = ''; |
|
||||
|
|
||||
return $string; |
|
||||
} |
|
||||
|
|
||||
public function rolesLink() |
|
||||
{ |
|
||||
$string = ''; |
|
||||
|
|
||||
return $string; |
|
||||
} |
|
||||
|
|
||||
public function usernameRoles() |
|
||||
{ |
|
||||
$string = $this->name.' ('; |
|
||||
$string .= ')'; |
|
||||
|
|
||||
return $string; |
|
||||
} |
|
||||
} |
|
||||
@ -1,59 +0,0 @@ |
|||||
<?php |
|
||||
namespace App\Entities\Users; |
|
||||
|
|
||||
use App\Entities\BaseRepository; |
|
||||
use App\Exceptions\UpdateUserException; |
|
||||
use App\Services\Facades\Option; |
|
||||
|
|
||||
/** |
|
||||
* Users Repository Class |
|
||||
*/ |
|
||||
class UsersRepository extends BaseRepository |
|
||||
{ |
|
||||
|
|
||||
protected $model; |
|
||||
|
|
||||
public function __construct(User $model) |
|
||||
{ |
|
||||
parent::__construct($model); |
|
||||
} |
|
||||
|
|
||||
public function getUsers($q) |
|
||||
{ |
|
||||
return User::where('name', 'like', '%'.$q.'%') |
|
||||
->paginate($this->_paginate); |
|
||||
} |
|
||||
|
|
||||
public function create($userData) |
|
||||
{ |
|
||||
if ($userData['password'] == '') { |
|
||||
$userData['password'] = Option::get('password_default', 'member'); |
|
||||
} |
|
||||
|
|
||||
$user = $this->storeArray($userData); |
|
||||
|
|
||||
return $user; |
|
||||
} |
|
||||
|
|
||||
public function update($userData, $userId) |
|
||||
{ |
|
||||
$user = $this->requireById($userId); |
|
||||
|
|
||||
foreach ($userData as $key => $value) { |
|
||||
$user->{$key} = $value; |
|
||||
} |
|
||||
|
|
||||
if ($user->save()) { |
|
||||
return $user; |
|
||||
} |
|
||||
|
|
||||
throw new UpdateUserException('Failed to update User'); |
|
||||
} |
|
||||
|
|
||||
public function delete($userId) |
|
||||
{ |
|
||||
$user = $this->requireById($userId); |
|
||||
|
|
||||
return $user->delete(); |
|
||||
} |
|
||||
} |
|
||||
@ -1,30 +0,0 @@ |
|||||
<?php |
|
||||
|
|
||||
namespace App\Http\Requests\Users; |
|
||||
|
|
||||
use App\Http\Requests\Request; |
|
||||
|
|
||||
class DeleteRequest extends Request |
|
||||
{ |
|
||||
/** |
|
||||
* Determine if the user is authorized to make this request. |
|
||||
* |
|
||||
* @return bool |
|
||||
*/ |
|
||||
public function authorize() |
|
||||
{ |
|
||||
return $this->user()->can('manage_users'); |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* Get the validation rules that apply to the request. |
|
||||
* |
|
||||
* @return array |
|
||||
*/ |
|
||||
public function rules() |
|
||||
{ |
|
||||
return [ |
|
||||
'user_id' => 'required', |
|
||||
]; |
|
||||
} |
|
||||
} |
|
||||
@ -1,33 +0,0 @@ |
|||||
<?php |
|
||||
|
|
||||
namespace App\Http\Requests\Users; |
|
||||
|
|
||||
use App\Http\Requests\Request; |
|
||||
|
|
||||
class UpdateRequest extends Request |
|
||||
{ |
|
||||
/** |
|
||||
* Determine if the user is authorized to make this request. |
|
||||
* |
|
||||
* @return bool |
|
||||
*/ |
|
||||
public function authorize() |
|
||||
{ |
|
||||
return $this->user()->can('manage_users'); |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* Get the validation rules that apply to the request. |
|
||||
* |
|
||||
* @return array |
|
||||
*/ |
|
||||
public function rules() |
|
||||
{ |
|
||||
return [ |
|
||||
'name' => 'required|min:5', |
|
||||
'email' => 'required|email|unique:users,email,'.$this->segment(2), |
|
||||
'password' => 'nullable|required_with:password_confirmation|between:6,15|confirmed', |
|
||||
'password_confirmation' => 'required_with:password', |
|
||||
]; |
|
||||
} |
|
||||
} |
|
||||
@ -1,56 +0,0 @@ |
|||||
<!DOCTYPE html> |
|
||||
<html lang="en"> |
|
||||
<head> |
|
||||
<meta charset="utf-8"> |
|
||||
<meta name="x-csrf-token" content="<?= csrf_token() ?>"> |
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge"> |
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1"> |
|
||||
<meta name="description" content=""> |
|
||||
<meta name="author" content=""> |
|
||||
<title>@yield('title', Option::get('app_name', 'Aplikasi Laravel'))</title> |
|
||||
|
|
||||
{!! Html::style('assets/css/bootstrap.min.css') !!} |
|
||||
{!! Html::style('assets/css/bootstrap-theme.min.css') !!} |
|
||||
{!! Html::style('assets/css/plugins/metisMenu/metisMenu.min.css') !!} |
|
||||
{!! Html::style('assets/css/font-awesome.min.css') !!} |
|
||||
@yield('ext_css') |
|
||||
{!! Html::style('assets/css/sb-admin-2.css') !!} |
|
||||
{!! Html::style('assets/css/app.css') !!} |
|
||||
</head> |
|
||||
<body> |
|
||||
@include('layouts.partials.top-header') |
|
||||
<div id="wrapper"> |
|
||||
|
|
||||
<div id="page-wrapper" class="page-no-sidebar"> |
|
||||
@include('flash::message') |
|
||||
<div class="container-fluid"> |
|
||||
@yield('content') |
|
||||
</div> |
|
||||
<!-- /.container-fluid --> |
|
||||
</div> |
|
||||
<!-- /#page-wrapper -->
|
|
||||
@include('layouts.partials.footer') |
|
||||
</div> |
|
||||
<!-- /#wrapper -->
|
|
||||
|
|
||||
{!! Html::script(url('assets/js/jquery.js')) !!} |
|
||||
{!! Html::script(url('assets/js/bootstrap.min.js')) !!} |
|
||||
{!! Html::script(url('assets/js/plugins/metisMenu/metisMenu.min.js')) !!} |
|
||||
@yield('ext_js') |
|
||||
{!! Html::script(url('assets/js/sb-admin-2.js')) !!} |
|
||||
|
|
||||
<script type="text/javascript"> |
|
||||
(function() { |
|
||||
$("div.alert.notifier, div.alert.add-cart-notifier").delay(5000).slideUp('slow'); |
|
||||
$.ajaxSetup({ |
|
||||
headers: { |
|
||||
'X-CSRF-Token': $('meta[name="x-csrf-token"]').attr('content') |
|
||||
} |
|
||||
}); |
|
||||
})(); |
|
||||
</script> |
|
||||
|
|
||||
@yield('script') |
|
||||
|
|
||||
</body> |
|
||||
</html> |
|
||||
@ -1,26 +0,0 @@ |
|||||
<div class="hidden-print" style="padding:10px 10px;vertical-align:middle"> |
|
||||
@if (auth()->user()) |
|
||||
<div class="pull-right hidden-xs" style="position: absolute; left: auto; right: 0;"> |
|
||||
<div class="panel panel-warning text-center"> |
|
||||
<div class="panel-heading" style="margin:auto 0"> |
|
||||
User: {{ auth()->user()->present()->usernameRoles }} |
|
||||
<br> |
|
||||
<a href="{{ route('auth.logout') }}"><i class="fa fa-sign-out fa-fw"></i> Keluar</a> |
|
||||
</div> |
|
||||
</div> |
|
||||
</div> |
|
||||
@endif |
|
||||
<a class="logo-brand" title="{{ Option::get('app_name', 'Aplikasi Laravel') }}" href="{{ route('home') }}"> |
|
||||
<img src="{{ url('assets/imgs/logo.png') }}" alt="Logo {{ Option::get('agency_name', 'Aplikasi Laravel') }}" width="60px"> |
|
||||
<h1>{{ Option::get('app_name', 'Aplikasi Laravel') }} <br><small>{{ Option::get('agency_tagline', 'Tagline Aplikasi Laravel') }}</small></h1> |
|
||||
</a> |
|
||||
</div> |
|
||||
|
|
||||
<nav class="navbar navbar-default hidden-md" role="navigation" style="margin-bottom: 0"> |
|
||||
<div class="navbar-header"> |
|
||||
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse"> |
|
||||
<span class="sr-only">Toggle navigation</span> |
|
||||
Menu |
|
||||
</button> |
|
||||
</div> |
|
||||
</nav> |
|
||||
@ -1,31 +0,0 @@ |
|||||
<!-- Navigation --> |
|
||||
<nav class="navbar navbar-default navbar-static-top" role="navigation" style="margin-bottom: 0"> |
|
||||
<div class="navbar-header"> |
|
||||
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse"> |
|
||||
<span class="sr-only">Toggle navigation</span> |
|
||||
Menu |
|
||||
</button> |
|
||||
<a class="navbar-brand" title="Home | {{ Option::get('agency_tagline', 'Laravel app description') }}" href="{{ route('home') }}"> |
|
||||
{{ Option::get('app_name', 'Laravel') }} |
|
||||
</a> |
|
||||
</div> |
|
||||
<!-- /.navbar-header --> |
|
||||
|
|
||||
<ul class="nav navbar-top-links navbar-right"> |
|
||||
<li class="dropdown"> |
|
||||
<a class="dropdown-toggle" data-toggle="dropdown" href="#"> |
|
||||
<i class="fa fa-user fa-fw"></i> {{ auth()->check() ? auth()->user()->name : 'Guest' }} <i class="fa fa-caret-down"></i> |
|
||||
</a> |
|
||||
<ul class="dropdown-menu dropdown-user"> |
|
||||
<li><a href="#">{{ auth()->user()->present()->usernameRoles }}</a></li> |
|
||||
<li><a href="{{ route('auth.profile') }}"><i class="fa fa-user fa-fw"></i> Profil</a></li> |
|
||||
<li><a href="{{ route('auth.change-password') }}"><i class="fa fa-lock fa-fw"></i> Ganti Password</a></li> |
|
||||
<li class="divider"></li> |
|
||||
<li><a href="{{ route('auth.logout') }}"><i class="fa fa-sign-out fa-fw"></i> Logout</a></li> |
|
||||
</ul> |
|
||||
<!-- /.dropdown-user --> |
|
||||
</li> |
|
||||
<!-- /.dropdown --> |
|
||||
</ul> |
|
||||
<!-- /.navbar-top-links --> |
|
||||
</nav> |
|
||||
Write
Preview
Loading…
Cancel
Save
Reference in new issue