Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Admin Panel #3

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@ Migrate the database.
```php
php artisan migrate
```
```

Seed the database.

```php
php artisan db:seed
```


Run this project on localhost
Expand All @@ -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.
Expand Down
65 changes: 65 additions & 0 deletions app/Http/Controllers/AdminController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use App\User;
use App\Register;

class AdminController extends Controller
{

/**
* Admin Panel dashboard.
*
* @return Response
*/
public function home(Request $request)
{
$yr_1 = Register::where('year', '1')->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']);
}
}
26 changes: 26 additions & 0 deletions app/Http/Controllers/Auth/LoginController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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']);
}
}
}
2 changes: 2 additions & 0 deletions app/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
class User extends Authenticatable
{
use Notifiable;

public $timestamps = false;

/**
* The attributes that are mass assignable.
Expand Down
34 changes: 34 additions & 0 deletions database/migrations/2018_10_27_203655_create_user_table.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateUserTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('users', function (Blueprint $table) {
$table->increments('id');
$table->string('username');
$table->string('password');
$table->boolean('new');
$table->rememberToken();
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('users');
}
}
2 changes: 1 addition & 1 deletion database/seeds/DatabaseSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ class DatabaseSeeder extends Seeder
*/
public function run()
{
// $this->call(UsersTableSeeder::class);
$this->call(UsersTableSeeder::class);
}
}
20 changes: 20 additions & 0 deletions database/seeds/UsersTableSeeder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

use Illuminate\Database\Seeder;

class UsersTableSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
DB::table('users')->insert([
'username' => 'admin',
'password' => bcrypt('admin'),
'new' => '1',
]);
}
}
48 changes: 48 additions & 0 deletions resources/views/AdminPanel/dashboard.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<!DOCTYPE html>
<html>
<head>
<title>Admin Panel</title>

<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">

<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin="anonymous"></script>
</head>
<body class="bg-dark">
<div class="container">
<ul class="list-group bg-white" style="margin-top: 8rem;">
<li class="list-group-item d-flex justify-content-between align-items-center">
1st Year
<span class="badge badge-primary badge-pill">{{ $yr_1 }}</span>
</li>
<li class="list-group-item d-flex justify-content-between align-items-center">
2nd Year
<span class="badge badge-primary badge-pill">{{ $yr_2 }}</span>
</li>
<li class="list-group-item d-flex justify-content-between align-items-center">
3rd Year
<span class="badge badge-primary badge-pill">{{ $yr_3 }}</span>
</li>
<li class="list-group-item d-flex justify-content-between align-items-center">
4th Year
<span class="badge badge-primary badge-pill">{{ $yr_4 }}</span>
</li>
<li class="list-group-item d-flex justify-content-between align-items-center active">
Total
<span class="badge badge-primary badge-pill">{{ $yr_1 + $yr_2 + $yr_3 + $yr_4 }}</span>
</li>
</ul>
<br>
<div class="text-center">
<a href="print" target="_blank" class="btn btn-lg btn-success">Print Registration Details</a>
&nbsp;
<a href="logout" class="btn btn-lg btn-danger">Logout</a>
</div>
<br>
</div>
</body>
</html>
58 changes: 58 additions & 0 deletions resources/views/AdminPanel/login.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<!DOCTYPE html>
<html>
<head>
<title>Login</title>

<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">

<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin="anonymous"></script>
</head>
<body class="bg-dark">
<div class="container">
<div class="row">
<div class="col-md-4 col-sm-4 col-xs-12"></div>
<div class="col-md-4 col-sm-4 col-xs-12 bg-white" style="margin-top: 8rem;">
<form action="admin/login" method="POST">
<br>
<div class="mx-auto">
<h1 class="font-weight-bold text-center">Login</h1>
@if (session('msg'))
<div class="alert {{ session('class') }}">
{{ session('msg') }}
</div>
@endif
</div>
{{ csrf_field() }}
<div class="form-group">
<label for="username">Username</label>
<input type="text" class="form-control {{ $errors->has('username') ? ' is-invalid' : '' }}" id="username" required name="username" autocomplete="off" placeholder="Username">
@if ($errors->has('username'))
<p class="text-danger">
{{ $errors->first('username') }}
</p>
@endif
</div>
<div class="form-group">
<label for="pwd">Password</label>
<input type="password" class="form-control {{ $errors->has('password') ? ' is-invalid' : '' }}" id="pwd" name="password" required placeholder="Password">
@if ($errors->has('password'))
<p class="text-danger">
{{ $errors->first('password') }}
</p>
@endif
</div>
<button type="submit" class="btn btn-success btn-block">Submit</button>
<br>
</form>
</div>
<div class="col-md-4 col-sm-4 col-xs-12"></div>
</div>
<br>
</div>
</body>
</html>
37 changes: 37 additions & 0 deletions resources/views/AdminPanel/print_data.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<!DOCTYPE html>
<html>
<head>
<title>Registration Details</title>

<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">

<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin="anonymous"></script>
</head>
<body>
<table class="table table-bordered">
<thead>
<tr>
<th scope="col">Present</th>
<th scope="col">Name</th>
<th scope="col">Year</th>
<th scope="col">Adm No</th>
</tr>
</thead>
<tbody>
@foreach($data as $d)
<tr>
<td></td>
<th>{{ $d->name }}</th>
<td>{{ $d->year }}</td>
<td>{{ $d->admission_no }}</td>
</tr>
@endforeach
</tbody>
</table>
</body>
</html>
Loading