Skip to content
Merged
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
11 changes: 11 additions & 0 deletions app/Http/Controllers/Auth/RegisterController.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,17 @@ public function handleVerify(Request $request)
$user->otp_expiry = null;
$user->save();

$this->mailer->sendTemplate(
$user->email,
$user->name,
'welcome',
[
'subject' => 'Welcome to OpenShelf!',
'user_name' => $user->name,
],
$user->id
);

$request->session()->forget('verify_email');

return redirect()->route('login')->with('success', 'Your account is verified. You may now sign in.');
Expand Down
51 changes: 51 additions & 0 deletions app/Http/Middleware/CheckRememberToken.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

namespace App\Http\Middleware;

use Closure;
use Illuminate\Http\Request;
use Symfony\Component\HttpFoundation\Response;
use App\Models\RememberToken;
use App\Models\User;

class CheckRememberToken
{
/**
* Handle an incoming request.
*
* @param \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response) $next
*/
public function handle(Request $request, Closure $next): Response
{
if (!$request->session()->has('user_id') && $request->cookie('remember_token')) {
$token = $request->cookie('remember_token');

if (str_contains($token, ':')) {
[$tokenUserId, $tokenValue] = explode(':', $token, 2);

$rememberToken = RememberToken::query()
->where('user_id', $tokenUserId)
->where('token', hash('sha256', $tokenValue))
->where('expiry', '>', time())
->first();

if ($rememberToken) {
$user = User::find($tokenUserId);
if ($user && $user->status === 'active') {
$request->session()->put([
'user_id' => $user->id,
'user_name' => $user->name,
'user_role' => $user->role,
'user_hall' => $user->hall,
'login_time' => time(),
]);
// Don't call regenerate here as it might conflict with other session operations in middleware
// Let the framework handle it naturally
}
}
}
}

return $next($request);
}
}
113 changes: 113 additions & 0 deletions app/Services/BorrowRequestService.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class BorrowRequestService
public function __construct(
private BookQueryService $bookQueryService,
private NotificationService $notificationService,
private MailerService $mailerService,
) {
}

Expand Down Expand Up @@ -67,6 +68,25 @@ public function createRequest(
'/requests/?id=' . $requestId,
);

$this->mailerService->sendTemplate(
$owner->email,
$owner->name,
'borrow_request',
[
'subject' => 'New Borrow Request for "' . $book->title . '"',
'owner_name' => $owner->name,
'book_title' => $book->title,
'book_author' => $book->author,
'borrower_name' => $borrowerName,
'borrower_email' => $borrower->email,
'borrower_department' => $borrower->department,
'duration_days' => $duration,
'borrower_phone' => $borrower->phone,
'message' => $message,
],
$owner->id
);

return $borrowRequest;
}

Expand Down Expand Up @@ -109,6 +129,27 @@ public function fileReturn(BorrowRequest $borrowRequest, string $userId, string
'/confirm-return/?token=' . $confirmationToken,
);

$owner = User::find($borrowRequest->owner_id);
if ($owner) {
$this->mailerService->sendTemplate(
$owner->email,
$owner->name,
'book_returned_owner',
[
'subject' => 'Please confirm return of "' . $borrowRequest->book_title . '"',
'owner_name' => $owner->name,
'borrower_name' => $userName,
'book_title' => $borrowRequest->book_title,
'return_date' => now()->toDateString(),
'return_condition' => $data['return_condition'] ?? 'same',
'return_notes' => $data['notes'] ?? '',
'confirm_url' => config('app.url') . '/confirm-return/?token=' . $confirmationToken,
'reject_url' => config('app.url') . '/confirm-return/?token=' . $confirmationToken . '&action=reject',
],
$owner->id
);
}

return true;
}

Expand Down Expand Up @@ -159,6 +200,23 @@ public function confirmReturn(BorrowRequest $borrowRequest, string $action, ?str
'/requests/?id=' . $borrowRequest->id,
);

$borrower = User::find($borrowRequest->borrower_id);
if ($borrower) {
$this->mailerService->sendTemplate(
$borrower->email,
$borrower->name,
'return_confirmed_borrower',
[
'subject' => 'Return Confirmed for "' . $borrowRequest->book_title . '"',
'borrower_name' => $borrower->name,
'owner_name' => $borrowRequest->owner_name,
'book_title' => $borrowRequest->book_title,
'confirm_date' => now()->toDateString(),
],
$borrower->id
);
}

return 'confirmed';
}

Expand Down Expand Up @@ -189,6 +247,23 @@ public function confirmReturn(BorrowRequest $borrowRequest, string $action, ?str
'/requests/?id=' . $borrowRequest->id,
);

$borrower = User::find($borrowRequest->borrower_id);
if ($borrower) {
$this->mailerService->sendTemplate(
$borrower->email,
$borrower->name,
'return_rejected_borrower',
[
'subject' => 'Return Rejected for "' . $borrowRequest->book_title . '"',
'borrower_name' => $borrower->name,
'owner_name' => $borrowRequest->owner_name,
'book_title' => $borrowRequest->book_title,
'reject_reason' => $rejectReason,
],
$borrower->id
);
}

return 'rejected';
}

Expand Down Expand Up @@ -274,6 +349,27 @@ public function approveRequest(BorrowRequest $borrowRequest, string $ownerId): b
'/requests/?id=' . $borrowRequest->id,
);

$borrower = User::find($borrowRequest->borrower_id);
$owner = User::find($ownerId);

if ($borrower && $owner) {
$this->mailerService->sendTemplate(
$borrower->email,
$borrower->name,
'request_approved',
[
'subject' => 'Request Approved for "' . $borrowRequest->book_title . '"',
'borrower_name' => $borrower->name,
'book_title' => $borrowRequest->book_title,
'owner_name' => $owner->name,
'owner_room' => $owner->room_number . ' (' . $owner->hall_name . ')',
'owner_phone' => $owner->phone,
'expected_return' => $borrowRequest->expected_return_date,
],
$borrower->id
);
}

return true;
}

Expand Down Expand Up @@ -309,6 +405,23 @@ public function rejectRequest(BorrowRequest $borrowRequest, string $ownerId, str
'/requests/?id=' . $borrowRequest->id,
);

$borrower = User::find($borrowRequest->borrower_id);

if ($borrower) {
$this->mailerService->sendTemplate(
$borrower->email,
$borrower->name,
'request_rejected',
[
'subject' => 'Request Rejected for "' . $borrowRequest->book_title . '"',
'borrower_name' => $borrower->name,
'book_title' => $borrowRequest->book_title,
'rejection_reason' => $reason,
],
$borrower->id
);
}

return true;
}

Expand Down
4 changes: 3 additions & 1 deletion bootstrap/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
health: '/up',
)
->withMiddleware(function (Middleware $middleware): void {
//
$middleware->web(append: [
\App\Http\Middleware\CheckRememberToken::class,
]);
})
->withExceptions(function (Exceptions $exceptions): void {
$exceptions->shouldRenderJsonWhen(
Expand Down
18 changes: 17 additions & 1 deletion resources/views/partials/header.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -447,10 +447,26 @@
border-radius: 12px;
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
margin-top: 0.5rem;
min-width: 280px;
width: 340px;
max-width: calc(100vw - 2rem);
z-index: 1000;
}

@media (max-width: 768px) {
.notification-bell,
.user-menu {
position: static;
}

.notification-dropdown,
.user-dropdown {
left: 1rem;
right: 1rem;
width: auto;
max-width: none;
}
}

[data-theme="dark"] .notification-dropdown,
[data-theme="dark"] .user-dropdown {
background: #1e293b;
Expand Down