Compare commits

...

7 Commits
master ... dev

Author SHA1 Message Date
5bb05e72f6 Update button add 2023-10-02 09:39:35 +07:00
Daeng Deni Mardaeni
daab5a3184 add breadcrumb 2023-09-27 16:45:44 +07:00
Daeng Deni Mardaeni
a2135cf4af update column users action 2023-09-27 15:44:58 +07:00
Daeng Deni Mardaeni
9daedaedc5 update migrations 2023-09-27 15:06:21 +07:00
Daeng Deni Mardaeni
b153558a25 update migrations 2023-09-27 15:06:08 +07:00
375463fc77 udpate seeder 2023-08-10 22:33:52 +07:00
a30879a337 update release for sit 2023-08-10 21:26:56 +07:00
23 changed files with 387 additions and 72 deletions

View File

@ -3,6 +3,7 @@
namespace Modules\Usermanager\DataTables;
use Modules\Usermanager\Entities\User;
use Yajra\DataTables\EloquentDataTable;
use Yajra\DataTables\Html\Column;
use Yajra\DataTables\Services\DataTable;
@ -18,8 +19,7 @@
public function dataTable($query)
{
return datatables()
->eloquent($query)
return (new EloquentDataTable($query))
->filter(function ($query) {
$search = request()->get('search');
if ($search['value'] !== "") {
@ -27,10 +27,19 @@
->orWhere('email', 'like', "%" . $search['value'] . "%");
}
})
->rawColumns(['action'])
->rawColumns(['action','last_login_at'])
->addIndexColumn()
->editColumn('user', function (User $model) {
return view('usermanager::users.users.columns._user', compact('model'));
})
->editColumn('role', function (User $user) {
return ucwords($user->roles->first()?->name);
})
->editColumn('last_login_at', function (User $user) {
return sprintf('<div class="badge badge-light fw-bold">%s</div>', $user->last_login_at ? $user->last_login_at->diffForHumans() : $user->updated_at->diffForHumans());
})
->addColumn('action', function (User $model) {
return view('usermanager::users.users._action', compact('model'));
return view('usermanager::users.users.columns._action', compact('model'));
});
}
@ -77,7 +86,9 @@
{
return [
Column::make('DT_RowIndex')->title('No')->orderable(false)->searchable(false),
Column::make('name')->title(__('Name')),
Column::make('user')->addClass('d-flex align-items-center')->name('name'),
Column::make('role')->searchable(false),
Column::make('last_login_at')->title('Last Login'),
Column::make('email'),
Column::computed('action')
->exportable(false)

View File

@ -18,6 +18,7 @@
$table->string('email')->unique();
$table->timestamp('email_verified_at')->nullable();
$table->string('password');
$table->string('avatar')->nullable();
$table->rememberToken();
$table->timestamps();
$table->softDeletes();

View File

@ -0,0 +1,29 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration {
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('users', function (Blueprint $table) {
$table->datetime('last_login_at')->nullable();
$table->string('last_login_ip')->nullable();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('users', function (Blueprint $table) {
$table->removeColumn('last_login_at');
$table->removeColumn('last_login_ip');
});
}
};

View File

@ -0,0 +1,34 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration {
/**
* Run the migrations.
*/
public function up()
: void
{
Schema::table('users', function (Blueprint $table) {
$table->foreignId('directorat_id')->nullable();
$table->foreignId('sub_directorat_id')->nullable();
});
}
/**
* Reverse the migrations.
*/
public function down()
: void
{
Schema::withoutForeignKeyConstraints(function () {
Schema::table('users', function (Blueprint $table) {
$table->dropColumn('directorat_id');
$table->dropColumn('sub_directorat_id');
});
});
}
};

View File

@ -0,0 +1,27 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration {
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('users', function (Blueprint $table) {
$table->string('profile_photo_path', 2048)->nullable()->after('email');
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('users', function (Blueprint $table) {
$table->dropColumn('profile_photo_path');
});
}
};

View File

@ -28,7 +28,12 @@
return [
['name' => 'User'],
['name' => 'Role'],
['name' => 'Permission']
['name' => 'Permission'],
['name' => 'system'],
['name' => 'master'],
['name' => 'document'],
['name' => 'setting'],
['name' => 'logs']
];
}
}

View File

@ -17,7 +17,7 @@
{
//app()[\Spatie\Permission\PermissionRegistrar::class]->forgetCachedPermissions();
$data = $this->data();
/*$data = $this->data();
foreach ($data as $value) {
$permission = Permission::updateOrCreate([
@ -37,22 +37,49 @@
}
}
}
}*/
$roles = Role::all();
foreach ($roles as $role) {
$data = $this->data($role->name);
foreach ($data as $value) {
$permission = Permission::updateOrCreate([
'name' => $value['name'],
'guard_name' => 'web' // or 'api
], [
'permission_group_id' => $value['group']
]);
if($role->name=='ad' && explode('.',$value['name'])[0]=='document'){
if($permission->name=='document.read'){
$role->givePermissionTo($permission);
}
} else{
$role->givePermissionTo($permission);
}
}
}
}
public function data()
public function data($role)
{
$data = [];
$model = [];
// list of model permission
$model = ['user', 'role', 'permission'];
$i = 1;
foreach ($model as $value) {
foreach ($this->crudActions($value) as $action) {
$data[] = ['name' => $action, 'group' => $i];
if ($role == 'administrator') {
$model = [['id' => 1, 'name' => 'user'], ['id' => 2, 'name' => 'role'], ['id' => 3, 'name' => 'permission'], ['id' => 4, 'name' => 'system'], ['id' => 5, 'name' => 'master'], ['id' => 6, 'name' => 'document'], ['id' => 7, 'name' => 'setting'], ['id' => 8, 'name' => 'logs']];
} elseif($role == 'ad'){
$model = [['id' => 4, 'name' => 'system'], ['id' => 6, 'name' => 'document'], ['id' => 7, 'name' => 'setting'], ['id' => 8, 'name' => 'logs']];
} elseif($role == 'dd'){
$model = [['id' => 4, 'name' => 'system'], ['id' => 5, 'name' => 'master'], ['id' => 6, 'name' => 'document'], ['id' => 7, 'name' => 'setting']];
} elseif($role == 'eo'){
$model = [['id' => 6, 'name' => 'document']];
}
foreach ($model as $value) {
foreach ($this->crudActions($value['name']) as $action) {
$data[] = ['name' => $action, 'group' => $value['id']];
}
$i++;
}
return $data;
@ -62,7 +89,7 @@
{
$actions = [];
// list of permission actions
$crud = ['create', 'read', 'update', 'delete'];
$crud = ['create', 'read', 'update', 'delete','authorize','report'];
foreach ($crud as $value) {
$actions[] = $name . '.' . $value;

View File

@ -27,7 +27,11 @@
{
return [
['name' => 'administrator'],
['name' => 'user'],
['name' => 'ad'],
['name' => 'dd'],
['name' => 'eo'],
['name' => 'siskon'],
['name' => 'siskon_otorisator']
];
}
}

View File

@ -17,24 +17,56 @@
*/
public function run(Generator $faker)
{
$roleAdmin = Role::find(1);
$roleUser = Role::find(2);
$roles = Role::all();
$user = User::create([
'name' => $faker->name,
'email' => 'demo@demo.com',
'password' => Hash::make('demo'),
'email_verified_at' => now(),
]);
$admin = User::create([
foreach ($roles as $role) {
if ($role->name == 'administrator') {
$admin = User::create(
[//ad dd ao
'name' => $faker->name,
'email' => 'admin@demo.com',
'password' => Hash::make('demo'),
'email_verified_at' => now(),
]);
]
);
$admin->assignRole($role);
}
$admin->assignRole($roleAdmin,);
$user->assignRole($roleUser);
if ($role->name == 'ad') {
$admin = User::create(
[//ad dd ao
'name' => "Associate Director",
'email' => '230700',
'password' => Hash::make('bagbag'),
'email_verified_at' => now(),
]
);
$admin->assignRole($role);
}
if ($role->name == 'dd') {
$admin = User::create(
[//ad dd ao
'name' => "Deputy Director",
'email' => '230701',
'password' => Hash::make('bagbag'),
'email_verified_at' => now(),
]
);
$admin->assignRole($role);
}
if ($role->name == 'eo') {
$admin = User::create(
[//ad dd ao
'name' => "Executive Officer",
'email' => '230702',
'password' => Hash::make('bagbag'),
'email_verified_at' => now(),
]
);
$admin->assignRole($role);
}
}
}
}

View File

@ -28,7 +28,7 @@
: LogOptions
{
return LogOptions::defaults()->logAll()
->useLogName('Cetak Label : ');
->useLogName('Module : ');
}
}

View File

@ -24,7 +24,12 @@
protected $fillable = [
'name',
'email',
'password'
'password',
'last_login_at',
'last_login_ip',
'profile_photo_path',
'direktorat_id',
'sub_direktorat_id',
];
/**
@ -44,5 +49,15 @@
*/
protected $casts = [
'email_verified_at' => 'datetime',
'last_login_at' => 'datetime',
];
public function getProfilePhotoUrlAttribute()
{
if ($this->profile_photo_path) {
return asset('storage/' . $this->profile_photo_path);
}
return $this->profile_photo_path;
}
}

View File

@ -5,6 +5,7 @@
use App\Http\Controllers\Controller;
use App\Providers\RouteServiceProvider;
use Illuminate\Http\Request;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\Auth;
use Modules\Usermanager\Http\Requests\LoginRequest;
@ -23,6 +24,11 @@
$request->session()->regenerate();
$request->user()->update([
'last_login_at' => Carbon::now()->toDateTimeString(),
'last_login_ip' => $request->getClientIp()
]);
return redirect()->intended(RouteServiceProvider::HOME);
}

View File

@ -34,6 +34,8 @@
'name' => $request->name,
'email' => $request->email,
'password' => Hash::make($request->password),
'last_login_at' => \Illuminate\Support\Carbon::now()->toDateTimeString(),
'last_login_ip' => $request->getClientIp()
]);
event(new Registered($user));

View File

@ -0,0 +1,54 @@
<?php
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use App\Models\User;
use Illuminate\Auth\Events\Verified;
use Laravel\Socialite\Facades\Socialite;
class SocialiteController extends Controller
{
public function redirect($provider)
{
// redirect from social site
if (request()->input('state')) {
// already logged in
// get user info from social site
$user = Socialite::driver($provider)->stateless()->user();
// check for existing user
$existingUser = User::where('email', $user->getEmail())->first();
if ($existingUser) {
auth()->login($existingUser, true);
return redirect()->to('/');
}
$newUser = $this->createUser($user);
auth()->login($newUser, true);
}
// request login from social site
return Socialite::driver($provider)->redirect();
}
function createUser($user)
{
$user = User::updateOrCreate([
'email' => $user->getEmail(),
], [
'name' => $user->getName(),
'password' => '',
'avatar' => $user->getAvatar(),
]);
if ($user->markEmailAsVerified()) {
event(new Verified($user));
}
return $user;
}
}

View File

@ -29,7 +29,7 @@
public function rules()
{
return [
'email' => ['required', 'string', 'email'],
'email' => ['required', 'string'],
'password' => ['required', 'string'],
];
}

View File

@ -5,17 +5,14 @@
@csrf
<!--begin::Heading-->
<div class="text-center mb-11">
<img alt="Logo" src="{{ image('logos/logo_agi.png') }}" class="h-150px app-sidebar-logo-default" style="margin-bottom: 100px;" />
<!--begin::Title-->
<h1 class="text-dark fw-bolder mb-3">
Sign In
</h1>
<!--end::Title-->
<!--begin::Subtitle-->
<div class="text-gray-500 fw-semibold fs-6">
Your Social Campaigns
</div>
<!--end::Subtitle--->
</div>
<!--begin::Heading-->
@ -34,18 +31,6 @@
</div>
<!--end::Input group--->
<!--begin::Wrapper-->
<div class="d-flex flex-stack flex-wrap gap-3 fs-base fw-semibold mb-8">
<div></div>
<!--begin::Link-->
<a href="/forgot-password" class="link-primary">
Forgot Password ?
</a>
<!--end::Link-->
</div>
<!--end::Wrapper-->
<!--begin::Submit button-->
<div class="d-grid mb-10">
<button type="submit" id="kt_sign_in_submit" class="btn btn-primary">
@ -53,16 +38,6 @@
</button>
</div>
<!--end::Submit button-->
<!--begin::Sign up-->
<div class="text-gray-500 text-center fw-semibold fs-6">
Not a Member yet?
<a href="/register" class="link-primary">
Sign up
</a>
</div>
<!--end::Sign up-->
</form>
<!--end::Form-->

View File

@ -2,6 +2,14 @@
$route = explode('.', Route::currentRouteName());
@endphp
@section('title')
Permissions
@endsection
@section('breadcrumbs')
{{ Breadcrumbs::render('user.permissions') }}
@endsection
<x-default-layout>
<!--begin::Card-->
<div class="card card-xxl-stretch mb-5 mb-xl-8">
@ -84,6 +92,17 @@
<div id="kt_datatable_example_buttons" class="d-none"></div>
<!--end::Hide default export buttons-->
<!--begin::Toolbar-->
<div class="d-flex justify-content-end ms-5" data-kt-user-table-toolbar="base">
<!--begin::Add user-->
<button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#kt_modal_user_permissions">
{!! getIcon('plus', 'fs-2', '', 'i') !!}
Add Permission
</button>
<!--end::Add user-->
</div>
<!--end::Toolbar-->
</div>
</div>
<div class="card-body pt-6">

View File

@ -2,6 +2,14 @@
$route = explode('.', Route::currentRouteName());
@endphp
@section('title')
Roles
@endsection
@section('breadcrumbs')
{{ Breadcrumbs::render('user.roles') }}
@endsection
<x-default-layout>
<!--begin::Card-->
<div class="card card-xxl-stretch mb-5 mb-xl-8">
@ -84,6 +92,17 @@
<div id="kt_datatable_example_buttons" class="d-none"></div>
<!--end::Hide default export buttons-->
<!--begin::Toolbar-->
<div class="d-flex justify-content-end ms-5" data-kt-user-table-toolbar="base">
<!--begin::Add user-->
<button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#kt_modal_user_roles">
{!! getIcon('plus', 'fs-2', '', 'i') !!}
Add Role
</button>
<!--end::Add user-->
</div>
<!--end::Toolbar-->
</div>
</div>
<div class="card-body pt-6">

View File

@ -0,0 +1,26 @@
@php
$route = explode('.', Route::currentRouteName());
@endphp
<!--begin:: Avatar -->
<div class="symbol symbol-circle symbol-50px overflow-hidden me-3">
<a href="{{ route($route[0].'.'.$route[1].'.show', $model) }}">
@if($model->profile_photo_url)
<div class="symbol-label">
<img src="{{ $model->profile_photo_url }}" class="w-100"/>
</div>
@else
<div class="symbol-label fs-3 {{ app(\App\Actions\GetThemeType::class)->handle('bg-light-? text-?', $model->name) }}">
{{ substr($model->name, 0, 1) }}
</div>
@endif
</a>
</div>
<!--end::Avatar-->
<!--begin::User details-->
<div class="d-flex flex-column">
<a href="{{ route($route[0].'.'.$route[1].'.show', $model) }}" class="text-gray-800 text-hover-primary mb-1">
{{ $model->name }}
</a>
<span>{{ $model->email }}</span>
</div>
<!--begin::User details-->

View File

@ -2,6 +2,14 @@
$route = explode('.', Route::currentRouteName());
@endphp
@section('title')
Users
@endsection
@section('breadcrumbs')
{{ Breadcrumbs::render('users') }}
@endsection
<x-default-layout>
<!--begin::Card-->
<div class="card card-xxl-stretch mb-5 mb-xl-8">
@ -32,7 +40,6 @@
</div>
<div class="card-toolbar">
<!--begin::Export dropdown-->
<button type="button" class="btn btn-light-primary" data-kt-menu-trigger="click"
data-kt-menu-placement="bottom-end">
@ -84,6 +91,17 @@
<div id="kt_datatable_example_buttons" class="d-none"></div>
<!--end::Hide default export buttons-->
<!--begin::Toolbar-->
<div class="d-flex justify-content-end ms-5" data-kt-user-table-toolbar="base">
<!--begin::Add user-->
<button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#kt_modal_user_users">
{!! getIcon('plus', 'fs-2', '', 'i') !!}
Add User
</button>
<!--end::Add user-->
</div>
<!--end::Toolbar-->
</div>
</div>
<div class="card-body pt-6">

View File

@ -19,15 +19,7 @@
Route::get('login', [AuthenticatedSessionController::class, 'create'])
->name('login');
if (isset($_ENV['METHOD_AUTH'])) {
if ($_ENV['METHOD_AUTH'] == 'usermanager') {
Route::post('login', [AuthenticatedSessionController::class, 'storeUserManager']);
}else {
Route::post('login', [AuthenticatedSessionController::class, 'store']);
}
} else {
Route::post('login', [AuthenticatedSessionController::class, 'store']);
}
Route::get('forgot-password', [PasswordResetLinkController::class, 'create'])

19
Routes/breadcrumbs.php Normal file
View File

@ -0,0 +1,19 @@
<?php
use Diglactic\Breadcrumbs\Breadcrumbs;
use Diglactic\Breadcrumbs\Generator as BreadcrumbTrail;
Breadcrumbs::for('users', function (BreadcrumbTrail $trail) {
$trail->parent('home');
$trail->push('Users', route('user.users.index'));
});
Breadcrumbs::for('user.roles', function (BreadcrumbTrail $trail) {
$trail->parent('users');
$trail->push('Roles', route('user.roles.index'));
});
Breadcrumbs::for('user.permissions', function (BreadcrumbTrail $trail) {
$trail->parent('users');
$trail->push('Permissions', route('user.permissions.index'));
});