2017 © Pedro Peláez
 

project slim-born

Slim Framework 3 skeleton application has authentication.

image

havenshen/slim-born

Slim Framework 3 skeleton application has authentication.

  • Tuesday, December 12, 2017
  • by HavenShen
  • Repository
  • 23 Watchers
  • 134 Stars
  • 501 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 29 Forks
  • 3 Open issues
  • 8 Versions
  • 10 % Grown

The README.md

slim-born

Scrutinizer Code Quality Build Status Code Coverage Build Status Latest Stable Version Latest Unstable Version Latest Stable Version Total Downloads License FOSSA Status, (*1)

Slim Framework 3 or 4 skeleton application has authentication MVC construction., (*2)

The user authentication has been achieved, there is a need to install and use., (*3)

Installation

For Slim 3

composer create-project "havenshen/slim-born v1.0.6" [my-app]

For Slim 4

composer create-project "havenshen/slim-born 2.0" [my-app]

.env

Copy file .env.example to .env, (*4)

DB_DRIVER=mysql
DB_HOST=localhost
DB_DATABASE=slimborn
DB_USERNAME=root
DB_PASSWORD=
DB_PORT=3306

Router

This is a Slim Framework Router. Reference - Slim Router, (*5)

<?php

$app->get('/', 'HomeController:index')->setName('home');

$app->group('', function () {
    $this->get('/auth/signup', 'AuthController:getSignUp')->setName('auth.signup');
    $this->post('/auth/signup', 'AuthController:postSignUp');

    $this->get('/auth/signin', 'AuthController:getSignIn')->setName('auth.signin');
    $this->post('/auth/signin', 'AuthController:postSignIn');
})->add(new GuestMiddleware($container));

Controller

Use Slim Framework Twig View. Reference - Twig-View, (*6)

<?php

namespace App\Controllers;

class HomeController extends Controller
{
    public function index($request, $response)
    {
        return $this->view->render($response, 'home.twig');
    }
}

Model

Use Laravel PHP Framework Eloquent. Reference - illuminate/database, (*7)

<?php

namespace App\Models;
use Illuminate\Database\Eloquent\Model;

class User extends Model
{
    protected $table = 'users';

    protected $fillable = [
        'email',
        'name',
        'password',
    ];

    public function setPassword($password)
    {
        $this->update([
            'password' => password_hash($password, PASSWORD_DEFAULT)
        ]);
    }
}

Middleware

<?php

namespace App\Middleware;

class AuthMiddleware extends Middleware
{
    public function __invoke($request, $response, $next)
    {
        if(! $this->container->auth->check()) {
            $this->container->flash->addMessage('error', 'Please sign in before doing that');
            return $response->withRedirect($this->container->router->pathFor('auth.signin'));
        }

        $response = $next($request, $response);

        return $response;
    }
}

Validation

Use the most awesome validation engine ever created for PHP. Reference - Respect/Validation, (*8)

<?php

namespace App\Controllers\Auth;
use App\Models\User;
use App\Controllers\Controller;
use Respect\Validation\Validator as v;

class AuthController extends Controller
{
    public function postSignUp($request, $response)
    {
        $validation = $this->validator->validate($request, [
            'email' => v::noWhitespace()->notEmpty()->email()->emailAvailable(),
            'name' => v::noWhitespace()->notEmpty()->alpha(),
            'password' => v::noWhitespace()->notEmpty(),
        ]);

        if ($validation->failed()) {
            return $response->withRedirect($this->router->pathFor('auth.signup'));
        }

        //  todo someting
    }
}

More basic functions

reference slim official documents - Slim Framework, (*9)

Use Packages

Look Feel

slimborn look feel, (*10)

Directory Structure

|-- slim-born
    |-- app
        |-- Auth
        |-- Controllers
        |-- Middleware
        |-- Models
        |-- Validation
        |-- Routes.php
    |-- bootstrap
        |-- app.php
    |-- public
    |-- resources
    ....

Testing

bash $ phpunit, (*11)

Contributing

Feel free to submit any minor enhancements, the goal here is to keep this as simple (yet as practical) as possible., (*12)

License

The MIT License (MIT). Please see License File for more information., (*13)

FOSSA Status, (*14)

The Versions

12/12 2017

dev-master

9999999-dev https://github.com/HavenShen/slim-born

Slim Framework 3 skeleton application has authentication.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar HavenShen

authentication skeleton slim slim 3

12/12 2017

v1.0.6

1.0.6.0 https://github.com/HavenShen/slim-born

Slim Framework 3 skeleton application has authentication.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar HavenShen

authentication skeleton slim slim 3

31/03 2017
22/03 2017
22/03 2017

v1.0.3

1.0.3.0 https://github.com/HavenShen/slim-born

Slim Framework 3 skeleton application has authentication.

  Sources   Download

MIT

The Requires

 

by Avatar HavenShen

authentication skeleton slim slim 3

15/06 2016

v1.0.2

1.0.2.0 https://github.com/HavenShen/slim-born

Slim Framework 3 skeleton application has authentication.

  Sources   Download

MIT

The Requires

 

by Avatar HavenShen

authentication skeleton slim slim 3

10/05 2016

v1.0.1

1.0.1.0 https://github.com/HavenShen/slim-born

Slim Framework 3 skeleton application has authentication.

  Sources   Download

MIT

The Requires

 

by Avatar HavenShen

authentication skeleton slim slim 3

19/04 2016

v1.0.0

1.0.0.0 https://github.com/HavenShen/slim-born

Slim Framework 3 skeleton application has authentication.

  Sources   Download

MIT

The Requires

 

by Avatar HavenShen

authentication skeleton slim slim 3