From 1b75fd15e003b4a31b4ec9e543089202adbed9d8 Mon Sep 17 00:00:00 2001 From: Anant Jain Date: Sun, 28 Oct 2018 11:47:15 +0530 Subject: [PATCH 1/2] Admin Panel --- app/Http/Controllers/AdminController.php | 65 ++++++++++++++++++ app/Http/Controllers/Auth/LoginController.php | 26 +++++++ app/User.php | 2 + .../2018_10_27_203655_create_user_table.php | 34 ++++++++++ database/seeds/DatabaseSeeder.php | 2 +- database/seeds/UsersTableSeeder.php | 20 ++++++ .../views/AdminPanel/dashboard.blade.php | 48 +++++++++++++ resources/views/AdminPanel/login.blade.php | 58 ++++++++++++++++ .../views/AdminPanel/print_data.blade.php | 37 ++++++++++ resources/views/AdminPanel/reset.blade.php | 67 +++++++++++++++++++ routes/web.php | 17 ++++- 11 files changed, 374 insertions(+), 2 deletions(-) create mode 100644 app/Http/Controllers/AdminController.php create mode 100644 database/migrations/2018_10_27_203655_create_user_table.php create mode 100644 database/seeds/UsersTableSeeder.php create mode 100644 resources/views/AdminPanel/dashboard.blade.php create mode 100644 resources/views/AdminPanel/login.blade.php create mode 100644 resources/views/AdminPanel/print_data.blade.php create mode 100644 resources/views/AdminPanel/reset.blade.php diff --git a/app/Http/Controllers/AdminController.php b/app/Http/Controllers/AdminController.php new file mode 100644 index 0000000..cf43348 --- /dev/null +++ b/app/Http/Controllers/AdminController.php @@ -0,0 +1,65 @@ +count(); + $yr_2 = Register::where('year', '2')->count(); + $yr_3 = Register::where('year', '3')->count(); + $yr_4 = Register::where('year', '4')->count(); + return view('AdminPanel.dashboard', ['yr_1' => $yr_1, 'yr_2' => $yr_2, 'yr_3' => $yr_3, 'yr_4' => $yr_4]); + } + + /** + * To generate printable attendence sheetd. + * + * @return Response + */ + public function print(Request $request) + { + $data = Register::select('name', 'admission_no', 'year')->orderBy('name')->get(); + return view('AdminPanel.print_data', ['data' => $data]); + } + + /** + * Reset login credentials. + * + * @param \Illuminate\Http\Request $request + * + * @return Response + */ + public function reset(Request $request) + { + $this -> validate($request,[ + 'username' => 'required|max:20', + 'password' => 'required|min:6|max:20', + 'password2' => 'required|min:6|max:20', + ]); + + if($request->input('password') != $request->input('password2')) + return back()->with(['msg' => 'Password do not match.', 'class' => 'alert-danger'])->withInput($request->all); + + $user = User::where('id', Auth::User()->id)->update([ + 'username' => $request->input('username'), + 'password' => bcrypt($request->input('password')), + 'new' => '0', + ]); + + Auth::logout(); + return redirect('admin')->with(['msg' => 'You had successfully updated your login credentials. Please login again with your new details', 'class' => 'alert-success']); + } +} diff --git a/app/Http/Controllers/Auth/LoginController.php b/app/Http/Controllers/Auth/LoginController.php index b2ea669..5029343 100644 --- a/app/Http/Controllers/Auth/LoginController.php +++ b/app/Http/Controllers/Auth/LoginController.php @@ -4,6 +4,8 @@ use App\Http\Controllers\Controller; use Illuminate\Foundation\Auth\AuthenticatesUsers; +use Illuminate\Http\Request; +use Illuminate\Support\Facades\Auth; class LoginController extends Controller { @@ -36,4 +38,28 @@ public function __construct() { $this->middleware('guest')->except('logout'); } + + /** + * Handle an authentication attempt. + * + * @param \Illuminate\Http\Request $request + * + * @return Response + */ + public function authenticate(Request $request) + { + $credentials = $request->only('username', 'password'); + + if (Auth::attempt($credentials)) { + if(Auth::user()->new == 1) { + return redirect('admin/reset')->with(['msg' => 'You had logined first time hence please reset your login credentials.', 'class' => 'alert-primary']); + } + else { + return redirect('admin/home'); + } + } + else { + return back()->with(['msg' => 'The username and/or password you specified are not correct.', 'class' => 'alert-danger']); + } + } } diff --git a/app/User.php b/app/User.php index bfd96a6..3da4922 100644 --- a/app/User.php +++ b/app/User.php @@ -8,6 +8,8 @@ class User extends Authenticatable { use Notifiable; + + public $timestamps = false; /** * The attributes that are mass assignable. diff --git a/database/migrations/2018_10_27_203655_create_user_table.php b/database/migrations/2018_10_27_203655_create_user_table.php new file mode 100644 index 0000000..a47b22a --- /dev/null +++ b/database/migrations/2018_10_27_203655_create_user_table.php @@ -0,0 +1,34 @@ +increments('id'); + $table->string('username'); + $table->string('password'); + $table->boolean('new'); + $table->rememberToken(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::drop('users'); + } +} diff --git a/database/seeds/DatabaseSeeder.php b/database/seeds/DatabaseSeeder.php index e119db6..2399bf1 100644 --- a/database/seeds/DatabaseSeeder.php +++ b/database/seeds/DatabaseSeeder.php @@ -11,6 +11,6 @@ class DatabaseSeeder extends Seeder */ public function run() { - // $this->call(UsersTableSeeder::class); + $this->call(UsersTableSeeder::class); } } diff --git a/database/seeds/UsersTableSeeder.php b/database/seeds/UsersTableSeeder.php new file mode 100644 index 0000000..580b9de --- /dev/null +++ b/database/seeds/UsersTableSeeder.php @@ -0,0 +1,20 @@ +insert([ + 'username' => 'admin', + 'password' => bcrypt('admin'), + 'new' => '1', + ]); + } +} diff --git a/resources/views/AdminPanel/dashboard.blade.php b/resources/views/AdminPanel/dashboard.blade.php new file mode 100644 index 0000000..1a24217 --- /dev/null +++ b/resources/views/AdminPanel/dashboard.blade.php @@ -0,0 +1,48 @@ + + + + Admin Panel + + + + + + + + + + + +
+ +
+ +
+
+ + \ No newline at end of file diff --git a/resources/views/AdminPanel/login.blade.php b/resources/views/AdminPanel/login.blade.php new file mode 100644 index 0000000..282286b --- /dev/null +++ b/resources/views/AdminPanel/login.blade.php @@ -0,0 +1,58 @@ + + + + Login + + + + + + + + + + + +
+
+
+
+
+
+
+

Login

+ @if (session('msg')) +
+ {{ session('msg') }} +
+ @endif +
+ {{ csrf_field() }} +
+ + + @if ($errors->has('username')) +

+ {{ $errors->first('username') }} +

+ @endif +
+
+ + + @if ($errors->has('password')) +

+ {{ $errors->first('password') }} +

+ @endif +
+ +
+
+
+
+
+
+
+ + \ No newline at end of file diff --git a/resources/views/AdminPanel/print_data.blade.php b/resources/views/AdminPanel/print_data.blade.php new file mode 100644 index 0000000..517dbd5 --- /dev/null +++ b/resources/views/AdminPanel/print_data.blade.php @@ -0,0 +1,37 @@ + + + + Registration Details + + + + + + + + + + + + + + + + + + + + + + @foreach($data as $d) + + + + + + + @endforeach + +
PresentNameYearAdm No
{{ $d->name }}{{ $d->year }}{{ $d->admission_no }}
+ + \ No newline at end of file diff --git a/resources/views/AdminPanel/reset.blade.php b/resources/views/AdminPanel/reset.blade.php new file mode 100644 index 0000000..81a50d0 --- /dev/null +++ b/resources/views/AdminPanel/reset.blade.php @@ -0,0 +1,67 @@ + + + + Reset + + + + + + + + + + + +
+
+
+
+
+
+
+

Reset Login Credentials

+ @if (session('msg')) +
+ {{ session('msg') }} +
+ @endif +
+ {{ csrf_field() }} +
+ + + @if ($errors->has('username')) +

+ {{ $errors->first('username') }} +

+ @endif +
+
+ + + @if ($errors->has('password')) +

+ {{ $errors->first('password') }} +

+ @endif +
+
+ + + @if ($errors->has('password2')) +

+ {{ $errors->first('password2') }} +

+ @endif +
+ +
+
+
+
+
+
+
+ + \ No newline at end of file diff --git a/routes/web.php b/routes/web.php index 66e3906..361b801 100644 --- a/routes/web.php +++ b/routes/web.php @@ -19,9 +19,24 @@ return view('workshop'); }); - Route::post('/register', 'RegisterController@register'); Route::post('/verify', 'RegisterController@verify'); + +Route::get('/admin', function () { + return view('AdminPanel.login'); +}); +Route::post('admin/login', 'Auth\LoginController@authenticate'); +Route::get('/admin/logout', 'Auth\LoginController@logout')->name('logout'); + +Route::group(['middleware' => ['auth']], function () { + Route::get('/admin/reset', function () { + return view('AdminPanel.reset'); + }); + Route::post('admin/reset', 'AdminController@reset'); + Route::get('/admin/home', 'AdminController@home'); + Route::get('/admin/print', 'AdminController@print'); +}); + Route::get('{any?}', function() { return Redirect::to('http://hackncs.com'); }); From 52dd30074b9d5c53fe1ce997055a9538e247e96c Mon Sep 17 00:00:00 2001 From: Anant Jain Date: Sun, 28 Oct 2018 11:51:47 +0530 Subject: [PATCH 2/2] Admin Panel Documentation --- README.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/README.md b/README.md index 3213c0a..970ba29 100644 --- a/README.md +++ b/README.md @@ -41,6 +41,13 @@ Migrate the database. ```php php artisan migrate ``` +``` + +Seed the database. + +```php +php artisan db:seed +``` Run this project on localhost @@ -55,6 +62,11 @@ This project will run on this server: http://localhost:8000/ ``` +### Admin Panel Details +Link: http://localhost:8000/admin +Username: admin +Password: admin + ### Contribution 1. Fork and clone the repo.