Reputation: 1564
I am trying to write a condition that will check for a specific parameter and the user credentials. If the user does not have one of two credentials and passes the correct parameter, they will get forwarded to a secure login screen.
This is what I did have that worked:
if ($request->getParameter('profile_type') == 'foo' && !$this->getUser()->isAdmin()) {
return $this->redirect('sfGuardAuth/secure');
}
But I have added a new user group so I need something like this:
if ($request->getParameter('profile_type') == 'foo' && (!$this->getUser()->isAdmin() || !$this->getUser()->isFaculty()) {
return $this->redirect('sfGuardAuth/secure');
}
So if you are not admin OR faculty, you get the redirect.
Is this a syntax or logic issue?
UPDATE
This is working, but it seems wrong logically
if (($request->getParameter('profile_type') == 'foo') && (!$this->getUser()->isAdmin() && !$this->getUser()->isFaculty())) {
return $this->redirect('sfGuardAuth/secure');
}
Upvotes: 0
Views: 248
Reputation: 1564
Just to answer the question, this is what I got to work:
if (($request->getParameter('profile_type') == 'foo') && (!$this->getUser()->isAdmin() && !$this->getUser()->isFaculty())) {
return $this->redirect('sfGuardAuth/secure');
}
I am not sure how the OR/AND operator is working to get the desired result, but it works, so that is an ok compromise.
Upvotes: 0
Reputation: 34107
(!$this->getUser()->isAdmin() || !$this->getUser()->isFaculty())
should be
!($this->getUser()->isAdmin() || $this->getUser()->isFaculty())
Update, with more explanation: you want to redirect the user if both isAdmin
and isFaculty
return false, and not redirect if either is yes.
If both are false:
!(false || false)
== !false
== true
=> redirect
!(true || false)
== !true
== false
=> no redirect
Upvotes: 1