diff --git a/app/Http/Controllers/AuthenticationController.php b/app/Http/Controllers/AuthenticationController.php new file mode 100644 index 0000000..6c04fc0 --- /dev/null +++ b/app/Http/Controllers/AuthenticationController.php @@ -0,0 +1,82 @@ +name_en = $request->name; + $user->contact_en = $request->contact; + $user->email = $request->email; + $user->password = Hash::make($request->password); + $user->role_id = 4; + if ($user->save()) + return redirect('login')->with('success', 'Successfully Registered'); + else + return redirect('login')->with('danger', 'Please Try Again'); + } catch (Exception $e) { + dd($e); + return redirect('login')->with('danger', 'Please Try Again'); + } + } + + public function signInForm() + { + return view('authentication.login'); + } + + public function signInCheck(SignInRequest $request) + { + try { + $user = User::where('contact_en', $request->username)->orWhere('email', $request->username)->first(); + if ($user) { + if (Hash::check($request->password, $request->username)) { + $this->setSession($user); + return redirect()->route('dashboard')->with('success', 'Successfully Logged In'); + } else + return redirect()->route('login')->with('error', 'Username or Password is wrong!'); + } else + return redirect()->route('login')->with('error', 'Username or Password is wrong!'); + } catch (Exception $e) { + dd($e); + return redirect()->route('login')->with('error', 'Username or Password is wrong!'); + } + } + + public function setSession($user) + { + return request()->session()->put( + [ + 'userId' => encryptor('encrypt', $user->id), + 'userName' => encryptor('encrypt', $user->name), + 'userId' => encryptor('encrypt', $user->id), + 'role' => encryptor('encrypt', $user->role->type), + 'roleIdentitiy' => encryptor('encrypt', $user->role->identity), + 'language' => encryptor('encrypt', $user->language), + 'image' => $user->image ?? 'No Image Found' + ] + ); + } + + public function signOut() + { + request()->session()->flush(); + return redirect('login')->with('error', currentUserId()); + } +} diff --git a/app/Http/Helpers/index.php b/app/Http/Helpers/index.php new file mode 100644 index 0000000..d11ecc6 --- /dev/null +++ b/app/Http/Helpers/index.php @@ -0,0 +1,39 @@ +session()->get('userId')); +} + +function currentUser() +{ + return encryptor('decrypt', request()->session()->get('roleIdentity')); +} diff --git a/app/Http/Middleware/isSuperadmin.php b/app/Http/Middleware/isSuperadmin.php new file mode 100644 index 0000000..77aa465 --- /dev/null +++ b/app/Http/Middleware/isSuperadmin.php @@ -0,0 +1,35 @@ +route('logOut'); + } else { + $user = User::findOrFail(currentUserId()); + app()->setLocale($user->language); //language + if (!$user) { + return redirect()->route('logOut'); + } else if (currentUser() != 'superadmin') { + return redirect()->back()->with('danger', 'Access Denied'); + } else { + return $next($request); + } + } + return redirect()->route('logOut'); + } +} diff --git a/app/Http/Requests/Authentication/SignInRequest.php b/app/Http/Requests/Authentication/SignInRequest.php new file mode 100644 index 0000000..d340519 --- /dev/null +++ b/app/Http/Requests/Authentication/SignInRequest.php @@ -0,0 +1,29 @@ +|string> + */ + public function rules(): array + { + return [ + 'username' => 'required', + 'password' => 'required' + ]; + } +} diff --git a/app/Http/Requests/Authentication/SignUpRequest.php b/app/Http/Requests/Authentication/SignUpRequest.php new file mode 100644 index 0000000..3dfaec8 --- /dev/null +++ b/app/Http/Requests/Authentication/SignUpRequest.php @@ -0,0 +1,31 @@ +|string> + */ + public function rules(): array + { + return [ + 'name'=>'required|max:255', + 'contact_en'=>'required|unique:users', + 'email'=> 'required|unique:users', + 'password'=>'required|confirmed', + ]; + } +} diff --git a/app/Models/Role.php b/app/Models/Role.php new file mode 100644 index 0000000..42bb4d2 --- /dev/null +++ b/app/Models/Role.php @@ -0,0 +1,11 @@ + - */ - protected $fillable = [ - 'name', - 'email', - 'password', - ]; - - /** - * The attributes that should be hidden for serialization. - * - * @var array - */ - protected $hidden = [ - 'password', - 'remember_token', - ]; - - /** - * The attributes that should be cast. - * - * @var array - */ - protected $casts = [ - 'email_verified_at' => 'datetime', - 'password' => 'hashed', - ]; + use HasFactory; } diff --git a/composer.json b/composer.json index 1a4c9c1..e886706 100644 --- a/composer.json +++ b/composer.json @@ -26,7 +26,9 @@ "App\\": "app/", "Database\\Factories\\": "database/factories/", "Database\\Seeders\\": "database/seeders/" - } + }, "files":[ + "app/Http/Helpers/index.php" + ] }, "autoload-dev": { "psr-4": { diff --git a/database/migrations/2023_11_12_031402_create_users_table.php b/database/migrations/2023_11_12_031402_create_users_table.php new file mode 100644 index 0000000..be6c844 --- /dev/null +++ b/database/migrations/2023_11_12_031402_create_users_table.php @@ -0,0 +1,40 @@ +id(); + $table->string('name_en'); + $table->string('name_bn')->nullable(); + $table->string('email')->unique(); + $table->string('contact_en')->unique(); + $table->string('contact_bn')->unique()->nullable(); + $table->unsignedBigInteger('role_id')->index(); + $table->foreign('role_id')->references('id')->on('roles')->onDelete('cascade'); + $table->string('password'); + $table->string('language')->default('en'); + $table->string('image')->nullable(); + $table->boolean('status')->default(1)->comment('1=>active 2=>inactive'); + $table->rememberToken(); + $table->timestamps(); + $table->softDeletes(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('users'); + } +}; diff --git a/database/migrations/2023_11_12_031415_create_roles_table.php b/database/migrations/2023_11_12_031415_create_roles_table.php new file mode 100644 index 0000000..a72f7a1 --- /dev/null +++ b/database/migrations/2023_11_12_031415_create_roles_table.php @@ -0,0 +1,54 @@ +id(); + $table->string('type', 20)->unique(); + $table->string('identity', 30)->unique(); + $table->timestamps(); + }); + + DB::table('roles')->insert([ + [ + 'type'=> 'Super Admin', + 'identity'=> 'superadmin', + 'created_at'=> Carbon::now() + ], + [ + 'type'=> 'Admin', + 'identity'=> 'admin', + 'created_at'=> Carbon::now() + ], + [ + 'type'=> 'Instructor', + 'identity'=> 'instructor', + 'created_at'=> Carbon::now() + ], + [ + 'type'=> 'Student', + 'identity'=> 'student', + 'created_at'=> Carbon::now() + ] + ]); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('roles'); + } +}; diff --git a/resources/views/Authentication/login.blade.php b/resources/views/Authentication/login.blade.php new file mode 100644 index 0000000..9927431 --- /dev/null +++ b/resources/views/Authentication/login.blade.php @@ -0,0 +1,66 @@ +@extends('layouts.appAuth') + +@section('content') + + +
+
+
+
+
+
+
+
+

Sign in your account

+
+ @csrf +
+ + + @if($errors->has('username')) + {{$errors->first('username')}} + @endif +
+
+ + + @if($errors->has('password')) + {{$errors->first('password')}} + @endif +
+
+
+
+ + +
+
+ +
+
+ +
+
+ +
+
+
+
+
+
+
+
+ + + +@endsection \ No newline at end of file diff --git a/resources/views/Authentication/register.blade.php b/resources/views/Authentication/register.blade.php new file mode 100644 index 0000000..db45ea6 --- /dev/null +++ b/resources/views/Authentication/register.blade.php @@ -0,0 +1,67 @@ +@extends('layouts.appAuth') + +@section('content') + + +
+
+
+
+
+
+
+
+

Sign up your account

+
+ @csrf +
+ + + @if($errors->has('name')) + {{$errors->first('name')}} + @endif +
+
+ + + @if($errors->has('email')) + {{$errors->first('email')}} + @endif +
+
+ + + @if($errors->has('contact_en')) + {{$errors->first('contact_en')}} + @endif +
+
+ + + @if($errors->has('password')) + {{$errors->first('password')}} + @endif +
+
+ + +
+
+ +
+
+ +
+
+
+
+
+
+
+
+ + +@endsection \ No newline at end of file diff --git a/resources/views/layouts/app.blade.php b/resources/views/layouts/app.blade.php index b12a18d..04c3c38 100644 --- a/resources/views/layouts/app.blade.php +++ b/resources/views/layouts/app.blade.php @@ -17,7 +17,7 @@ - + + + + + + + + + + + + + +
+ + + @yield('content') + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + +{{-- TOASTER --}} + + + + + + + \ No newline at end of file diff --git a/resources/views/welcome.blade.php b/resources/views/welcome.blade.php index 8aae856..a6e1c74 100644 --- a/resources/views/welcome.blade.php +++ b/resources/views/welcome.blade.php @@ -2,528 +2,537 @@ @section('content') - -
- -
- -
-
-
-
-

Total Students

-
422
-
-
-
-
+ + +
+ +
+ +
+
+
+
+

Total Students

+
422
+
+
+
+
+
-
-
-
-
-

New Students

-
357
-
-
-
-
+
+
+
+

New Students

+
357
+
+
+
+
+
-
-
-
-
-

Total Course

-
547
-
-
-
6,2,8,4,-3,8,1,-3,6,-5,9,2,-8,1,4,8,9,8,2,1 +
+
+
+

Total Course

+
547
+
+
+
6,2,8,4,-3,8,1,-3,6,-5,9,2,-8,1,4,8,9,8,2,1 +
-
-
-
-
-

Fees Collection

-
3280$
-
-
- 7,6,8,7,3,8,3,3,6,5,9,2,8 -
-
-
-
-
-
-

Income/Expense Report

-
-
- -
-
-
-
-
-
-

Income/Expense Report

-
-
- -
-
-
-
-
-
-
Assign Task
-
-
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
#TaskAssigned ProfessorsStatusProgress
1Working Design reportHerman BeckDONE -
-
- 70% Complete -
-
-
2Fees Collection reportEmma WatsonPanding -
-
- 70% Complete -
-
-
3Management reportMary AdamsPanding -
-
- 70% Complete -
-
-
4Library book statusCaleb RichardsSuspended -
-
- 70% Complete -
-
-
5Placement statusJune LanePanding -
-
- 70% Complete -
-
-
6Working Design reportHerman BeckDONE -
-
- 70% Complete -
-
-
+
+
+
+

Fees Collection

+
3280$
+
+
+ 7,6,8,7,3,8,3,3,6,5,9,2,8
-
-
-
-
-

Notifications

-
-
- -
-
-
-

New Student List

+
+
+
+

Income/Expense Report

+
+
+ +
-
-
- - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameAssigned ProfessorBranchStatusDate Of AdmitEdit
- -
-
- -
-
-
Ricky Antony
+
+
+
+
+
Assign Task
+
+
+
+ + + + + + + + + + + + + + + + + - - - - - - - - + + + + + + + - - - - - - - - + + + + + + + - - - - - - - - + + + + + + + - - - - - - - - + + + + + + + - - - - - - - - + + + + + + + - - - - - - - - + + +
#TaskAssigned ProfessorsStatusProgress
1Working Design reportHerman BeckDONE +
+
+ 70% Complete
- -
Herman BeckMechanicalDONE30/03/2018 - - -
- -
-
- -
-
-
Emma Watson
+
2Fees Collection reportEmma WatsonPanding +
+
+ 70% Complete
- -
Emma WatsonComputerPanding11/07/2017 - - -
- -
-
- -
-
-
Rowen Atkinson
+
3Management reportMary AdamsPanding +
+
+ 70% Complete
- -
Mary AdamsMechanicalDONE05/04/2016 - - -
- -
-
- -
-
-
Antony Hopkins
+
4Library book statusCaleb RichardsSuspended +
+
+ 70% Complete
- -
Caleb Richards Computer Suspended05/04/2018 - - -
- -
-
- -
-
-
Jennifer Schramm
+
5Placement statusJune LanePanding +
+
+ 70% Complete
- -
June LaneFees CollectionPanding17/03/2016 - - -
- -
-
- -
-
-
Raymond Mims
+
6Working Design reportHerman BeckDONE +
+
+ 70% Complete
- -
Herman BeckComputerSuspended12/07/2014 - - -
- -
-
- +
+
+
+
+
+
+
+
+
+

New Student List

+
+
+
+ + + + + + + + + + + + + + + + + + + + + + - - - - - - - -
NameAssigned ProfessorBranchStatusDate Of AdmitEdit
+ +
+
+ +
+
+
Ricky Antony
+
-
Herman BeckMechanicalDONE30/03/2018 + + +
+ +
+
+ +
+
+
Emma Watson
+
- -
-
Jennifer SchrammMechanicalPanding15/06/2014 - - -
+ +
Emma WatsonComputerPanding11/07/2017 + + +
+ +
+
+ +
+
+
Rowen Atkinson
+
+
+
+
Mary AdamsMechanicalDONE05/04/2016 + + +
+ +
+
+ +
+
+
Antony Hopkins
+
+
+
+
Caleb Richards Computer Suspended05/04/2018 + + +
+ +
+
+ +
+
+
Jennifer Schramm
+
+
+
+
June LaneFees CollectionPanding17/03/2016 + + +
+ +
+
+ +
+
+
Raymond Mims
+
+
+
+
Herman BeckComputerSuspended12/07/2014 + + +
+ +
+
+ +
+
+
Michael Jenkins
+
+
+
+
Jennifer SchrammMechanicalPanding15/06/2014 + + +
+
-
- + + @endsection diff --git a/routes/web.php b/routes/web.php index d259f33..88b5b17 100644 --- a/routes/web.php +++ b/routes/web.php @@ -1,6 +1,7 @@ name('register'); +Route::post('/register', [auth::class, 'signUpStore'])->name('register.store'); +Route::get('/login', [auth::class, 'signInForm'])->name('login'); +Route::post('/login', [auth::class, 'signInCheck'])->name('login.check'); +Route::get('/logout', [auth::class, 'signOut'])->name('logOut'); + + Route::get('/', function () { return view('welcome'); }); +Route::get('/dashboard', function () { + return view('welcome'); +})->name('dashboard');