I am setting for the first time the Auth component on my site, and everything seems to work fine except when I try to access a restricted page. Instead of being redirected to http://localhost/MySite/users/login, I get redirected to http://localhost/MySite/users/users/login, the controller name is repeated on the url. How can this issue be fixed?
I am using CakePhp 2.4.4
AppController
class AppController extends Controller {
public $components = array('DebugKit.Toolbar',
'Session','Auth' => array(
'loginRedirect'=> array(
'controller' => 'admins',
'action' => 'admin_index'
),
'logoutRedirect' => array(
'controller' => 'users',
'action' => 'login'
),
'loginAction' => array(
'controller' => 'users',
'action' => 'login',
'plugin' => 'users'
),
'authError' => 'Não tem permissão para aceder a esta área. Por favor faça login.',
'authenticate' => array(
'Form' => array(
'fields' => array('username' => 'username', 'password' => 'password'
),
'userModel' => 'User'
)
),
'authorize' =>array('Controller'
)
)
);
public function beforeFilter(){
$this->Auth->allow('index','ShowImages','ShowShowbill','ShowVideos','ShowContactUs','contact','login','DisplayMusic','DisplayEntertainment','DisplayPromotion','DisplayStaff','DisplayEquipments');
}
In Auth component you need to add 'unauthorizedRedirect' otherwise Cake tries to redirect to /{app-directory} (this was giving me a headache yesterday).
public $components = array(
//your other components
'Auth' => array(
//your other options for Auth
'unauthorizedRedirect' => '/home'
)
);
This would direct any user trying to access a page they shouldn't be allowed on to 'yourDomain/home'.
Related
I've tried all the possible combination for modifying the default model for authentication in cakephp 2.5
actually my current appController is
class AppController extends Controller {
public $components = array(
'Session',
'Auth' => array(
'loginRedirect' => array(
'controller' => 'utente',
'action' => 'login'
),
'logoutRedirect' => array(
'controller' => 'pages',
'action' => 'display',
'home'
)
)
);
function beforeFilter() {
$this->Auth->fields = array(
'username' => 'email',
'password' => 'password'
);
$this->Auth->userModel = 'Utente';
}
}
I have also tried with this answers but going into /cakephp-master/ redirect me with no regret to users/login. why?
I have a site in cakephp 2.x where I want that a guest user (not logged in) can see same pages:
users/login
users/forgot_password
users/reset_password
I have AuthComponent that can't access my page. I can access to users/login but not to forgot_password and reset_password, if i try to ccess always redirect to the login page.
This is my AppController with AuthComponent:
public $components = array(
'Session',
'Auth' => array(
'loginAction' => array('controller'=>'users','action'=>'login', 'admin'=>false),
'logoutRedirect' => array('controller'=>'users','action'=>'login'),
'loginRedirect' => array('controller'=>'projects', 'action'=>'index'),
'authError' => 'Questa risorsa non sembra appartenere al tuo account, oppure non hai eseguito l\'accesso',
'autoRedirect' => false,
'authorize' => array(
'Controller',
'Actions' => array(
'actionPath' => 'controllers'
)
),
'authenticate' => array(
'Form' => array(
'fields' => array('username' => 'email')
)
)
)
);
In this case I can't access to forgot_password and reset_password.
But if I change it to this:
public $components = array(
'Session',
'Auth' => array(
'loginAction' => null,
'logoutRedirect' => array('controller'=>'users','action'=>'login'),
'loginRedirect' => array('controller'=>'projects', 'action'=>'index'),
'authError' => 'Questa risorsa non sembra appartenere al tuo account, oppure non hai eseguito l\'accesso',
'autoRedirect' => false,
'authorize' => array(
'Controller',
'Actions' => array(
'actionPath' => 'controllers'
)
),
'authenticate' => array(
'Form' => array(
'fields' => array('username' => 'email')
)
)
)
);
I have set null to loginAction in this case I can access to forgot_password and reset_password but page are blank without errors, body are empty. These page are simply html without query like this:
controller action
public function forgot_password(){
}
view
<div>
<p>RESTORE PASSWORD</p>
</div>
Someone can help me? Thanks
In your beforeFilter() callback, add $this->Auth->allow('forgot_password');
Api: AuthComponent:allow()
I am having a user table with an active field datatype enum(1,0) for my cake php application
I want to dis allow the inactive users from logging into my application. For this i added this code in my Appcontroller.php
public $components = array('Acl', 'Session',
'Auth' => array('authorize' => array('Controller'),
'loginRedirect' => array('controller' => 'users', 'action' => 'index'),
'logoutRedirect' => array('controller' => 'users', 'action' => 'login'),
'Form' => array('userModel' => 'User'),
'all' => array('scope' => array('User.active' => 1)))
);
My user model is User
But this is allowing the in active users also to login to the application.
What am i doing wrong?
Thanks
please check your array it is wrong assing
check below array and it will work for you
public $components = array(
'Auth' => array(
'loginAction' => array(
'controller' => 'users',
'action' => 'login'
),
'authError' => 'Je hebt geen toegang tot dit gedeelte',
'authenticate' => array(
'Form' => array(
'fields' => array('username' => 'email'),
'scope' => array('is_admin' => '1')
),
)
),
'Session'
);
Whenever I've dealt with enums in CakePHP, their value is always a string. Therefore I think the problem you're encountering is that 1 is not equal to '1'.
For your active field, try using the BOOLEAN datatype which is a synonym of TINYINT(1). You should then write in your Auth component configuration:
public $components = array('Acl', 'Session',
'Auth' => array('authorize' => array('Controller'),
'loginRedirect' => array('controller' => 'users', 'action' => 'index'),
'logoutRedirect' => array('controller' => 'users', 'action' => 'login'),
'Form' => array('userModel' => 'User'),
'all' => array('scope' => array('User.active' => true)))
);
Semantically, I feel this makes more sense.
Noob question!
I have a complete admin setup: login, authentication an so on, it's working.
So, now i need a new controller to another situation and then i create the controller named PressDownloadsController and the correct views to every action inside this new controller.
I also created the following route:
Router::connect('/pressdownloads', array('controller' => 'pressdownloads', 'action' => 'downloads'));
Inside the pressDownloads controller, there's some redirect between some actions.
When i try to open the url /pressdownloads/downloads or just /pressdownloads it just goes to admin controller and i need to login in before acess the pressdownloads area.
Why?
The Auth Settings inside UsersController (admin):
Ok. I get it.
So the auth settings:
public $components = array(
'Session',
'Auth' => array(
'loginAction' => array(
'controller' => 'users',
'action' => 'login',
'prefix' => 'admin',
),
'loginRedirect' => '/admin/events',
'logoutRedirect' => '/admin',
'authError' => 'Acesso negado',
'flash' => array(
'element' => 'admin/messages/error',
'key' => 'auth',
'params' => array()
),
'authorize' => array('Controller'),
'authenticate' => array(
'Form' => array(
'fields' => array('username' => 'email')
)
)
)
);
I recommend to check Auth component settings and how you split admin area from non-admin.
Also, you may specify in your routing not to use admin prefix like this:
Router::connect('/pressdownloads', array('controller' => 'pressdownloads', 'action' => 'downloads', 'admin' => false));
I believe you are going to that link after "Admin" has been enabled. Simply put you must be clicking the link from the pages served by admin.
Try adding additional parameter "admin" => false in your present route.
Router::connect('/pressdownloads',
array(
'controller' => 'pressdownloads',
'action' => 'downloads',
'admin' => false
)
);
I might hav askd question related to this earlier but not satisfied by answers and no answer is working.....My doubt is little different , i have two controllers
1.UsersController.
2.MembersController.
My doubt is the Auth component is working wonders for UsersControllers, but the Auth is not working for MembersController. In simple terms whenever i try to use Auth component for my MembersController, instead of redirecting to Members view. It is displaying UsersController pages....And when i delete the UsersController i get below error...
Error: UsersController could not be found.
Is there any connection between Auth and Users. How to set Auth component for my MembersController......
This is how i am using it....
public $components = array(
'Session',
'Auth' => array(
'loginRedirect' => array('controller' => 'members', 'action' => 'home'),
'logoutRedirect' => array('controller' => 'members', 'action' => 'index')
)
);
public function beforeFilter() {
$this->Auth->allow('index', 'view');
}
In your App Controller
class AppController extends Controller {
public $components = array(
'Auth' => array(
'authorize' => 'actions',
'actionPath' => 'controllers/',
'loginAction' => array(
'controller' => 'members',
'action' => 'login',
'plugin' => false,
'admin' => false,
),
),
);
}