Skip to content

SamuelRoberto/slim3-authentication

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Slim3 Session-Based Authentication

This project is a start point if you need to connect Slim3 with a secure Session-Based authentication. In this codebase you will find a complete skeleton that contains: Slim3 Framework, Twig View, MySQL Database(for users), both Bootstrap3 and FontAwesome implemented.

Why I created this project?

I had to create an application with Slim and a skeleton whitch includes a secure authentication was really helpfull: I didn't find nothing good. So I decided to create and share this simple skeleton. Hope it will help you!

Table of Content

Getting Started

Prerequisites

You have to install Composer before running the installation command. Click here to see more information about Composer!

Installing

Navigate into your folder and issuing this command into a command line

`$ composer create-project --no-interaction samuelr/slim3-auth myapp-name`

Run Project

  1. $ cd myapp-name
  2. $ sudo php -S 0.0.0.0:8888 -t public public/index.php
  3. Browse to http://localhost:8888

If you have any problem make sure that you launched this command with sudo!

What is included

In this project you will find a Slim3-Based Project with:

  1. Secure Session-Based authentication
  2. Twig-View Template engine
  3. MySQL Integration
  4. Bootstrap 3 and FontAwesome already loaded
  5. Integrated Monolog logger
  6. Clean and easily editable code

Authors

  • Samuel Roberto - Initial project

See also the list of contributors who participated in this project.

Mind Mapping

You can find a full mind mapping for this project here:

Documentation

Create and import database

To create database table open your MySQL (or MariaDB) console and launch the queries that you find in 'myapp-name/db/slim3_auth_example.sql'. However these are the schemas:

    -- MySQL Script generated by MySQL Workbench
    -- ven 30 giu 2017 20:20:04 CEST
    -- Model: New Model    Version: 1.0
    -- MySQL Workbench Forward Engineering
    
    SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0;
    SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;
    SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='TRADITIONAL,ALLOW_INVALID_DATES';
    
    -- -----------------------------------------------------
    -- Schema slim3_auth
    -- -----------------------------------------------------
    DROP SCHEMA IF EXISTS `slim3_auth` ;
    
    -- -----------------------------------------------------
    -- Schema slim3_auth
    -- -----------------------------------------------------
    CREATE SCHEMA IF NOT EXISTS `slim3_auth` DEFAULT CHARACTER SET utf8 ;
    USE `slim3_auth` ;
    
    -- -----------------------------------------------------
    -- Table `slim3_auth`.`user`
    -- -----------------------------------------------------
    DROP TABLE IF EXISTS `slim3_auth`.`user` ;
    
    CREATE TABLE IF NOT EXISTS `slim3_auth`.`user` (
      `id_user` INT NOT NULL AUTO_INCREMENT,
      `email` VARCHAR(120) NOT NULL,
      `password` VARCHAR(40) NOT NULL,
      `session` TEXT NOT NULL,
      `disabled` TINYINT(1) NOT NULL DEFAULT '0',
      `created_date` DATETIME NOT NULL DEFAULT NOW(),
      `modification_date` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
      PRIMARY KEY (`id_user`),
      UNIQUE INDEX `email_UNIQUE` (`email` ASC))
    ENGINE = InnoDB;
    
    
    SET SQL_MODE=@OLD_SQL_MODE;
    SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
    SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;

Database settings

Now open the folder 'myapp-name/app/src/config.php'. You will find the following code:

DEFINE('DB_HOST', 'localhost');
DEFINE('DB_USER', 'root');
DEFINE('DB_PASS', '');
DEFINE('DB_NAME', 'slim3_auth');

Now you can set your Database's host, user, password and name.

Key directories

  • app: Application code
  • app/src: All class files within the App namespace
  • app/templates: Twig template files
  • cache/twig: Twig's Autocreated cache files
  • db: Database Files
  • log: Log files
  • public: Webserver root
  • vendor: Composer dependencies

You can see a full structure at the following link.

Contributing

See the list of contributors who participated in this project.

Licenses

  • Slim3-Session-Base-Authentication: Code released under MIT License
  • Slim3-Skeleton: Added into LICENSE file

About

Slim3 Session-Based Authentication Skeleton

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published