Skip to content

Laravel Web Application for Advanced Web Programming Module (V2)

Notifications You must be signed in to change notification settings

Wasim27/wasocial-v2

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

78 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation


Logo

Wasocial

By Wasim Ramzan (u1970064)
Advanced Web Programming · Assignment 2
University of Huddersfield

Table of Contents
  1. Project Description
  2. Getting Started
  3. Usage
  4. Extra Implementations Information
  5. Testing
  6. Reflective Analysis
  7. Contact
  8. References

Project Description

Product Image

Wasocial is a website that allows users to create and view posts in an efficient manner. Similar to the likes of Facebook, Twitter and other social networks.

During the second assignment my main focus was on implementing advanced features.


Advanced Features Implemented

  • Following and unfollowing feature
  • Google Two Factor Authentication
  • Docker
  • Build & Deploy to AWS Lightsail (Nginx)
    ... and other changes to some features

(back to top)

Technologies Used

Here are some of the frameworks, libraries and kits used which I made efficient use of whilst creating the website. Using these certain technologies saves time, allowing me to focus on the main features of the website.

(back to top)

Getting Started

Docker is now the best way to get the project setup allowing for efficient management of the dependencies.

Prerequisites

  • Docker & Docker-compose

Installation

  1. Clone the repo

    git clone [email protected]:hudds-awp2021-cht2520/assignment-02-Wasim27.git
  2. Build Dockerfile and start containers

    docker-compose build && docker-compose up -d
    
  3. Install the PHP dependencies

    docker-compose exec app composer install
  4. Make the .env file (copy .env.example to .env no changes are required)

  5. Provide permissions to the following folders

    sudo chmod -R 777 storage/
    sudo chmod -R 777 bootstrap/cache/
    
  6. Migrate the database and seed

    docker-compose exec app php artisan migrate:fresh --seed
  7. Generate application encryption key

    docker-compose exec app php artisan key:generate
  8. Go to the web server hosted by nginx
    http://localhost:8088/

(back to top)

Usage


Following and unfollowing feature

Users can now follow and unfollow eachother. This is a feature we see popular on social media where you can follow profiles of others. There is a lot of scalabiltiy with this feature. For example, I could further implement features such as messaging your followers, viewing only posts of those you follow and privacy options.

This was out of scope of my advanced features task as my interest was mainly on features that I aren't already similar to the ones I have done already.

You can view your followers on the right sidebar and click on them to go to their profile. This helps keep track on their lifestyle. Also, on the feed page the top 10 most followed users will be displayed.

Simply visit any users profile and follow them (or unfollow if you have already followed them)!


Homepage



Google Two Factor Authentication

Two factor authentication is essential for most websites as it enhances your security. Users are now able to use the Google Authenticator app as a secondary login security feature. Simply click on the security badge on the sidebar click generate secret key and follow the instructions to get setup!

Once setup users must verify their code to access the website. If the code expires on the app you may have to refresh the page and try again.

Pragmarx Google2fa a password authentication package provides me with the ability to generate OTP and verify these are correct.

Setup Auth Page
Verify Auth Page



Docker

Docker allows me to create containers which contain my dependencies. It also provides the ability to run code in any environment. Docker has made it easier for me to build, deploy and manage containers.

On the other hand, docker compose enables me to configure server and storage dependencies.
Here are the containers that I have running:

  • MySQL; database creation and management
  • Nginx; webserver to host my site
  • Mailhog; fake SMTP server for email testing
  • PHP; run PHP commands in the container


Apart from Mailhog the others should be self explanatory. We can use mailhog to test emails such as the forgotten password feature. If we were to send an email password reset link then it can be viewed on mailhog.

To view them after resetting a registered users password visit http://localhost:8025/

Login Page



AWS Lightsail

IMPORTANT: Docker will have the fully functioning website. AWS Lightsail will work for most features but does not have an email server. Also, it has not been fully tested so use Docker for most tasks.

AWS Lightsail similarly allows me to build and deploy my application but this time on the cloud. AWS Lightsail is a virtual private server provider. They provide many services such as database storage and hosting my application on the cloud. This is better for scalability as it does not require me to purchase a physical server myself.

This would particularly work well if my website was to go live. For example, I could manage domain names, backup my website and conduct many other management functions. To summarise, it would allow me to manage my app efficiently.

Currently, using the free tier as it is suitable for my needs. Again, I chose Nginx to host my webserver as seen below.


Lightsail Instance
Lightsail Databse

NOTE: NO LONGER DEPLOYED ON AWS!



Extra Implementations Information

  • Factories and seeders were used to create fake users, posts and likes. Fake likes can be viewed on the profile page of the default user

    Default user details:

    Email: [email protected]
    
    Password: testacc123
    

Testing

Testing is done using PHPUnit as this is what Laravel provides us by default.

Test updates:

  • Changed test files to contain their respective models/controller methods rather than mixing them
  • Further tests for views (2fa and other pages)
  • Tests for the following/unfollowing feature
  • Tests must be run in the docker container
  • The 2fa middleware can be tested in the routes by visiting /test_middleware

I have done this through assertions and checking if values exist or do not exist within the database.

To run tests simply run in the docker container:

docker-compose exec app php artisan test   

... and all tests should pass!



Test Success


IMPORTANT: MUST MIGRATE AND RESEED THE DATABASE FOR THE WEBSITE TO WORK AFTER RUNNING TESTS
docker-compose exec app php artisan test

(back to top)

Reflective Analysis

I chose AWS Lightsail as the cloud platform of my choice as it is what I found simplest to use. To get setup I only had to do small amounts of configuration and it was rather quick. The part which took most time was waiting for the instances/databases to create which is not a huge issue!

To create my instances I had to simply select my platform (Linux) and host (Nginx). Next steps were simple such as generating an ssh key, region and plan etc. After this I was able to ssh to the server and clone my application. After creating the database and setting it up on my .env file then configuring HTTP/HTTPS I was pretty much complete. Furthermore, the process was really simple and did not have any issues which I have not encountered previously.

Despite this, there were many alternatives such as Heroku which is supposedly more catered towards startups. Social media websites are resource intesive therefore AWS is the platform that can meet those high computational demands. Although mine wont go live, it would be very easy to scale and meet demands if for example my website were to receive more traction.

I am of course in charge of security issues of my server such as not leaking the key etc. For the cloud itself I can be safe with AWS security and rely on them to manage the cloud infrastructure. Alternatively, if I had a physical server I would be responsible for its security which could be daunting. Another essential feature is snapshots to backup my server. This would be important for any issues that occur on the server and always having a backup to rely on.

As mentioned previously, one of the main reasons I picked Lightsail was due to its simplicity. However, there is another AWS service called EC2. EC2 overall is much more powerful than Lightsail and provides greater server and database performance. With EC2 I would have to manually do alot of the things that were simpler on Lightsail such as configuring settings and generating the ssh key. The added complexity of EC2 was not worth it for my goals, although if I required increase in performance, it would be the viable option.

An improvement I could have done with Lightsail was to deploy my docker containers - as it would let me work with Mailhog and other dependencies which I have.


Test Success


(back to top)


Contact

Name: Wasim Ramzan

University Email: [email protected]

Project Link: https://github.com/hudds-awp2021-cht2520/assignment-01-Wasim27

(back to top)

References

Most references are inlined within the code however here are some that assisted in creating certain features.

(back to top)

About

Laravel Web Application for Advanced Web Programming Module (V2)

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages