Skip to content

Instantly share code, notes, and snippets.

Avatar

Jordi Bassagañas programarivm

View GitHub Profile
@programarivm
programarivm / index.php
Created Jul 12, 2020
wide-open CORS set up
View index.php
<?php
require realpath(dirname(__FILE__)) .'/../src/bootstrap.php';
header("Access-Control-Allow-Origin: *");
header('Access-Control-Allow-Methods: GET, POST');
header("Access-Control-Allow-Headers: DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range");
switch (true) {
case '/api/query' === $_SERVER['REQUEST_URI'] && $_SERVER['REQUEST_METHOD'] === 'POST':
@programarivm
programarivm / default.conf
Created Jul 12, 2020
wide-open CORS set up
View default.conf
server {
listen 443 ssl;
server_name pgn-chess-data.local;
ssl_certificate /etc/nginx/ssl/pgn-chess-data.local.crt;
ssl_certificate_key /etc/nginx/ssl/pgn-chess-data.local.key;
ssl_ciphers EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH;
ssl_protocols TLSv1.1 TLSv1.2;
root /usr/share/nginx/pgn-chess-data/public;
View Session.js
import Cookies from 'js-cookie';
const name = 'session';
export default class Session {
static get() {
if (Cookies.get(name)) {
return JSON.parse(Cookies.get(name));
}
return {
View AuthController.php
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class AuthController extends Controller
{
const COOKIE_ACCESS_TOKEN = 'access_token';
const COOKIE_SESSION = 'session';
View StoreRestaurant.php
<?php
namespace App\Http\Requests;
class StoreRestaurant extends AbstractAuthorizedFormRequest
{
/**
* Get the validation rules that apply to the request.
*
* @return array
View AbstractAuthorizedFormRequest.php
<?php
namespace App\Http\Requests;
use App\Acl;
use Illuminate\Foundation\Http\FormRequest;
abstract class AbstractAuthorizedFormRequest extends FormRequest
{
/**
@programarivm
programarivm / api.php
Created Nov 5, 2019
The ACL middleware is ready to be used in the API's routes.
View api.php
<?php
use Illuminate\Http\Request;
Route::post('/auth/login', 'AuthController@login');
Route::post('/auth/logout', 'AuthController@logout')->middleware('jwt.authorizer');
Route::get('restaurants', 'RestaurantController@index')->middleware('jwt.authorizer', 'acl');
Route::get('restaurants/{restaurant}', 'RestaurantController@show')->middleware('jwt.authorizer', 'acl');
Route::post('restaurants', 'RestaurantController@store')->middleware('jwt.authorizer', 'acl');
@programarivm
programarivm / Kernel.php
Last active Nov 5, 2019
Adding the new middleware to the $routeMiddleware variable
View Kernel.php
<?php
// ...
/**
* The application's route middleware.
*
* These middleware may be assigned to groups or used individually.
*
* @var array
*/
@programarivm
programarivm / Acl.php
Last active Dec 28, 2019
ACL middleware
View Acl.php
<?php
namespace App\Http\Middleware;
use Closure;
class Acl
{
/**
* Handle an incoming request.
@programarivm
programarivm / gist:530e8f4f74c78d68a5e6c57df7cdc988
Created Nov 5, 2019
The acls table is seeded with the permissions data
View gist:530e8f4f74c78d68a5e6c57df7cdc988
mysql> select * from acls;
+----+-----------------------------+-------------+---------------------+---------------------+
| id | resource | role | created_at | updated_at |
+----+-----------------------------+-------------+---------------------+---------------------+
| 1 | ReviewController@store | ROLE_BASIC | 2019-11-04 21:53:18 | 2019-11-04 21:53:18 |
| 2 | RestaurantController@index | ROLE_EDITOR | 2019-11-04 21:53:18 | 2019-11-04 21:53:18 |
| 3 | RestaurantController@show | ROLE_EDITOR | 2019-11-04 21:53:18 | 2019-11-04 21:53:18 |
| 4 | RestaurantController@update | ROLE_EDITOR | 2019-11-04 21:53:18 | 2019-11-04 21:53:18 |
| 5 | RestaurantController@delete | ROLE_EDITOR | 2019-11-04 21:53:18 | 2019-11-04 21:53:18 |
| 6 | ReviewController@delete | ROLE_EDITOR | 2019-11-04 21:53:18 | 2019-11-04 21:53:18 |