CakePHP 3 Authentication on Production -
i have followed pretty tutorial the cakephp website add authentication website (except not need roles on website, admin login). on machine whole authentication works , pages can access admin. have copied folder , database web hoster, there have problems logging in.
this code looks like:
in config/routes.php have:
router::prefix('admin', function($routes) { $routes->connect('/', ['controller'=>'users','action'=>'login']); $routes->fallbacks('inflectedroute'); });
in src/controller/admin/userscontroller.php
namespace app\controller\admin; use app\controller\appcontroller; use cake\event\event; class userscontroller extends appcontroller { public function beforefilter(event $event) { parent::beforefilter($event); $this->auth->allow(['logout']); } public function login(){ if ($this->request->is('post')) { $user = $this->auth->identify(); if ($user) { $this->auth->setuser($user); return $this->redirect($this->auth->redirecturl()); } $this->flash->error(__('please check username , password.')); } } }
the entity user contains method hashing:
protected function _setpassword($password) { return (new defaultpasswordhasher)->hash($password); }
finally, in controller/appcontroller.php have implemented following, should allow every logged-in user access pages.
class appcontroller extends controller { public function initialize() { parent::initialize(); $this->loadcomponent('flash'); $this->loadcomponent('auth', [ 'loginredirect' => [ 'controller' => 'requests', 'action' => 'index' ], 'logoutredirect' => [ 'prefix' => false, 'controller' => '/' ] ]); } public function beforefilter(event $event) { parent::beforefilter($event); if($this->request->session()->check('auth.user.id')) { $this->layout = 'admin'; } } public function isauthorized($user) { return true; } }
as said, works on local machine. however, on server, following error:
you not authorized access location.
i tried various php versions, make sure error not there. using printouts, see pass if($user)
check in login()
method. however, don't know how proceed , i'm pretty clueless possibly solutions. have installed cakephp in subdomain on webhoster - problem?
Comments
Post a Comment