NASER add admin levels & fix break button

This commit is contained in:
mobin
2026-04-08 09:22:17 +00:00
parent a6b5f27343
commit fcc50d8ec8
8 changed files with 8543 additions and 8374 deletions
+26 -10
View File
@@ -34,7 +34,12 @@ class AdminController extends Controller
$u = User::select('name', 'is_admin') $u = User::select('name', 'is_admin')
->where('user_name', $uname) ->where('user_name', $uname)
->first(); ->first();
if ($u->is_admin == '1') { if ($u->is_admin == 1){
$provider = 'admin';
}elseif ($u->is_admin == 2){
$provider = 'supervisor';
}
if ($u->is_admin == '1' || $u->is_admin == '2') {
setcookie('ad', '1', time() + (60 * 60 * 24 * 365 * 5), "/"); setcookie('ad', '1', time() + (60 * 60 * 24 * 365 * 5), "/");
$users = User::wherenotnull('user_name') $users = User::wherenotnull('user_name')
->with('attendances') ->with('attendances')
@@ -83,7 +88,8 @@ class AdminController extends Controller
"text" => 'شما به پنل ادمین وارد شدید✔️' "text" => 'شما به پنل ادمین وارد شدید✔️'
], ],
"users" => $users, "users" => $users,
'reqs' => $records 'reqs' => $records,
"userType" => $provider
]); ]);
} }
@@ -136,6 +142,11 @@ class AdminController extends Controller
$nstartt = $request->starttime; $nstartt = $request->starttime;
$nendt = $request->endtime; $nendt = $request->endtime;
// dd($request); // dd($request);
$user = User::where('user_name', $_COOKIE['user_identity'])->first();
if ($user->is_admin == 2){
$attController = new AttendanceController();
return $attController->edit($request);
}
if ($id == 'new') { if ($id == 'new') {
$user_name = $request->uname; $user_name = $request->uname;
if($request->display_date == null){ if($request->display_date == null){
@@ -276,15 +287,17 @@ class AdminController extends Controller
} }
$record->requested = ''; $record->requested = '';
$record->save(); $record->save();
$create_requests_key = "att-tempreq:creates:{$data->userid}"; // $create_requests_key = "att-tempreq:creates:{$data->userid}";
Redis::connection()->lrem($create_requests_key, 1, json_encode($data)); // $create_requests_key = "att-tempreq:{$data->userid}:{$data->id}";
// $t = Redis::connection()->lrem($create_requests_key, -1, json_encode($data));
// Redis::connection()->del("att-tempreq:{$data->userid}:{$data->id}"); Redis::connection()->del("att-tempreq:{$data->userid}:{$data->id}");
tel_notif($record->user_identity, "تایید"); tel_notif($record->user_identity, "تایید");
return redirect()->back()->with('message', [ return json_encode($data);
'color' => '#6aff00ff', // return redirect()->back()->with('message', [
"text" => 'رکورد با موفقیت ذخیره شد.✔️' // 'color' => '#6aff00ff',
]); // "text" => 'رکورد با موفقیت ذخیره شد.✔️'
// ]);
} elseif ($data->function == 'new') { } elseif ($data->function == 'new') {
// dd($data); // dd($data);
$starttime = $data->oldenter ? Carbon::parse($data->oldenter)->format('H:i:s') : null; $starttime = $data->oldenter ? Carbon::parse($data->oldenter)->format('H:i:s') : null;
@@ -311,10 +324,13 @@ class AdminController extends Controller
} }
if ($request->update == 'reject') { if ($request->update == 'reject') {
if($data->function == 'delete' || $data->function == 'edit'){
Redis::connection()->del("att-tempreq:{$data->userid}:{$data->id}");
}elseif($data->function == 'new'){
$create_requests_key = "att-tempreq:creates:{$data->userid}"; $create_requests_key = "att-tempreq:creates:{$data->userid}";
Redis::connection()->lrem($create_requests_key, 1, json_encode($data)); Redis::connection()->lrem($create_requests_key, 1, json_encode($data));
}
// Redis::connection()->del("att-tempreq:{$data->userid}:{$data->id}");
// dd($data->id); // dd($data->id);
if ($data->id !== "new") { if ($data->id !== "new") {
$att = Attendance::find($data->id); $att = Attendance::find($data->id);
@@ -127,6 +127,48 @@ class AttendanceController extends Controller
// return redirect(route('admin.dashboard')); // return redirect(route('admin.dashboard'));
// } // }
// public function login1(Request $request)
// {
//
// $credentials = $request->only(['phone', 'password']);
// $user = User::where('number', $credentials['phone'])->first();
// if($user->is_admin == 0){
// $provider = 'employee';
// }elseif ($user->is_admin == 1){
// $provider = 'admin';
// }elseif ($user->is_admin == 2){
// $provider = 'supervisor';
// }
// return $this->_loginWithPassword($credentials, $provider);
// }
//
// protected function _loginWithPassword($credentials, $provider)
// {
//
//
// $token = auth($provider)->attempt($credentials);
// if (!$token) {
// throw new UnprocessableEntityHttpException('شماره موبایل یا پسوورد وارد شده اشتباه است');
// }
// $user = auth($provider)->user();
//
//
// return $this->respondWithToken($token);
// }
//
// protected function respondWithToken($token)
// {
// return response()->json([
// 'access_token' => $token,
// 'token_type' => 'bearer',
// 'expires_in' => auth()->factory()->getTTL()
// ]);
// }
public function ai() public function ai()
{ {
$response = Http::withHeaders([ $response = Http::withHeaders([
+3 -1
View File
@@ -10,7 +10,9 @@
"laravel/framework": "^12.0", "laravel/framework": "^12.0",
"laravel/tinker": "^2.10.1", "laravel/tinker": "^2.10.1",
"morilog/jalali": "^3.4", "morilog/jalali": "^3.4",
"predis/predis": "^3.2" "predis/predis": "^3.2",
"tymon/jwt-auth": "^1.0"
}, },
"require-dev": { "require-dev": {
"fakerphp/faker": "^1.23", "fakerphp/faker": "^1.23",
Generated
+85
View File
@@ -5840,6 +5840,91 @@
], ],
"time": "2025-04-30T23:37:27+00:00" "time": "2025-04-30T23:37:27+00:00"
}, },
{
"name": "tymon/jwt-auth",
"version": "dev-develop",
"source": {
"type": "git",
"url": "https://github.com/tymondesigns/jwt-auth.git",
"reference": "014be8d493d228d14bbc291b24e835d330c092a0"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/tymondesigns/jwt-auth/zipball/014be8d493d228d14bbc291b24e835d330c092a0",
"reference": "014be8d493d228d14bbc291b24e835d330c092a0",
"shasum": ""
},
"require": {
"illuminate/auth": "^5.2|^6|^7|^8|^9",
"illuminate/contracts": "^5.2|^6|^7|^8|^9",
"illuminate/http": "^5.2|^6|^7|^8|^9",
"illuminate/support": "^5.2|^6|^7|^8|^9",
"lcobucci/jwt": "^3.4|^4.0",
"namshi/jose": "^7.0",
"nesbot/carbon": "^1.0|^2.0",
"php": "^7.4|^8.0"
},
"require-dev": {
"illuminate/console": "^5.2|^6|^7|^8|^9",
"illuminate/database": "^5.2|^6|^7|^8|^9",
"illuminate/routing": "^5.2|^6|^7|^8|^9",
"mockery/mockery": ">=0.9.9",
"phpunit/phpunit": "^8.5|^9.4",
"yoast/phpunit-polyfills": "^0.2.0"
},
"type": "library",
"extra": {
"laravel": {
"aliases": {
"JWTAuth": "Tymon\\JWTAuth\\Facades\\JWTAuth",
"JWTFactory": "Tymon\\JWTAuth\\Facades\\JWTFactory"
},
"providers": [
"Tymon\\JWTAuth\\Providers\\LaravelServiceProvider"
]
},
"branch-alias": {
"dev-develop": "1.0-dev"
}
},
"autoload": {
"psr-4": {
"Tymon\\JWTAuth\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Sean Tymon",
"email": "tymon148@gmail.com",
"homepage": "https://tymon.xyz",
"role": "Developer"
}
],
"description": "JSON Web Token Authentication for Laravel and Lumen",
"homepage": "https://github.com/tymondesigns/jwt-auth",
"keywords": [
"Authentication",
"JSON Web Token",
"auth",
"jwt",
"laravel"
],
"support": {
"issues": "https://github.com/tymondesigns/jwt-auth/issues",
"source": "https://github.com/tymondesigns/jwt-auth"
},
"funding": [
{
"url": "https://www.patreon.com/seantymon",
"type": "patreon"
}
],
"time": "2022-04-27T08:53:50+00:00"
},
{ {
"name": "voku/portable-ascii", "name": "voku/portable-ascii",
"version": "2.0.3", "version": "2.0.3",
+17 -2
View File
@@ -14,8 +14,8 @@ return [
*/ */
'defaults' => [ 'defaults' => [
'guard' => env('AUTH_GUARD', 'web'), 'guard' => 'user',
'passwords' => env('AUTH_PASSWORD_BROKER', 'users'), 'passwords' => 'users',
], ],
/* /*
@@ -40,6 +40,21 @@ return [
'driver' => 'session', 'driver' => 'session',
'provider' => 'users', 'provider' => 'users',
], ],
'admin' => [
'driver' => 'jwt',
'provider' => 'admins',
// 'hash' => true,
],
'supervisor' => [
'driver' => 'jwt',
'provider' => 'supervisors',
// 'hash' => true,
],
'employee' => [
'driver' => 'jwt',
'provider' => 'employees',
// 'hash' => true,
],
], ],
/* /*
+8 -1
View File
@@ -42,7 +42,7 @@ foreach ($users as $u) {
else else
$us = false; $us = false;
$u->working = $us ? 1 : 0; $u->working = $us ? 1 : 0;
}else } else
$u->working = 0; $u->working = 0;
foreach ($u->attendances as $u_att) { foreach ($u->attendances as $u_att) {
@@ -93,7 +93,9 @@ $usersChunked = $users->chunk(3);
<th class="px-2 py-2 border w-1/6">تاریخ</th> <th class="px-2 py-2 border w-1/6">تاریخ</th>
<th class="px-2 py-2 border w-1/6">ورود</th> <th class="px-2 py-2 border w-1/6">ورود</th>
<th class="px-2 py-2 border w-1/6">خروج</th> <th class="px-2 py-2 border w-1/6">خروج</th>
@if($userType == 'admin')
<th class="px-2 py-2 border w-1/6">تعیین وضعیت</th> <th class="px-2 py-2 border w-1/6">تعیین وضعیت</th>
@endif
</tr> </tr>
</thead> </thead>
@@ -129,6 +131,7 @@ $usersChunked = $users->chunk(3);
<td class="px-4 py-2 border">{{ $oldExit || $newExit ? ($rec->id=='new' || $oldExit==($newExit ?? '') ? $oldExit : $oldExit.'👇🏻'.$newExit) : '-' }}</td> <td class="px-4 py-2 border">{{ $oldExit || $newExit ? ($rec->id=='new' || $oldExit==($newExit ?? '') ? $oldExit : $oldExit.'👇🏻'.$newExit) : '-' }}</td>
@endif @endif
@if($userType == 'admin')
<td class="px-4 py-2 border"> <td class="px-4 py-2 border">
<form method="post" action="{{route('admin.update')}}"> <form method="post" action="{{route('admin.update')}}">
@csrf @csrf
@@ -151,6 +154,7 @@ $usersChunked = $users->chunk(3);
</button> </button>
</form> </form>
</td> </td>
@endif
</tr> </tr>
@empty @empty
<tr> <tr>
@@ -196,6 +200,8 @@ $usersChunked = $users->chunk(3);
</p> </p>
</a> </a>
@if($userType == 'admin')
<button type="button" <button type="button"
class="rounded-lg bg-cyan-500 hover:bg-cyan-600" class="rounded-lg bg-cyan-500 hover:bg-cyan-600"
onclick="window.location.href='{{ url('attendance/profile').'?username='.$u->user_name }}'" onclick="window.location.href='{{ url('attendance/profile').'?username='.$u->user_name }}'"
@@ -203,6 +209,7 @@ $usersChunked = $users->chunk(3);
display: inline-block; font-size: 16px; margin: 4px 2px; cursor: pointer; "> display: inline-block; font-size: 16px; margin: 4px 2px; cursor: pointer; ">
ویرایش ویرایش
</button> </button>
@endif
</div> </div>
@endforeach @endforeach
+36 -36
View File
@@ -8,35 +8,35 @@ use Carbon\Carbon;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
if (!empty($user->tasks)) { //if (!empty($user->tasks)) {
$in_progress = '#fca000'; // $in_progress = '#fca000';
$todo = '#7d7d7d'; // $todo = '#7d7d7d';
$error = '#fc0000'; // $error = '#fc0000';
$backlog = '#bababa'; // $backlog = '#bababa';
$done = '#40de02'; // $done = '#40de02';
$cancelled = 'black'; // $cancelled = 'black';
//
$state = [ // $state = [
"c73c2044-ea14-42cb-b08d-cecf3d1fdfb5" => "$in_progress",// in progress // "c73c2044-ea14-42cb-b08d-cecf3d1fdfb5" => "$in_progress",// in progress
"a9ce312f-cfca-491e-8e3d-1975aa6ebc10" => "$todo",//to do // "a9ce312f-cfca-491e-8e3d-1975aa6ebc10" => "$todo",//to do
"dea1fb57-a281-4fe7-8f3e-ee5567637e35" => "$error",// error // "dea1fb57-a281-4fe7-8f3e-ee5567637e35" => "$error",// error
"770fbe42-99f6-41db-9b9e-773d9cced1a5" => "$backlog",//backlog // "770fbe42-99f6-41db-9b9e-773d9cced1a5" => "$backlog",//backlog
"b0e464e1-34eb-41ea-b2f7-3ef7483bc9f0" => "$done",//done // "b0e464e1-34eb-41ea-b2f7-3ef7483bc9f0" => "$done",//done
"d61d14a3-72f7-4f44-894b-efe8b2a75be1" => "$cancelled",//canceled // "d61d14a3-72f7-4f44-894b-efe8b2a75be1" => "$cancelled",//canceled
]; // ];
$state_order = [ // $state_order = [
"c73c2044-ea14-42cb-b08d-cecf3d1fdfb5", // "c73c2044-ea14-42cb-b08d-cecf3d1fdfb5",
"a9ce312f-cfca-491e-8e3d-1975aa6ebc10", // "a9ce312f-cfca-491e-8e3d-1975aa6ebc10",
"dea1fb57-a281-4fe7-8f3e-ee5567637e35", // "dea1fb57-a281-4fe7-8f3e-ee5567637e35",
"770fbe42-99f6-41db-9b9e-773d9cced1a5", // "770fbe42-99f6-41db-9b9e-773d9cced1a5",
"b0e464e1-34eb-41ea-b2f7-3ef7483bc9f0", // "b0e464e1-34eb-41ea-b2f7-3ef7483bc9f0",
"d61d14a3-72f7-4f44-894b-efe8b2a75be1", // "d61d14a3-72f7-4f44-894b-efe8b2a75be1",
]; // ];
//
$user->tasks = $user->tasks->sortBy(function ($task) use ($state_order) { // $user->tasks = $user->tasks->sortBy(function ($task) use ($state_order) {
return array_search($task->state, $state_order); // return array_search($task->state, $state_order);
}); // });
} //}
//dd(count($break = $user->attendanceBreaks)); //dd(count($break = $user->attendanceBreaks));
if (count($user->attendanceBreaks) > 0){ if (count($user->attendanceBreaks) > 0){
$break = $user->attendanceBreaks[0]; $break = $user->attendanceBreaks[0];
@@ -111,13 +111,13 @@ if (count($user->attendanceBreaks) > 0){
</button> </button>
{{--<p>{{Carbon::now()}}</p>--}} {{--<p>{{Carbon::now()}}</p>--}}
</form> </form>
@if(session('open_task_modal')) {{-- @if(session('open_task_modal'))--}}
<script> {{-- <script>--}}
window.onload = () => { {{-- window.onload = () => {--}}
openTaskModal(); {{-- openTaskModal();--}}
}; {{-- };--}}
</script> {{-- </script>--}}
@endif {{-- @endif--}}
@else @else
+2
View File
@@ -24,6 +24,8 @@ Route::get('/', function () {
return view('welcome'); return view('welcome');
}); });
Route::post('/login', [\App\Http\Controllers\AttendanceController::class, 'login1']);
Route::post('/task/create', [TaskController::class, 'addTask'])->name('createTask'); Route::post('/task/create', [TaskController::class, 'addTask'])->name('createTask');
Route::get('/ai', function () { Route::get('/ai', function () {