karolstawowski / OxiSweeperBackend

Backend for OxiSweeper made using PHP and Laravel.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

OxiSweeperBackend

Language License Version

Description

Laravel implementation of backend for popular game called 'Minesweeper' made by Robert Donner.
OxiSweeperBackend implements application user interface and database for user authentication, authorization and record tracking.
OxiSweeperFrontend implements the Minesweeper game itself and routing for users depending of theirs role.

Installation and usage

Prerequisite

To run the project you need to have followed software installed:

  1. Xampp
  2. Composer
  3. Laravel Sanctum

Installation

  1. Clone the repository:
git clone https://github.com/karolstawowski/OxiSweeperBackend
  1. Create .env file based on .env.example
copy .env.example .env
  1. Run Apache and MySQL server using Xampp

  2. Create new database (default database name: minesweeper)

  3. Migrate the database:

php artisan migrate
  1. Seed the database with records:
php artisan db:seed

Project run

To run the project use

php artisan serve

command in the root directory of the repositorium.

Use case example

  1. User enters log in/register page
  2. User logs in/creates new accout
  3. User is redirected to route based on role - /game or /dashboard
  4. User can log out, which redirects to /login page

Authorization/authentication model

When user logs in or registers, user token is being assigned. User token is stored on the client side in cookies. Every time user enters any page, request for user role to backend is being sent. User role is stored in frontend application's context. Unauthorized user is being redirected to allowed path. Unauthenticated user can access /login path only.

Database structure

Scores table

CREATE TABLE `scores` (
  `id` bigint(20) UNSIGNED NOT NULL PRIMARY KEY,
  `score` int(11) NOT NULL,
  `user_id` bigint(20) UNSIGNED NOT NULL FOREIGN KEY,
  `difficulty_level` enum('1','2','3') COLLATE utf8mb4_unicode_ci NOT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

Users table

CREATE TABLE `users` (
  `id` bigint(20) UNSIGNED NOT NULL PRIMARY KEY,
  `name` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
  `password` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
  `user_role_id` bigint(20) UNSIGNED NOT NULL DEFAULT 2 FOREIGN KEY,
  `remember_token` varchar(100) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

User roles table

CREATE TABLE `user_roles` (
  `id` bigint(20) UNSIGNED NOT NULL PRIMARY KEY,
  `role_name` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

API Routes

Public routes

  • POST /register
  • POST /login

Protected routes

  • GET /users
  • GET /scores
  • GET /score/top/{user_token}/{difficulty_level}
  • POST /role
  • POST /user
  • POST /score
  • POST /logout

Tools and technologies

PHP, Laravel, Sanctum, Eloquent ORM.

About

Backend for OxiSweeper made using PHP and Laravel.

License:MIT License


Languages

Language:PHP 82.9%Language:Blade 15.8%Language:Shell 0.8%Language:JavaScript 0.5%