Giter Site home page Giter Site logo

agdobrynin / slim-born Goto Github PK

View Code? Open in Web Editor NEW

This project forked from havenshen/slim-born

0.0 1.0 0.0 203 KB

Slim Framework 3 skeleton application has authentication MVC construction.

Home Page: https://slim-born.herokuapp.com/

License: MIT License

PHP 62.17% CSS 0.72% HTML 30.56% TSQL 6.55%

slim-born's Introduction

slim-born

Scrutinizer Code Quality Build Status Code Coverage Build Status Latest Stable Version Latest Unstable Version Latest Stable Version Total Downloads License

Slim Framework 3 skeleton application has authentication MVC construction.

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

Installation

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

.env

Copy file .env.example to .env

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

<?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

<?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

<?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

<?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

Use Packages

Look Feel

slimborn look feel

Directory Structure

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

Testing

$ phpunit

License

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

slim-born's People

Contributors

havenshen avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.