diff --git a/app/Helpers/custom.php b/app/Helpers/custom.php
new file mode 100644
index 0000000..edfed86
--- /dev/null
+++ b/app/Helpers/custom.php
@@ -0,0 +1,156 @@
+where('ms_group_id', session('group_id'))->first();
+ $query = count(array_intersect((array)$access, (array)$model->access));
+ } else {
+ $query = MasterAccessMenu::where($access, true)->where('module', 'LIKE', $key.'%')->where('ms_group_id', session('group_id'))->count();
+ }
+ } else {
+ $query = MasterAccessMenu::where($access, true)->where('ms_menu_id', $key)->where('ms_group_id', session('group_id'))->count();
+ }
+
+ if ($query > 0) {
+ return true;
+ } else {
+ return false;
+ }
+ } else {
+ return true;
+ }
+
+ }
+}
+
+if (!function_exists('renderMenu')) {
+
+ /**
+ * Loops through a folder and requires all PHP files
+ * Searches sub-directories as well.
+ *
+ * @param $folder
+ */
+ function renderMenu()
+ {
+ $active = true;
+ $parent = MasterMenu::where('status',true)->where('menu_type','sidebar')->where('parent_id',0)->get();
+ $html = '';
+ foreach ($parent as $p1) {
+ // echo $p1->MsMenuId.'
';
+ $child2 = MasterMenu::where('status',true)->where('menu_type','sidebar')->where('parent_id',$p1->MsMenuId)->get();
+ $access1 = permission('is_read', $p1->MsMenuId, 'menu', true);
+
+ $ch1 = count($child2) > 0 ? '' : '';
+ $link1 = count($child2) > 0 ? '' : 'menu-link';
+
+ if ($access1) {
+ $active1 = $active ? ' ' . null : null;
+
+ $html .= '
' . @$p1->title.'';
+ if (count($child2) > 0) {
+ $html .= '';
+ $html .= '';
+ } else {
+ $html .= '';
+ }
+ $html .= '';
+ }
+ }
+ return $html;
+ }
+}
+
+if (!function_exists('include_route_files')) {
+ /**
+ * Loops through a folder and requires all PHP files
+ * Searches sub-directories as well.
+ *
+ * @param $folder
+ */
+ function include_route_files($folder)
+ {
+ include_files_in_folder($folder);
+ }
+}
+
+if (!function_exists('include_files_in_folder')) {
+ /**
+ * Loops through a folder and requires all PHP files
+ * Searches sub-directories as well.
+ *
+ * @param $folder
+ */
+ function include_files_in_folder($folder)
+ {
+ try {
+ $rdi = new RecursiveDirectoryIterator($folder);
+ $it = new RecursiveIteratorIterator($rdi);
+
+ while ($it->valid()) {
+ if (!$it->isDot() && $it->isFile() && $it->isReadable() && $it->current()->getExtension() === 'php') {
+ require $it->key();
+ }
+
+ $it->next();
+ }
+ } catch (Exception $e) {
+ echo $e->getMessage();
+ }
+ }
+}
\ No newline at end of file
diff --git a/app/Http/Controllers/Auth/CustomLoginController.php b/app/Http/Controllers/Auth/CustomLoginController.php
index e92a8c3..de56c7f 100644
--- a/app/Http/Controllers/Auth/CustomLoginController.php
+++ b/app/Http/Controllers/Auth/CustomLoginController.php
@@ -19,30 +19,82 @@ class CustomLoginController extends Controller
public function post_login(Request $request)
{
Validator::make($request->all(), [
- 'email' => 'required|email',
+ 'email' => 'required',
'password' => 'required',
])->validate();
$credentials = array('email' => $request->email, 'password' => $request->password);
$user = User::where('email', $credentials['email'])->first();
+ if(!@$user){
+ $user = User::where('username', $credentials['email'])->first();
- if ($user && Hash::check($credentials['password'], $user->password)) {
- Auth::attempt(['email' => $request->email, 'password' => $request->password]);
+ if ($user && Hash::check($credentials['password'], $user->password)) {
+ Auth::attempt(['username' => $request->email, 'password' => $request->password]);
- return redirect('dashboard')->with([
- 'message' => trans('Selamat datang kembali'),
- 'type' => "success"
- ]);
-
+ $session = [
+ 'username' => $user->username,
+ 'name' => $user->name,
+ 'email' => $user->email,
+ 'npsn' => @$user->sekolah->npsn,
+ 'ms_tingkat_sekolah_id' => @$user->sekolah->ms_tingkat_sekolah_id,
+ 'status_sekolah' => @$user->sekolah->status_sekolah,
+ 'alamat_sekolah' => @$user->sekolah->alamat_sekolah,
+ 'kontak_person' => @$user->sekolah->kontak_person,
+ 'telp' => @$user->sekolah->telp,
+ 'currYear' => date('Y'),
+ 'group_id' => @$user->ms_group_id,
+ ];
+ session($session);
+
+ return redirect('dashboard')->with([
+ 'message' => trans('Selamat datang kembali'),
+ 'type' => "success"
+ ]);
+
+ }else{
+ return redirect('/login')
+ ->withInput()
+ ->with([
+ 'message' => trans('Akun anda tidak ditemukan'),
+ 'type' => "error"
+ ]);
+ }
}else{
- return redirect('/login')
- ->withInput()
- ->with([
- 'message' => trans('Akun anda tidak ditemukan'),
- 'type' => "error"
- ]);
+ if ($user && Hash::check($credentials['password'], $user->password)) {
+ Auth::attempt(['email' => $request->email, 'password' => $request->password]);
+
+ $session = [
+ 'username' => $user->username,
+ 'name' => $user->name,
+ 'email' => $user->email,
+ 'npsn' => @$user->sekolah->npsn,
+ 'ms_tingkat_sekolah_id' => @$user->sekolah->ms_tingkat_sekolah_id,
+ 'status_sekolah' => @$user->sekolah->status_sekolah,
+ 'alamat_sekolah' => @$user->sekolah->alamat_sekolah,
+ 'kontak_person' => @$user->sekolah->kontak_person,
+ 'telp' => @$user->sekolah->telp,
+ 'currYear' => date('Y'),
+ 'group_id' => @$user->ms_group_id,
+ ];
+ session($session);
+
+ return redirect('dashboard')->with([
+ 'message' => trans('Selamat datang kembali'),
+ 'type' => "success"
+ ]);
+
+ }else{
+ return redirect('/login')
+ ->withInput()
+ ->with([
+ 'message' => trans('Akun anda tidak ditemukan'),
+ 'type' => "error"
+ ]);
+ }
}
+
+
}
public function logout()
diff --git a/app/Http/Controllers/Auth/CustomRegisterController.php b/app/Http/Controllers/Auth/CustomRegisterController.php
index 93f5dbe..36a1d79 100644
--- a/app/Http/Controllers/Auth/CustomRegisterController.php
+++ b/app/Http/Controllers/Auth/CustomRegisterController.php
@@ -9,6 +9,7 @@ use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Hash;
use Illuminate\Http\Request;
use App\Models\User;
+use App\Models\Master\MasterGroupUser;
use App\Models\ProfileSekolah as Profile;
class CustomRegisterController extends Controller
@@ -48,6 +49,7 @@ class CustomRegisterController extends Controller
$user = new User;
$user->email = $request->email;
+ $user->username = $request->npsn;
$user->password = Hash::make($request->password);
$user->name = $request->name;
$user->save();
@@ -62,6 +64,11 @@ class CustomRegisterController extends Controller
$profile->telp = $request->telp;
$profile->save();
+ $group = new MasterGroupUser;
+ $group->user_id = $user->id;
+ $group->ms_group_id = 2; //sekolah
+ $group->save();
+
return redirect('/login')->with([
'message' => 'Berhasil membuat akun baru, silahkan login',
'type' => 'success',
diff --git a/app/Http/Controllers/HomeController.php b/app/Http/Controllers/HomeController.php
index 7cbc2c3..bb63742 100644
--- a/app/Http/Controllers/HomeController.php
+++ b/app/Http/Controllers/HomeController.php
@@ -25,4 +25,10 @@ class HomeController extends Controller
{
return view('home');
}
+
+ public function dashboard()
+ {
+ $data['title'] = 'Dashboard';
+ return view('home',$data);
+ }
}
diff --git a/app/Http/Controllers/Management/RoleController.php b/app/Http/Controllers/Management/RoleController.php
new file mode 100644
index 0000000..fac18aa
--- /dev/null
+++ b/app/Http/Controllers/Management/RoleController.php
@@ -0,0 +1,65 @@
+belongsTo(MasterGroup::class, 'ms_group_id','MsGroupId');
+ }
+
+ public function user()
+ {
+ return $this->belongsTo(\App\Models\User::class, 'user_id','id');
+ }
}
diff --git a/app/Models/Master/MasterMenu.php b/app/Models/Master/MasterMenu.php
index ece78e9..39925e1 100644
--- a/app/Models/Master/MasterMenu.php
+++ b/app/Models/Master/MasterMenu.php
@@ -23,4 +23,196 @@ class MasterMenu extends Model
'created_by',
'updated_by',
];
+
+ public function submenu()
+ {
+ return $this->hasMany(MasterMenu::class,'parent_id','id');
+ }
+
+ public static function coreMenus($type, array $status = [1]): mixed
+ {
+ return MasterMenu::where('parent_id', '=', 0)
+ ->where('menu_type', '=', $type)
+ ->whereIn('status', $status);
+ }
+
+ public static function coreMenusByParent($id, array $status = [1]): mixed
+ {
+ return MasterMenu::where('parent_id', '=', $id)
+ ->whereIn('status', $status);
+ }
+
+ public static function getMenuByParentPosition($id, $type, array $active = [1], int $year = null): mixed
+ {
+ if ($year) {
+ $currYear = $year;
+ } else {
+ $currYear = date('Y');
+ }
+
+ return MasterMenu::where('parent_id', '=', $id)
+ ->where('menu_type', '=', $type)
+ ->whereIn('status', $active)
+ ->union(MasterMenu::coreMenus($type, $active))
+ ->orderBy('ordering')
+ ->get();
+ }
+
+ /**
+ * @author alex.gz
+ * @created 08/12/2023 12:53
+ *
+ * @param $type
+ * @param int|null $year
+ *
+ * @return mixed
+ */
+ public static function getParentByType($type, int $year = null): mixed
+ {
+ if ($year) {
+ $currYear = $year;
+ } else {
+ $currYear = date('Y');
+ }
+
+ return MasterMenu::where('parent_id', '=', 0)
+ ->where('menu_type', '=', $type)
+ ->union(MasterMenu::coreMenus($type))
+ ->orderBy('ordering')
+ ->get();
+ }
+
+ /**
+ * @author alex.gz
+ * @created 08/12/2023 18:07
+ *
+ * @param $type
+ * @param int|null $year
+ *
+ * @return mixed
+ */
+ public static function getMenuByYear($type, int $year = null): mixed
+ {
+ if ($year) {
+ $currYear = $year;
+ } else {
+ $currYear = date('Y');
+ }
+
+ return MasterMenu::where('parent_id', '=', 0)
+ ->where('menu_type', '=', $type)
+ ->where('status', '=', true)
+ ->orderBy('ordering')
+ ->get();
+ }
+
+ /**
+ * @author alex.gz
+ * @created 08/12/2023 12:54
+ *
+ * @param $type
+ * @param int|null $year
+ *
+ * @return mixed
+ */
+ public static function getParentByTypeStatus($type, int $year = null): mixed
+ {
+ if ($year) {
+ $currYear = $year;
+ } else {
+ $currYear = date('Y');
+ }
+
+ return MasterMenu::where('parent_id', '=', 0)
+ ->where('menu_type', '=', $type)
+ ->where('status', '=', true)
+ ->union(MasterMenu::coreMenus($type))
+ ->orderBy('ordering')
+ ->get();
+ }
+
+ /**
+ * @author alex.gz
+ * @created 08/12/2023 12:54
+ *
+ * @param $id
+ * @param array $active
+ * @param int|null $year
+ *
+ * @return mixed
+ */
+ public static function getMenuByParent($id, array $active = [1], int $year = null): mixed
+ {
+ if ($year) {
+ $currYear = $year;
+ } else {
+ $currYear = date('Y');
+ }
+
+ return MasterMenu::where('parent_id', '=', $id)
+ ->union(MasterMenu::coreMenusByParent($id, $active))
+ ->whereIn('status', $active)
+ ->orderBy('ordering')
+ ->get();
+ }
+
+ /**
+ * @author alex.gz
+ * @created 08/12/2023 14:54
+ *
+ * @param int $year
+ *
+ * @return mixed
+ */
+ public static function countMenuByYear(int $year): mixed
+ {
+ $model = MasterMenu::where('status', '=', true);
+ return $model->count();
+ }
+
+ /**
+ * @author alex.gz
+ * @created 08/12/2023 12:55
+ *
+ * @param $id
+ * @param int|null $year
+ *
+ * @return mixed
+ */
+ public static function getActiveById($id, int $year = null): mixed
+ {
+ if ($year) {
+ $currYear = $year;
+ } else {
+ $currYear = date('Y');
+ }
+
+ return MasterMenu::where('id', '=', $id)
+ ->where('status', '=', true)
+ ->first();
+ }
+
+ /**
+ * @author alex.gz
+ * @created 08/12/2023 12:55
+ *
+ * @param $type
+ * @param int|null $year
+ *
+ * @return mixed
+ */
+ public static function getActiveByPosition($type, int $year = null): mixed
+ {
+ if ($year) {
+ $currYear = $year;
+ } else {
+ $currYear = date('Y');
+ }
+
+ return MasterMenu::where('menu_type', '=', $type)
+ ->where('status', '=', true)
+ ->union(MasterMenu::coreMenus($type))
+ ->orderBy('ordering')
+ ->get();
+ }
}
diff --git a/app/Models/User.php b/app/Models/User.php
index c7ef882..e3ef034 100644
--- a/app/Models/User.php
+++ b/app/Models/User.php
@@ -21,6 +21,7 @@ class User extends Authenticatable
// protected $primaryKey = 'user_id';
protected $fillable = [
'name',
+ 'username',
'email',
'password',
];
@@ -43,4 +44,9 @@ class User extends Authenticatable
protected $casts = [
'email_verified_at' => 'datetime',
];
+
+ public function sekolah()
+ {
+ return $this->belongsTo(ProfileSekolah::class,'id','user_id');
+ }
}
diff --git a/composer.json b/composer.json
index 7cf2ae9..7c1814f 100644
--- a/composer.json
+++ b/composer.json
@@ -31,7 +31,10 @@
"autoload-dev": {
"psr-4": {
"Tests\\": "tests/"
- }
+ },
+ "files": [
+ "app/Helpers/custom.php"
+ ]
},
"scripts": {
"post-autoload-dump": [
diff --git a/database/migrations/2014_10_12_000000_create_users_table.php b/database/migrations/2014_10_12_000000_create_users_table.php
index 444fafb..e83809b 100644
--- a/database/migrations/2014_10_12_000000_create_users_table.php
+++ b/database/migrations/2014_10_12_000000_create_users_table.php
@@ -14,6 +14,7 @@ return new class extends Migration
Schema::create('users', function (Blueprint $table) {
$table->id();
$table->string('name');
+ $table->string('username');
$table->string('email')->unique();
$table->timestamp('email_verified_at')->nullable();
$table->string('password');
diff --git a/database/migrations/2025_02_11_140501_create_master_groups_table.php b/database/migrations/2025_02_11_140501_create_master_groups_table.php
index 61d9f71..b959a50 100644
--- a/database/migrations/2025_02_11_140501_create_master_groups_table.php
+++ b/database/migrations/2025_02_11_140501_create_master_groups_table.php
@@ -13,8 +13,8 @@ return new class extends Migration
{
Schema::create('ms_group', function (Blueprint $table) {
$table->id('MsGroupId');
- $table->string('menu_group', 50)->unique();
- $table->string('menu_group_alias', 50)->unique();
+ $table->string('name', 50)->unique();
+ $table->string('alias', 50)->unique();
$table->boolean('status')->default(true)->comment('True/False');
$table->foreignId('created_by')->default(0);
$table->foreignId('updated_by')->default(0)->nullable();
diff --git a/database/migrations/2025_02_11_140609_create_master_group_users_table.php b/database/migrations/2025_02_11_140609_create_master_group_users_table.php
index aa8708b..129d2bb 100644
--- a/database/migrations/2025_02_11_140609_create_master_group_users_table.php
+++ b/database/migrations/2025_02_11_140609_create_master_group_users_table.php
@@ -15,6 +15,7 @@ return new class extends Migration
$table->id('MsGroupUserId');
$table->foreignId('ms_group_id')->comment('FK Group');
$table->foreignId('user_id')->comment('FK User');
+ $table->timestamps();
$table->foreign('user_id')->references('id')->on('users')->cascadeOnDelete();
$table->foreign('ms_group_id')->references('MsGroupId')->on('ms_group')->cascadeOnDelete();
diff --git a/database/migrations/2025_02_19_150642_add_column_group_id.php b/database/migrations/2025_02_19_150642_add_column_group_id.php
new file mode 100644
index 0000000..6da9085
--- /dev/null
+++ b/database/migrations/2025_02_19_150642_add_column_group_id.php
@@ -0,0 +1,29 @@
+foreignId('ms_group_id')->comment('FK ms group');
+ $table->foreign('ms_group_id')->references('MsGroupId')->on('ms_group')->cascadeOnDelete();
+ });
+ }
+
+ /**
+ * Reverse the migrations.
+ */
+ public function down(): void
+ {
+ Schema::table('users', function (Blueprint $table) {
+ //
+ });
+ }
+};
diff --git a/database/seeders/DatabaseSeeder.php b/database/seeders/DatabaseSeeder.php
index 70d2cf2..89e02c3 100644
--- a/database/seeders/DatabaseSeeder.php
+++ b/database/seeders/DatabaseSeeder.php
@@ -6,6 +6,8 @@ namespace Database\Seeders;
use Illuminate\Database\Seeder;
use App\Models\User;
use App\Models\Master\MasterTingkatSekolah;
+use App\Models\Master\MasterGroup;
+use App\Models\Master\MasterGroupUser;
use Hash;
class DatabaseSeeder extends Seeder
@@ -15,15 +17,6 @@ class DatabaseSeeder extends Seeder
*/
public function run(): void
{
- User::updateOrCreate([
- 'name' => 'Administrator',
- 'email' => 'adminadiwiyata@dlh.go.id',
- ],[
- 'name' => 'Administrator',
- 'email' => 'adminadiwiyata@dlh.go.id',
- 'password' => Hash::make('##SekolahAdiwiyata123'),
- ]);
-
$data = [
['name' => 'SD'],
['name' => 'SMP'],
@@ -45,5 +38,49 @@ class DatabaseSeeder extends Seeder
'name' => $val['name'],
]);
}
+
+
+ $group = [
+ ['name' => 'Administrator','alias' => 'administrator'],
+ ['name' => 'Sekolah','alias'=> 'sekolah'],
+ ['name' => 'Satuan Pelaksana','alias' => 'satuan_pelaksana'],
+ ['name' => 'Suku Dinas', 'alias' => 'suku_dinas'],
+ ['name' => 'Dinas','alias' => 'dinas'],
+ ['name' => 'Penilai Kota','alias' => 'penilai_kota'],
+ ['name' => 'Penilai Provinsi','alias' => 'penilai_provinsi'],
+ ];
+
+ foreach($group as $valGroup){
+ MasterGroup::updateOrCreate([
+ 'name' => $valGroup['name'],
+ 'alias' => $valGroup['alias'],
+ ],[
+ 'name' => $valGroup['name'],
+ 'alias' => $valGroup['alias'],
+ 'status' => 1,
+ ]);
+ }
+
+ User::updateOrCreate([
+ 'name' => 'Administrator',
+ 'username' => 'administrator',
+ 'email' => 'adminadiwiyata@dlh.go.id',
+ ],[
+ 'name' => 'Administrator',
+ 'username' => 'administrator',
+ 'email' => 'adminadiwiyata@dlh.go.id',
+ 'password' => Hash::make('##SekolahAdiwiyata123'),
+ ]);
+
+ MasterGroupUser::updateOrCreate([
+ 'ms_group_id' => '1',
+ 'user_id' => '1',
+ ],[
+ 'ms_group_id' => '1',
+ 'user_id' => '1',
+ ]);
+
+
+
}
}
diff --git a/resources/views/auth/login.blade.php b/resources/views/auth/login.blade.php
index 62467fb..8635cc2 100644
--- a/resources/views/auth/login.blade.php
+++ b/resources/views/auth/login.blade.php
@@ -47,7 +47,7 @@
{{csrf_field()}}
-
+