GitHub Timeline Assignment

Create a simple PHP application that accepts a visitor’s email address and emails them a GitHub timeline update every five minutes.

Approach to build this application

  • Using Model View Controller (MVC) architecture for better organization and sepration of concerns.
  • MySQL database is used for persisting data. Using PDO for interaction with database. Only using prepared statements for preventing SQL injection.

Project Workflow Overview

User Interaction

  1. User visits https://host/.
  2. User enters their email.
  3. User clicks the subscribe button.
  4. Form data (email) is submitted via POST method to https://host/subscribe.

Subscription Process

  1. POST method to https://host/subscribe action:
  2. Email is validated.
  3. verification token is generated.
  4. Email and verification token is inserted in to verify table.
  5. Email with a verification link (https://host/verify?token=abc) is sent to the user.

Verification Process

  1. User clicks on the verification link.
  2. GET method to https://host/verify?token=abd.
  3. Verification token is validated.
  4. Token is searched in verify table.
  5. If token is found.
  6. Unsubscribe token is generated.
  7. Email and unsubscribe token is inserted in to the subscribed table.
  8. Row is deleted from the verify table.

Email Delivery

  1. All subscribed emails are fetched form subscribed table.
  2. https://github.com/timeline is fetched and returns XML data.
  3. XML data is parsed and required fields are extracted.
  4. Message is created using email template for each email.
  5. mail() is used to send the each email.

Unsubscription Process

  1. Each email contains an unsubscribe link at the bottom (https://host/unsubscribe?token=abc).
  2. If user clicks the unsubscribe link.
  3. subscribed table is searched for unsubscribe token.
  4. If found then the row is deleted from subscribed table.

Database Schemas

  • verify table
CREATE TABLE verify (
  id INT(10) AUTO_INCREMENT PRIMARY KEY,
  email VARCHAR(50) NOT NULL UNIQUE,
  token varchar(50) NOT NULL 
)
  • subscribed table
CREATE TABLE subscribed (
  id INT(10) AUTO_INCREMENT PRIMARY KEY,
  email VARCHAR(50) NOT NULL UNIQUE,
  token varchar(50) NOT NULL 
)

Project File Structure

.
└── app/
    ├── public/
    │   └── index.php
    ├── sql/
    │   └── local.sql
    ├── src/
    │   ├── Controllers/
    │   │   ├── HomeController.php
    │   │   └── SubscriptionController.php
    │   ├── Models/
    │   │   ├── Datbase.php
    │   │   ├── Mail.php
    │   │   └── Subscription.php
    │   ├── Views/
    │   │   ├── 404.html
    │   │   ├── Home.php
    │   │   └── Message.php
    │   ├── cronjobs/
    │   │   ├── cron_email_template.php
    │   │   ├── send_emails.php
    │   │   └── xmlhelper.php
    │   ├── templates/
    │   │   └── email_templates.php
    │   ├── autoloader.php
    │   ├── Controller.php
    │   ├── Router.php
    │   └── routes.php
    ├── .gitignore
    ├── phpcs.xml
    └── README.md
«
»

Leave a Reply

Your email address will not be published. Required fields are marked *