Problems with Auth in CakePHP - php

I've been using CakePHP for some time now. But I still fail to solve some issues on my own.
Its been difficult to understand how Cake Auth works but in these past few weeks I've managed to work with it.
Now to my issue:
I have 2 separate tables(Say for Admin Users and Normal Users). Both have different Controllers (Lets say they are AdminsController and UsersController).
Now I have completed Users module without any trouble. Users login and Admin Login are different views. As I dont want any normal User to be able to get their hands on Admin login page I've kept it separate from normal user login.
Users login works fine with Auth. But now I want to use another Auth for AdminController for some reason I am unable to make use the second Auth from AdminController and control automatically transfers to the Users Login
It would be great if someone could point in the correct direction. Please!
Thank You. In advance!!
P.S : I've also tried using Auth->userModel

Sorry everyone I was using Auth->userModel slightly wrong way.
I was adding it to my Admin Controller but not in User Controller so if you came here looking for an answer please use
$this->Auth->userModel="User";
in every controller in beforeFilter()
enjoy.......

Related

Laravel 5 rydurham/sentinal: post-login, redirect based on group membership

I have a Laravel 5.1 app using Sentinal for security. Right now we're just using the two stock groups, Users and Admins. Recently I invited a colleague to start testing my app, so I created a user for him. I forgot to add him to the Admins group. When he logged on in infinite redirect loop started because the authentication redirect sends users to a route called home, but you can't load home if you aren't in Admins, and get redirected back to login. Which redirects you back to home.
This is a business rule, we only want Admins using the part of the app that they need to authenticate to, but we'd like to do something friendlier than sending a 403 if you aren't an Admin. I would like to send Authenticated Users to a specific route, or even just redirect them to a static page.
I think I've almost worn out Google trying to get a clue about how to do this. Seems like this should be easy-peasy. I could start hacking the vendor code, but I can't believe that there isn't a more graceful way to do this.
Sorry if this is a dumb question. I'm fairly new to Laravel.
OK folks, I got this working. I wrote a piece of middleware called RedirectIfNotAdmin.
I couldn't find a Sentry or Guard property/method that could tell me about group membership, so I made plain ol' eloquent models for my users and groups tables. I created a many-to-many between those models. In my middleware I use Sentry to get a user id, with that I instantiate one of my own User models. In my User model I implemented a method isAdmin() which gets the groups for the User and returns true if one of them is 'Admins'.
If that isAdmin() method returns false, I redirect to a page that explains that the user doesn't have permissions.
Quite a bit more elaborate solution than what I expected I would need to write. I really thought rydurham/sentinal would have this pretty much solved. Maybe Sentinal does have a cleaner solution and I'm too dense to find it. If anybody would like to comment on a better way to solve this, I'm all ears.

How to implement SabreDav/CalDav in CakePHP 3.0?

I'm trying to implement CalDav in CakePHP 3.0 and I'm new to both of them. I've created a Customer portal and want that every single user has access to his appointments.
I followed the tutorial http://sabre.io/dav/caldav/, but when I try to run mypage/calendarserver.php/ (which i've located in webroot), it only appears my own created login page (it should display a login from sabredav).
The real problem is: when I try to create for example: "mypage/calendarserver.php/principals" Cake tells me that the principals controller is missing. I don't want to use any controller of Cake when I access this url. Does somebody know how to avoid calling the controller of Cake?
Thanks for your help.

Codeigniter - How to achieve different member areas within a site? Tank_Auth

I have built an app using codeigniter which has 3 different member groups
Admininstrators - Who login to a dashboard and have CRUD facilities to Add/Edit/Delete Events, shows and artists
Clients - Who Login from the front end and see all the items that the admin have added via the back end.
Media Partners - Who Login from the front-end and see certain parts of what the client can see but not all things.
I have integrated the Tank_Auth Library for the Clients section which all works fine. What I would like to achieve though is for the administrator to be able to login to a seperate admin area and the media partners to be able to login to a seperate area too.
What is the best way to approach this?
Do I need to create sepearate dashboard controllers for each userbase and duplicate the Tank_Auth controller 3 times and tweak this?
Ideally The Admin users also need to be able to add news users and login to all 3 seperate areas?
Has anybody achieved such a solution before, If so how did you go about it? perhaps tank auth isn't the correct approach?
Any input would be appreciated.
Thanks Dan
I am using CI, but haven't used Tank_Auth, I have my auth class and in every function I have the following method called: $this->auth->accessMap(get_class($this),__FUNCTION__);
In auth class:
public function accessMap($controller_name,$function_name)
{
if ($this->perms_array[$controller_name][$function_name])
return true;
else $this->redir();
}
I have permissions array in config:
$config['user_perms']['className']['method1'] = array($config['user_types']['admin']);
$config['user_perms']['className']['method2'] = array($config['user_types']['admin'],$config['user_types']['user']);
Like this you can specify for each method which user has permission to use it.
I hope this will help.
I can't find the thread on the CI forums because I can't seem to login to their website right now, however do a search for 'zend_acl in codeigniter'. Alternatively there is this blog post about how to implement it, but it is slightly dated.
ACL stands for Access Control List, it will allow you to setup various permissions for different types of users. Zend has one of the best implementations of ACL in my opinion.
More information about ACL's can be found on zend's website.
Absence of user group is a pain when using tank_auth if we have multiple user groups. I ran into this issue recently. Here is the solution posted in CI forms.
Using tank_auth for both front end user registration and login and back end admin login

Admin section in CakePHP

I'm having a hard time understanding how the CakePHP admin system works.
Should all controllers who has an action which requires login include AuthComponent or just the one who handles the login/logout?
Let's say I want to protect the add action of a controller. First I create admin_add() in the controller and then in the beforeFilter() method I check if $this->Session->check('Auth.User') is set a redirect based on this? Turns out it was better to just controll this with $this->Auth->allow()
What is the easiest way to return to the URL the user was trying to access? Is there a better way than setting a session variable? Turns out it does this automagically :)
If someone has a good tutorial for this I would happily read it :)
I've already read this tutorial but I found it to be a little to basic and the CakePHP-docs are not that great on this topic either.
There is no Cake admin system as such. There is Authentication component and there is Access Control List component. You can use only Authentication component if you wish or you can use both of them. If you want to create your admin system from scratch follow this tutorial. Or you can try already created admin panel - PoundCake Control Panel.
we have created an admin system for cakePHP, works similar to the scaffolding but it's configurable and ready to deploy, check it at http://browniephp.org
You can learn a lot from others codes, specially something like CakePHP Admin plugin at: https://github.com/Maldicore/Admin

mvc procedure question

I am borrowing some codeigniter authentication library and try to integrate it with my mvc version.
My version initiates breadcrums in the basecontroller and every module has it's own
controller that extends it.
What I want to know is if I am submitting my login form, then my submit action
will be /controller/function.
But, I don't want the function to appear in the breadcrumbs, how is this normally done.
As I am writing this, I am thinking that I can run all the logic threw the default
index function.
On the other hand, you want to be able to call on functions directly.
The question is how this is normally done in an mvc architecture
Could someone give me some feedback on this, please.
thanks, Richard
Once you authenticate are you redirecting the user to where they were previously or the index page on the website?
Usually the login controller doesn't actually have a view, it just authenticates and forwards you to either the login form if you are not authenticated, or a logged in page if the person is authenticated.

Categories