verifyemailApi - n1lby73/industrial-IOT GitHub Wiki

Overview

The Email Verification API allows users to verify their email addresses using a one-time password (OTP) generated and sent to their registered email. Upon successful verification, the user's email will be marked as verified.

Endpoint URL

  • URL: https://industrialiot.onrender.com/api/verifyemail

  • Allowed Methods:

    HTTP Method Function
    POST For completing email verification
    PUT For changing email where otp is sent to - for cases of typo during registration
    GET Requesting new OTP - cases of expired OTP

Request Parameters

  • Headers:

    • Content-Type: application/json
  • Body Parameters:

    • For POST method:

      Parameter Type Description
      otp String The one-time password received via email (required).
      email String User's email where otp was sent (required)
    • For PUT method:

      Parameter Type Description
      email String User's initial email address used in the registering phase (required)
      newEmail String New email to send OTP code (required)
    • For GET method:

      Parameter Type Description
      email String User's email address (required)

Responses

  • For POST method:

    • Success Response:

      • Status Code: 200 OK

      • Response Body:

        {
          "success": "email verified successfully"
        }
    • Error Responses:

    • Status Code: 400 Bad Request

      • Response Body:

        {
          "error": "email does not exist"
        }
      • Reason: The email sent to verify has not been registered or does not exist in the database

    • Status Code: 409 Conflict

      • Response Body:

        {
          "alert":"email verification already completed"
        }
      • Reason: The email sent to verify has already been verified

    • Status Code: 400 Bad Request

      • Response Body:

        {
          "error": "invalid otp entered"
        }
      • Reason: User input a wrong OTP that was not stored in the database

    • Status Code: 400 Bad Request

      • Response Body:

        {
          "error": "expired otp, request for a new one"
        }
      • Reason: OTP timeout has elapsed

    • Status Code: 500 Internal Server Error

      • Response Body:

        {
          "error": "failed to update db", 
          "details": "<error details>"
        }
      • Reason: Indicates an error to populate database with new data within the server

    • Status Code: 500 Internal Server Error

      • Response Body:

        {
          "error": "verification unsuccessfull",
          "details": "<error details>"
        }
      • Reason: Indicates an error to complete email verification

  • For PUT method:

    • Success Response:

      • Status Code: 200 OK
      • Response Body:
        {
          "success": "email update completed and otp sent to new email",
        
          "email": "<updated Email>"
        }
        • Description: Indicates a successful email change.
    • Error Responses:

      • Status Code: 409 conflict

        • Response Body:
          {
            "alert": "email already exist, login instead"
          }
        • Description: Indicates that email user intends to switch to already exist.
      • Status Code: 400 Bad Request

        • Response Body:
          {
            "error": "invalid email format"
          }
        • Description: Indicates the user email is not a valid format
      • Status Code: 400 Bad Request

        • Response Body:
          {
            "error":"invalid old email"
          }
        • Description: Indicates the old email is not a valid one
      • Status Code: 500 Internal Server Error

        • Response Body:
          {
            "error": "update unsuccessfull",
            "details": "<Error Details>"
          }
        • Description: Indicates a failure to update the email due to an internal server error.
  • For GET method:

    • Success Response:

      • Status Code: 200 OK
      • Response Body:
        {
          "success": "otp sent to mail"
        }
        • Description: Indicates successful OTP generation and email sent for OTP verification.
    • Error Responses:

      • Status Code: 409 conflict

        • Response Body:
          {
            "alert": "email already exist, login instead"
          }
        • Description: Indicates that email user is requestng OTP for has already been verified.
      • Status Code: 400 Bad Request

        • Response Body:
          {
            "error": "invalid email format"
          }
        • Description: Indicates the user email is not a valid format
      • Status Code: 500 Internal Server Error

        • Response Body:
          {
            "error": "could not update db",
            "details": "<Error Details>"
          }
        • Description: Indicates a failure to update the database with the new OTP
      • Status Code: 500 Internal Server Error

        • Response Body:
          {
            "error": "OTP generation failed"
          }
        • Description: Indicates a failure to generate the OTP due to an internal server error.

Usage

  • For POST method:

    1. Request Method: POST

    2. Endpoint URL: https://industrialiot.onrender.com/api/verifyemail

    3. Header:

       Content-Type: application/json
    4. Request Body:

      {
        "otp": "<OTP sent to mail>",
        "email": "<Email to be verified>"
      }
  • For PUT method:

    1. Request Method: PUT

    2. Endpoint URL: https://industrialiot.onrender.com/api/verifyemail

    3. Header:

       Content-Type: application/json
    4. Request Body:

      {
          "email": "<Email used during registration>",
          "newEmail": "<Email to change to>"
      }
  • For GET method:

    1. Request Method: GET

    2. Endpoint URL: https://industrialiot.onrender.com/api/verifyemail

    3. Header:

       Content-Type: application/json
    4. Request Body:

      {
        "email": "<USER_EMAIL>"
      }
⚠️ **GitHub.com Fallback** ⚠️