EstateHub

Administrator Authentication API

Base URL: http://localhost:8000/api/v1
Prefix: /accounts/admins
Auth: JWT Bearer token for protected endpoints
Headers: Content-Type: application/json

1. Admin Login

Authenticate an admin user and return JWT tokens.

POST/accounts/admins/login/

Auth: Not required

Request Body

JSON
{
  "email": "admin@example.com",
  "password": "StrongPass123"
}

Success Example

JSON
{
  "success": true,
  "message": "Admin logged in successfully.",
  "data": {
    "admin": {
      "id": 1,
      "full_name": "Admin User",
      "email": "admin@example.com",
      "phone": null,
      "roles": [
        "admin"
      ],
      "status": "active",
      "is_active": true,
      "is_staff": true,
      "is_superuser": false
    },
    "tokens": {
      "refresh": "jwt_refresh_token",
      "access": "jwt_access_token"
    }
  }
}

Notes

  • Only users with the admin role can log in through this endpoint.

  • Inactive, blocked, deleted, customer, and seller accounts are rejected.


2. Admin Logout

Logout an admin session by blacklisting the refresh token.

POST/accounts/admins/logout/

Auth: Required

Headers

HTTP
Authorization: Bearer {{access_token}}

Request Body

JSON
{
  "refresh": "jwt_refresh_token"
}

Success Example

JSON
{
  "success": true,
  "message": "Logged out successfully.",
  "data": {}
}

Notes

  • Requires an authenticated admin access token.

  • The submitted refresh token is blacklisted.


3. Refresh Admin JWT Access Token

Generate a new admin access token from a valid admin refresh token.

POST/accounts/admins/token/refresh/

Auth: Not required

Request Body

JSON
{
  "refresh": "jwt_refresh_token"
}

Success Example

JSON
{
  "success": true,
  "message": "Access token refreshed successfully.",
  "data": {
    "access": "new_jwt_access_token"
  }
}

Notes

  • The refresh token must belong to an admin user.

  • Customer and seller refresh tokens are rejected.


4. Change Admin Password

Change the password for the currently authenticated admin.

POST/accounts/admins/change-password/

Auth: Required

Headers

HTTP
Authorization: Bearer {{access_token}}

Request Body

JSON
{
  "current_password": "StrongPass123",
  "new_password": "NewStrongPass123"
}

Success Example

JSON
{
  "success": true,
  "message": "Password changed successfully.",
  "data": {}
}

Notes

  • Requires an authenticated admin access token.

  • current_password must match the admin's existing password.

  • new_password must pass Django password validation.


5. Send Admin Reset Password Email

Send password reset instructions to an admin email address.

POST/accounts/admins/send-reset-password-email/

Auth: Not required

Request Body

JSON
{
  "email": "admin@example.com"
}

Success Example

JSON
{
  "success": true,
  "message": "If the email exists, password-reset instructions were sent.",
  "data": {}
}

Notes

  • The response is generic to avoid exposing whether an email exists.

  • Reset instructions are only sent when the email belongs to an admin user.


6. Reset Admin Password

Reset an admin password using a password reset token.

POST/accounts/admins/reset-password/

Auth: Not required

Request Body

JSON
{
  "token": "password_reset_token",
  "password": "ResetStrongPass123"
}

Success Example

JSON
{
  "success": true,
  "message": "Password reset successfully.",
  "data": {}
}

Notes

  • The token must be a valid, unexpired admin password reset token.

  • password must pass Django password validation.


Common Success Format

JSON
{
  "success": true,
  "message": "Success message.",
  "data": {}
}

Common Error Format

JSON
{
  "success": false,
  "message": "Validation failed.",
  "errors": {
    "email": [
      "Enter a valid email address."
    ]
  }
}