API_AND.PHP

Overview

This endpoint handles customer login and initiates the “start quote” workflow for the logistics portal. It verifies a static API token, authenticates users via api_loginCustomer, and conditionally renders carrier-selection templates.

Authentication Mechanism

All requests must include a token query or form parameter matching the hard-coded value.

  • On invalid token, the API immediately returns a failure JSON and exits.
  • Valid token allows further action-specific processing.

Dependencies

  • inc/config.php: Loads database connection, helper functions (including api_loginCustomer), and defines TEMPLATE_DIR.
  • api_loginCustomer: Authenticates against the customers table, sets session variables, and returns login status.
  • Template files (under TEMPLATE_DIR/api_select_carrier/):
    • api_select_carrier_top.php
    • api_select_carrier_content.php

Common Parameters

Parameter Type Required Description
token string Yes Static API access token
action string Yes* Operation: LOGIN or start_quote
usr_email string Yes* Customer email
pwd string Yes (for LOGIN) Plaintext password (will be MD5-hashed)

* action and usr_email must both be present to trigger any processing .

Supported Actions

  • LOGIN 🟢: Authenticate user and return JSON status.
  • start_quote 🚀: Include carrier-selection HTML snippets.

Action: LOGIN

When action=LOGIN, the script:

  1. Hashes the supplied pwd using MD5.
  2. Calls api_loginCustomer($email, $hashedPwd, false, '1', $plainPwd).
  3. On successful login ($status['LOGIN'] === true), returns the full $status array as JSON.
  4. On failure, returns {"LOGIN":"FAIL","email":"<provided>"}.
{
  "title": "Customer Login",
  "description": "Authenticate a customer and start a session",
  "method": "POST",
  "baseUrl": "https://<your-domain>/linuxfront-v2-logistics",
  "endpoint": "/api_and.php",
  "headers": [
    {
      "key": "Content-Type",
      "value": "application/x-www-form-urlencoded",
      "required": true
    }
  ],
  "formData": [
    {
      "key": "token",
      "value": "04f5109a69305ead86c45cc08518e28e",
      "required": true
    },
    {
      "key": "action",
      "value": "LOGIN",
      "required": true
    },
    {
      "key": "usr_email",
      "value": "[email protected]",
      "required": true
    },
    {
      "key": "pwd",
      "value": "plaintextPassword",
      "required": true
    }
  ],
  "responses": {
    "200": {
      "description": "Login successful",
      "body": "{\n  \"Customer_ID\": 123,\n  \"Customer_Type\": \"company\",\n  \"Customer_email\": \"[email protected]\",\n  \"LOGIN\": true,\n  \"msg\": \"Login Successfull\"\n}"
    },
    "401": {
      "description": "Authentication failure",
      "body": "{\n  \"LOGIN\": \"FAIL\",\n  \"email\": \"[email protected]\"\n}"
    }
  }
}

Action: start_quote

When action=start_quote, assuming prior successful authentication, the script includes two template parts to render the carrier selection UI:

  • api_select_carrier_top.php
  • api_select_carrier_content.php
{
  "title": "Start Quote – Carrier Selection",
  "description": "Render the carrier selection interface for a new freight quote",
  "method": "POST",
  "baseUrl": "https://<your-domain>/linuxfront-v2-logistics",
  "endpoint": "/api_and.php",
  "headers": [
    {
      "key": "Content-Type",
      "value": "application/x-www-form-urlencoded",
      "required": true
    }
  ],
  "formData": [
    {
      "key": "token",
      "value": "04f5109a69305ead86c45cc08518e28e",
      "required": true
    },
    {
      "key": "action",
      "value": "start_quote",
      "required": true
    },
    {
      "key": "usr_email",
      "value": "[email protected]",
      "required": true
    },
    {
      "key": "pwd",
      "value": "plaintextPassword",
      "required": true
    }
  ],
  "responses": {
    "200": {
      "description": "HTML for carrier selection",
      "body": "<!-- HTML markup from api_select_carrier_top.php -->\n<div class=\"carrier-list\">…</div>"
    },
    "401": {
      "description": "Authentication failure",
      "body": "{\n  \"LOGIN\": \"FAIL\"\n}"
    }
  }
}

Error Handling

  • Invalid Token:
    { "LOGIN": "FAIL" }
    
  • Missing/Invalid Credentials:
    { "LOGIN": "FAIL", "email": "<provided>" }
    

Code Flow

flowchart TD
  A[Request] --> B{Validate token}
  B -- invalid --> C[Return {"LOGIN":"FAIL"}]
  B -- valid --> D{action & usr_email set?}
  D -- false --> E[No action performed]
  D -- true --> F[Hash pwd & call api_loginCustomer]
  F --> G{action == "LOGIN"?}
  G -- true --> H{LOGIN status}
  H -- true --> I[Return JSON status]
  H -- false --> J[Return {"LOGIN":"FAIL","email"}]
  G -- "start_quote" --> K[Include carrier templates]

Key Design Decisions

  • Static Token Check: Simplifies client access control without a full OAuth flow.
  • Single-File Endpoint: Combines login and UI rendering logic to minimize routing complexity.
  • Template Inclusion: Leverages PHP templates for HTML rather than JSON payloads in start_quote.

  • inc/config.php: Defines constants and bootstraps helper functions.
  • inc/functions_v2.inc.php: Contains the api_loginCustomer implementation, which handles credential validation and session initialization.
  • Templates under TEMPLATE_DIR/api_select_carrier/: UI pieces for carrier selection.

End of Documentation