Commit fddd8566 authored by Bastien Durel's avatar Bastien Durel
Browse files

admin page with login

parent 53707154
<?php
class BcryptAuth extends \Auth {
function login($id,$pw,$realm=NULL) {
if (method_exists($this, '_hash'.$this->storage)) {
$hash = $this->{'_hash'.$this->storage}($id); // get hash from storage
return password_verify($pw, $hash);
}
else
return parent::login($id,$pw,$realm);
}
protected function _hashsql($id) {
$user = call_user_func_array(
[$this->mapper,'load'],
[
[
$this->args['id'].'=?',
$id
]
]
);
if ($user)
return $user->{$this->args['pw']};
else
return '';
}
function __construct($storage,array $args=NULL) {
parent::__construct($storage,$args);
}
}
<?php
echo 'TODO';
require 'vendor/autoload.php';
require 'pdo.config.php'; # provides $dbdsn, $dbuser, $dbpass
$f3 = \Base::instance();
$db = new DB\SQL($dbdsn, $dbuser, $dbpass);
$f3->set('DB', $db);
$user = new \DB\SQL\Mapper($db, 'users');
$auth = new BcryptAuth($user, array('id'=>'user_id', 'pw'=>'password'));
$f3->set('auth', $auth);
$f3->route(
'GET /admin',
function($f3) {
if (!$f3->get('auth')->basic())
die();
echo 'TODO';
}
);
$f3->run();
......@@ -4,9 +4,40 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically"
],
"hash": "326dd0f14ee56e2f317987b03c879002",
"content-hash": "bf814b9c47b9d85162e4a9dade2434f6",
"hash": "03588c1f9c549ce8e083bc9ac03c1a14",
"content-hash": "b0b411d65d0270b73ec2403fd0ecff10",
"packages": [
{
"name": "bcosca/fatfree",
"version": "3.6.4",
"source": {
"type": "git",
"url": "https://github.com/bcosca/fatfree.git",
"reference": "dee4d73918a42076d5ac7db64d6d39706c7f328a"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/bcosca/fatfree/zipball/dee4d73918a42076d5ac7db64d6d39706c7f328a",
"reference": "dee4d73918a42076d5ac7db64d6d39706c7f328a",
"shasum": ""
},
"require": {
"php": ">=5.4"
},
"type": "library",
"autoload": {
"files": [
"lib/base.php"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"GPL-3.0"
],
"description": "A powerful yet easy-to-use PHP micro-framework designed to help you build dynamic and robust Web applications - fast!",
"homepage": "http://fatfreeframework.com/",
"time": "2018-04-19 17:23:25"
},
{
"name": "justinrainbow/json-schema",
"version": "5.2.7",
......
......@@ -2,7 +2,7 @@
if ($_SERVER['REQUEST_METHOD'] == 'GET') {
http_response_code(301);
header('Location: admin.php');
header('Location: admin');
die();
}
if ($_SERVER['REQUEST_METHOD'] != 'POST') {
......
<?php // -*- php -*-
$user = 'foo';
$pass = 'bar';
$db = new PDO('mysql:host=localhost;dbname=reports;charset=UTF8', $user, $pass);
$dbuser = 'foo';
$dbpass = 'bar';
$dbdsn = 'mysql:host=localhost;dbname=reports;charset=UTF8';
$db = new PDO($dbdsn, $dbuser, $dbpass);
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment