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., (*1)
Why I created this project?, (*2)
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!, (*3)
Table of Content
Getting Started
Prerequisites
You have to install Composer before running the installation command.
Click here to see more information about Composer!, (*4)
Installing
Navigate into your folder and issuing this command into a command line, (*5)
`$ composer create-project --no-interaction samuelr/slim3-auth myapp-name`
Run Project
$ cd myapp-name
$ sudo php -S 0.0.0.0:8888 -t public public/index.php
- Browse to http://localhost:8888
If you have any problem make sure that you launched this command with sudo!, (*6)
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, (*7)
Authors
- Samuel Roberto - Initial project
See also the list of contributors who participated in this project., (*8)
Mind Mapping
You can find a full mind mapping for this project here:
* Routes' mind-mapping
* Structure's mind-mapping, (*9)
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:, (*10)
-- 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:, (*11)
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., (*12)
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., (*13)
Contributing
See the list of contributors who participated in this project., (*14)
Licenses
-
Slim3-Session-Base-Authentication
: Code released under MIT License
-
Slim3-Skeleton
: Added into LICENSE file