C
C
Chvalov2014-11-02 04:55:00
PHP
Chvalov, 2014-11-02 04:55:00

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('/');
    
  }
}

There is a Siginin.php model :
<?php
  class Signin extends DB\SQL\Mapper {
    public function __construct(DB\SQL $db) {
      parent::__construct($db,'users');
    }
}

There is a router
GET /auth=UserController->auth
POST /auth=UserController->login
GET /logout=UserController->logout

Well, the form:
<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>

What is wrong with me? When you drink, log in throws you on the same page, but the redirect should hit.
Or maybe someone has an example of authorization on Fat Free when the passwords in the database are in MD5

Answer the question

In order to leave comments, you need to log in

2 answer(s)
C
Chvalov, 2014-11-03
@Chvalov

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('/');
    
  }

#
# artur #, 2014-11-02
@passshift

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('/');

1 is authorization success? In this case, redirect $this->f3->reroute ( ' /here ' ) ;
And the slash before Auth is still not clear:
Is this a "feature" of the framework?
Maybe it will be off topic, but if you are new to working with frameworks and are just starting to master the Fat free Framework, then I can advise 2 good substitutes:
kohanaframework.org - a meager Russian-speaking community, BUT beautiful, understandable and logical code without a ton of garbage, there is a couple of Russian-language unofficial guides that will help you get a successful start.
laravel.ru - an excellent Russian-language guide, also good in all respects.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question