Answer the question
In order to leave comments, you need to log in
Authorization does not work - Fat free Framework, what should I do?
There is a controller:
<?php
class Controller {
protected $f3;
protected $db;
function beforeroute() {
}
function afterroute() {
echo Template::instance()->render('client_layout.html');
}
function __construct() {
$f3=Base::instance();
$db=new DB\SQL(
$f3->get('db_host') . $f3->get('db_name'),
$f3->get('db_user'),
$f3->get('db_pass')
);
$this->f3=$f3;
$this->db=$db;
}
}
class UserController extends Controller {
public function index()
{
$this->f3->set('page_head','Главная');
$this->f3->set('view','client/index.html');
}
// Страница входа (Авторизации)
public function auth()
{
$this->f3->clear('SESSION');
$this->f3->set('page_head','Авторизация');
$this->f3->set('view','client/auth.html');
}
// Процесс авторизации
public function login()
{
$signin = new Signin($this->db);
$signin->set('login',$this->f3->get('post.login'));
$signin->set('password',md5($this->f3->get('post.password')));
$auth=new \Auth($signin, array('id'=>'login','pw'=>'password'));
if ($auth->login($this->f3->get('post.login'),md5($this->f3->get('post.password')))==1)
$this->f3->reroute('/');
}
}
<?php
class Signin extends DB\SQL\Mapper {
public function __construct(DB\SQL $db) {
parent::__construct($db,'users');
}
}
GET /auth=UserController->auth
POST /auth=UserController->login
GET /logout=UserController->logout
<form action="{{ @BASE.'/auth' }}" method="post" class="form-horizontal" role="form">
<fieldset>
<div class="clearfix">
<input type="text" id="login" name="login" class="input-block-level" placeholder="Username">
</div>
<div class="clearfix">
<input type="password" id="password" name="password" class="input-block-level" placeholder="Password">
</div>
<button type="submit" class="btn btn-primary">
Sign in
</button>
</fieldset>
</form>
Answer the question
In order to leave comments, you need to log in
The whole problem was that my "post" was written in lowercase, but I needed it in uppercase :)
// Процесс авторизации
public function login()
{
$signin = new Signin($this->db);
$signin->set('login',$this->f3->get('POST.login'));
$signin->set('password',md5($this->f3->get('POST.password')));
$auth=new \Auth($signin, array('id'=>'login','pw'=>'password'));
if ($auth->login($this->f3->get('POST.login'),md5($this->f3->get('POST.password')))==1)
$this->f3->reroute('/');
}
I am completely unfamiliar with this framework and the syntax is not fully understood, but it seems to me that the whole point is in these lines:
if ($auth->login($this->f3->get('post.login'),md5($this->f3->get('post.password')))==1)
$this->f3->reroute('/');
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question