Skip to content
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
7 changes: 7 additions & 0 deletions LibraryManagement.code-workspace
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"folders": [
{
"path": "."
}
]
}
112 changes: 112 additions & 0 deletions app/Http/Controllers/AdminController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
<?php

namespace App\Http\Controllers;

use App\Http\Requests\ProfileRequest;
use App\Services\UserService;
use Illuminate\Http\Request;
use App\Models\User;

class AdminController extends Controller
{
public function __construct()
{
$this->middleware('auth');
}
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
$users = User::paginate(User::PAGINATE);

return view('admin.user.list', compact('users'));
}

/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function ban(User $user)
{

if ($user->is_banned) {
$user->is_banned = 0;
} else {
$user->is_banned = 1;
}
$user->update();

return redirect()->back()->with('success', 'User Status Changed');
}

public function delete(User $user)
{
$user->delete();
return redirect()->back()->with('success', 'User Deleted');
}
public function create()
{
return view('admin.user.add');
}

/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(ProfileRequest $request, UserService $action)
{
$action->storeUser($request);
return redirect()->back()->with('success', 'Librarian Added');
}

/**
* Display the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function show($id)
{
//
}

/**
* Show the form for editing the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function edit($id)
{
//
}

/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param int $id
* @return \Illuminate\Http\Response
*/
public function update(Request $request, $id)
{
//
}

/**
* Remove the specified resource from storage.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function destroy($id)
{
//
}
}
21 changes: 13 additions & 8 deletions app/Http/Controllers/Auth/AuthenticatedSessionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,19 @@

use App\Http\Controllers\Controller;
use App\Http\Requests\Auth\LoginRequest;
use App\Models\User;
use App\Providers\RouteServiceProvider;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\View\View;

class AuthenticatedSessionController extends Controller
{
/**
* Display the login view.
*
* @return \Illuminate\View\View
* @return View
*/
public function create()
{
Expand All @@ -23,23 +26,25 @@ public function create()
/**
* Handle an incoming authentication request.
*
* @param \App\Http\Requests\Auth\LoginRequest $request
* @return \Illuminate\Http\RedirectResponse
* @param LoginRequest $request
* @return RedirectResponse
*/
public function store(LoginRequest $request)
{
$request->authenticate();

$request->session()->regenerate();

return redirect(RouteServiceProvider::HOME);
if ($request->userType() == User::ROLE_USER) {
return redirect(RouteServiceProvider::DASHBOARD);
} else {
return redirect(RouteServiceProvider::HOME);
}
}

/**
* Destroy an authenticated session.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\RedirectResponse
* @param Request $request
* @return RedirectResponse
*/
public function destroy(Request $request)
{
Expand Down
92 changes: 92 additions & 0 deletions app/Http/Controllers/AuthorController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
<?php

namespace App\Http\Controllers;

use App\Http\Requests\AuthorRequest;
use App\Models\Author;
use App\Services\AuthorService;
use Illuminate\Http\Request;

class AuthorController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
$authors = Author::paginate(Author::PAGINATE);
return view('admin.author.list', compact('authors'));
}

/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create()
{
return view('admin.author.add');
}

/**
* Store a newly created resource in storage.
*
* @param AuthorRequest $request
* @param AuthorService $action
* @return void
*/
public function store(AuthorRequest $request, AuthorService $action)
{
$action->storeAuthor($request);
return redirect()->back()->with('success', 'Author Added');
}

/**
* Display the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function show($id)
{
//
}

/**
* Show the form for editing the specified resource.
*
* @param Author $author
* @return \Illuminate\Http\Response
*/
public function edit(Author $author)
{
return view('admin.author.edit', compact('author'));
}

/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param int $id
* @return \Illuminate\Http\Response
*/
public function update(Request $request, $id)
{
//
}

/**
* Remove the specified resource from storage.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function destroy(Author $author)
{
$author->delete();
return redirect()->back()->with('success', 'Author Deleted');

}
}
33 changes: 33 additions & 0 deletions app/Http/Controllers/UserController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

namespace App\Http\Controllers;

use App\Http\Requests\ProfileRequest;
use App\Models\User;
use App\Services\UserService;

Comment thread
me-shaon marked this conversation as resolved.
class UserController extends Controller
{
public function __construct()
{
$this->middleware('auth');
}
Comment thread
me-shaon marked this conversation as resolved.

public function profile(User $user)
{
return view('profile', compact('user'));
}
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add an empty line after the method.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done


public function dashboard()
{
return view('user.dashboard');
}
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add an empty line after the method.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You've missed this.


public function profileUpdate(ProfileRequest $request, UserService $action)
{
$profile = $action->getUser($request->id);
$action->updateUser($request, $profile);
return redirect()->back()->with('success', 'Profile updated');
}

}
14 changes: 10 additions & 4 deletions app/Http/Requests/Auth/LoginRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,8 @@ public function authenticate()
{
$this->ensureIsNotRateLimited();

if (! Auth::attempt($this->only('email', 'password'), $this->filled('remember'))) {
if (!Auth::attempt($this->only('email', 'password', 'is_banned'), $this->filled('remember'))) {
RateLimiter::hit($this->throttleKey());

throw ValidationException::withMessages([
'email' => __('auth.failed'),
]);
Expand All @@ -56,6 +55,8 @@ public function authenticate()
RateLimiter::clear($this->throttleKey());
}

//I have created this method

/**
* Ensure the login request is not rate limited.
*
Expand All @@ -65,7 +66,7 @@ public function authenticate()
*/
public function ensureIsNotRateLimited()
{
if (! RateLimiter::tooManyAttempts($this->throttleKey(), 5)) {
if (!RateLimiter::tooManyAttempts($this->throttleKey(), 5)) {
return;
}

Expand All @@ -88,6 +89,11 @@ public function ensureIsNotRateLimited()
*/
public function throttleKey()
{
return Str::lower($this->input('email')).'|'.$this->ip();
return Str::lower($this->input('email')) . '|' . $this->ip();
}

public function userType()
{
return auth()->user()->role;
}
}
31 changes: 31 additions & 0 deletions app/Http/Requests/AuthorRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

class AuthorRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}

/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'name' => 'required',
'description' => 'required'
];
}
}
Loading