# Account Suspension System Documentation

## Overview

The SwiftPay application now includes an enhanced account suspension system that allows administrators to:

1. **Suspend accounts with specific duration** (1-365 days)
2. **Set suspension reasons** for transparency
3. **Automatically reactivate accounts** when suspension expires
4. **Send email notifications** for all account status changes

## Features

### 1. Enhanced Account Status Management

Administrators can now change user account status with additional information:

-   **Active**: Normal account access
-   **Suspended**: Temporary restriction with automatic expiry
-   **Blocked**: Permanent account restriction

### 2. Suspension Duration

When suspending a user:

-   Required duration field (1-365 days)
-   Required reason field for documentation
-   Automatic calculation of suspension end date
-   Email notification to user with details

### 3. Automatic Reactivation

The system automatically reactivates suspended accounts through:

-   **Hourly cron job**: `users:reactivate-suspended`
-   **Middleware check**: Real-time verification during login
-   **Email notification**: User receives confirmation when reactivated

### 4. Email Notifications

Users receive emails for:

-   **Account suspended**: Duration, reason, and end date
-   **Account blocked**: Reason for blocking
-   **Account reactivated**: Welcome back message

## Database Schema

New fields added to `users` table:

-   `suspension_duration_days` (integer, nullable)
-   `suspended_until` (datetime, nullable)
-   `suspension_reason` (text, nullable)

## Scheduled Tasks

The command `users:reactivate-suspended` runs hourly to check for expired suspensions and automatically reactivate accounts.

## Usage Instructions

### Suspending a User

1. Navigate to user profile in admin panel
2. Click "Change Account Status"
3. Select "Suspended"
4. Enter suspension duration (1-365 days)
5. Provide suspension reason
6. Click "Update User Account Status"

The user will:

-   Receive an email with suspension details
-   Be logged out immediately
-   Have their account automatically reactivated after the specified period

### Blocking a User

1. Navigate to user profile in admin panel
2. Click "Change Account Status"
3. Select "Blocked"
4. Provide block reason
5. Click "Update User Account Status"

### Reactivating a User

1. Navigate to user profile in admin panel
2. Click "Change Account Status"
3. Select "Active"
4. Click "Update User Account Status"

## Email Templates

Email templates are located in:

-   `resources/views/emails/account-suspended.blade.php`
-   `resources/views/emails/account-blocked.blade.php`
-   `resources/views/emails/account-reactivated.blade.php`

## Console Commands

Run manual checks:

```bash
php artisan users:reactivate-suspended
```

## Middleware Updates

The `CheckAccountStatus` middleware now:

-   Checks for expired suspensions on login
-   Automatically reactivates expired accounts
-   Sends reactivation emails when needed
