An open API service indexing awesome lists of open source software.

https://github.com/zyron-tech/dummy-backend

A PHP backend with email OTP authentication using PHPMailer and PostgreSQL. It provides APIs for user registration, login, and OTP verification, designed for seamless integration with frontend applications.
https://github.com/zyron-tech/dummy-backend

backend-api email-otp email-otp-validation email-sender otp-verification php user-authentication

Last synced: 3 months ago
JSON representation

A PHP backend with email OTP authentication using PHPMailer and PostgreSQL. It provides APIs for user registration, login, and OTP verification, designed for seamless integration with frontend applications.

Awesome Lists containing this project

README

          

# PHP Backend with Email OTP Authentication

This backend system is built with PHP, using PHPMailer for sending OTPs via email during user registration and login processes. The backend connects to a PostgreSQL database to manage users and authentication.

## How to Integrate with Frontend

### Overview

The backend provides RESTful API endpoints for sign-up, login, and OTP verification. To connect the frontend (e.g., a React, Vue, or plain HTML/JavaScript application) to the backend, you will use HTTP requests (e.g., `fetch` or `axios`) to interact with these endpoints.

### API Endpoints

1. **Sign Up Endpoint**: Registers a new user and sends an OTP to their email.
- **URL**: `/public/signup.php`
- **Method**: `POST`
- **Parameters**: `username`, `password`, `email`

2. **Login Endpoint**: Logs in the user with email and password.
- **URL**: `/public/login.php`
- **Method**: `POST`
- **Parameters**: `email`, `password`

3. **Verify OTP Endpoint**: Verifies the OTP sent to the user’s email during sign-up.
- **URL**: `/public/verify-otp.php`
- **Method**: `POST`
- **Parameters**: `email`, `otp`

4. **Delete Account Endpoint**: Users can easily delete their account if it is no longer needed
- **URL**: `/public/delete_account.php`
- **Method**: `POST`
- **Parameters**: `email`,`password`

### Example Frontend Integration

Here's a basic HTML/JavaScript example showing how to interact with the backend API endpoints using the `fetch` API:

#### Sample Sign-Up Form

```html




User Sign-Up





Sign Up


document.getElementById('signupForm').addEventListener('submit', async (e) => {
e.preventDefault();
const formData = new FormData(e.target);

try {
const response = await fetch('https://dummy-backend-gyc3.onrender.com/public/signup.php', {
method: 'POST',
body: formData
});
const result = await response.json();
alert(result.message);
} catch (error) {
console.error('Error during sign-up:', error);
alert('An error occurred. Please try again.');
}
});

```

#### Sample Verify Otp Code

```html




Verify OTP




Verify OTP


document.getElementById('verifyOtpForm').addEventListener('submit', async (e) => {
e.preventDefault();
const formData = new FormData(e.target);

try {
const response = await fetch('https://dummy-backend-gyc3.onrender.com/public/verify-otp.php', {
method: 'POST',
body: formData
});
const result = await response.json();
alert(result.message);
} catch (error) {
console.error('Error during OTP verification:', error);
alert('An error occurred. Please try again.');
}
});

```