User Registration

Overview Description

The user registration feature allows new users to create accounts in the system using standard email-based registration. The system validates user data, creates the user account, assigns default roles, and sends email verification. This is the traditional registration method that does not involve OAuth or third-party authentication.

API: User Registration API

Activity Diagram

flowchart TD
    A[User submits registration] --> B[Validate email, name, company]
    B --> C{Data valid?}
    C -->|No| D[Return validation error]
    C -->|Yes| E[Check email uniqueness]
    E --> F{Email unique?}
    F -->|No| G[Return duplicate email error]
    F -->|Yes| H[Create user account]
    H --> I[Assign default group role]
    I --> J[Send verification email]
    J --> K[Return success response]
    
    style A fill:#e1f5fe
    style K fill:#c8e6c9
    style D fill:#ffcdd2
    style G fill:#ffcdd2

Sequence Diagram

Standard Registration Flow

sequenceDiagram
    participant Client
    participant RegisterController
    participant AuthService
    participant Database
    participant EmailService
    
    Note over Client,EmailService: Standard Email Registration Flow
    
    rect rgb(200, 255, 200)
    Note right of Client: Happy Case Flow
    
    Client->>RegisterController: POST /api/v1/general/auth/register
    Note over Client,RegisterController: {email, name, companyName}
    
    rect rgb(200, 230, 255)
    Note right of RegisterController: Input Validation
    RegisterController->>RegisterController: Validate request data
    end
    
    rect rgb(200, 255, 255)
    Note right of RegisterController: Business Logic
    RegisterController->>AuthService: register(email, name, companyName)
    
    AuthService->>Database: Check email uniqueness
    Database-->>AuthService: Email available
    
    AuthService->>Database: Create user record
    Database-->>AuthService: User created
    
    AuthService->>Database: Assign default group role
    Database-->>AuthService: Role assigned
    end
    
    rect rgb(255, 255, 200)
    Note right of AuthService: Send Verification Email
    AuthService->>EmailService: Send verification email
    EmailService-->>AuthService: Email sent successfully
    end
    
    AuthService-->>RegisterController: User created successfully
    RegisterController->>Client: 201 Created + user data
    end
    
    rect rgb(255, 200, 200)
    Note right of Client: Error Handling
    rect rgb(255, 230, 230)
    alt Validation Error
        RegisterController->>Client: 422 Validation Error
    else Email Already Exists
        Database-->>AuthService: Email exists
        AuthService-->>RegisterController: Email conflict
        RegisterController->>Client: 409 Conflict
    else Database Error
        Database-->>AuthService: Database error
        AuthService-->>RegisterController: Error result
        RegisterController->>Client: 500 Internal Server Error
    end
    end
    end

Steps

Step 1: Submit Registration Request

  • Description: User submits registration form with email, name, and company
  • Request: POST /api/v1/general/auth/register
  • Validation:
    • Email format validation
    • Required field validation (email, name, companyName)
    • Company name length validation

Step 2: Validate Input Data

  • Description: System validates all input data
  • Action:
    • Check email format using Laravel validation rules
    • Validate name length and format
    • Validate company name requirements

Step 3: Check Email Uniqueness

  • Description: Ensure email is not already registered
  • Action:
    • Query database for existing email
    • Return error if email already exists

Step 4: Create User Account

  • Description: Create new user record in database
  • Action:
    • Store user information
    • Generate unique user identifier
    • Store user data with active status
    • Set is_first_login = true

Step 5: Assign Default Role

  • Description: Assign user to default group with appropriate role
  • Action:
    • Create group membership record
    • Assign admin (new group)

Step 6: Send Verification Email

  • Description: Send email with verification link to registered email
  • Action:
    • Generate verification token
    • Send email with verification link
    • Log email sending status

Step 7: Return Success Response

  • Description: Send successful response to client
  • Response:
    • Success: 201 Created with user data
    • Include user ID, name, email, and status
    • Send email with verification link to registered email

Database Related Tables & Fields

erDiagram
    users {
        bigint id PK "Primary key"
        varchar name "User's full name"
        varchar email UK "User's email address (unique)"
        varchar payment_provider_customer_id "Payment provider customer ID"
        tinyint status "User status (1: active, 0: inactive)"
        varchar remember_token "Laravel remember token"
        timestamp created_at "Creation timestamp"
        timestamp updated_at "Last update timestamp"
        timestamp deleted_at "Soft delete timestamp"
        boolean is_first_login "First login flag"
    }
    
    groups {
        bigint id PK "Primary key"
        varchar name "Group name"
        text description "Group description"
        bigint created_by FK "User who created the group"
        timestamp created_at "Creation timestamp"
        timestamp updated_at "Last update timestamp"
    }
    
    group_members {
        bigint id PK "Primary key"
        bigint group_id FK "Group ID"
        bigint user_id FK "User ID"
        bigint group_role_id FK "Role ID in the group"
        timestamp created_at "Creation timestamp"
        timestamp updated_at "Last update timestamp"
    }
    
    group_roles {
        bigint id PK "Primary key"
        varchar name "Role name"
        text description "Role description"
        timestamp created_at "Creation timestamp"
        timestamp updated_at "Last update timestamp"
    }
    
    users ||--o{ group_members : "has"
    groups ||--o{ group_members : "contains"
    group_roles ||--o{ group_members : "defines"
    users ||--o{ groups : "creates"

Error Handling

HTTP Status Error Code Description
409 EMAIL_ALREADY_EXISTS Email address is already registered
422 UNPROCESSABLE_ENTITY Validation errors in request data
500 INTERNAL_SERVER_ERROR Server error during registration process

Additional Notes

  • Standard Registration Only: This endpoint is specifically for email-based registration without OAuth
  • Email Validation: Ensures proper email format and uniqueness
  • Company Information: Required for business context and group management
  • Default Roles: New users are automatically assigned to default groups
  • No OAuth: This registration method does not involve Google, Facebook, or other OAuth providers
  • Status Management: New users are created with active status by default
  • First Login Tracking: Users are marked for first-time login experience
  • Email Verification: Registration includes email verification for enhanced security