Hello everybody,
so I hope I've identified the problem now, but no reason. I've to
Controllers which extends my own AppController. That has the following
code:
class AppController extends Controller {
var $components = array('Auth', 'Session');
public function beforeFilter() {
parent::beforeFilter();
$this->__assignDataUrlToLayout();
if(isset($this->Auth)) {
$this->__setAuthConfig();
}
}
private function __assignDataUrlToLayout() {
$this->set('data_url', $this->request->webroot . '' .
$this->name .
'/' . $this->action);
}
private function __setAuthConfig() {
$this->Auth->userScope = array('User.enabled' => true);
$this->Auth->loginRedirect = array('controller' => 'index',
'action'
=> 'index');
$this->Auth->loginAction = array('controller' => 'users',
'action'
=> 'login');
$this->Auth->logoutRedirect =
array(Configure::read('Routing.admin')
=> false, 'controller' => 'Users', 'action' => 'login');
$this->Auth->allow(array('*'));
var_dump($this->Auth->user());
}
}
Both controllers don't have any var $components-statements. In the
first controller the dump of test-action in:
class IndexController extends AppController {
public function index() {
}
public function test() {
$this->set('user', $this->Auth->user());
}
}
has a result in the other controller not. What can be the reason?
On 18 Nov., 14:02, Gerrit <[email protected]> wrote:
> Now I know, that my user is not authorized in this controller. In
> every other controller he passed the auth. Interesting is, that all
> auth config is defined in AppController.
>
> On 18 Nov., 13:12, Gerrit <[email protected]> wrote:
>
>
>
>
>
>
>
> > Thank you, now it works. But there is one controller where no actions
> > are displayed, only a white page. When I add $this->allow('*'); then
> > everything in this controller is working. Do you know why? This is
> > only one controller...
>
> > On 18 Nov., 11:41, Jeremy Burns | Class Outfit
>
> > <[email protected]> wrote:
> > > This is Cake 2.0? Then the automagicness has been removed from the login
> > > method and you need to code it.
>
> > >http://book2.cakephp.org/en/core-libraries/components/authentication....
>
> > > Jeremy Burns
> > > Class Outfit
>
> > > Tel: +44 (0) 208 123 3822
> > > Mob: +44 (0) 7973 481949
> > > Skype: jeremy_burnshttp://www.classoutfit.com
>
> > > Jeremy Burns
> > > Class Outfit
>
> > >http://www.classoutfit.com
>
> > > On 18 Nov 2011, at 10:31, Gerrit wrote:
>
> > > > No Problem.
>
> > > > class UsersController extends AppController {
>
> > > > var $components = array('Auth', 'Session');
>
> > > > public function beforeFilter() {
> > > > $this->Auth->allow(array('login'));
>
> > > > parent::beforeFilter();
> > > > }
>
> > > > public function login() {
>
> > > > }
>
> > > > public function logout() {
> > > > $this->Auth->logout();
> > > > }
>
> > > > /**
> > > > * index method
> > > > *
> > > > * @return void
> > > > */
> > > > public function index() {
> > > > $this->User->recursive = 0;
> > > > $this->set('users', $this->paginate());
> > > > }
>
> > > > /**
> > > > * view method
> > > > *
> > > > * @param string $id
> > > > * @return void
> > > > */
> > > > public function view($id = null) {
> > > > $this->User->id = $id;
> > > > if (!$this->User->exists()) {
> > > > throw new NotFoundException(__('Invalid user'));
> > > > }
> > > > $this->set('user', $this->User->read(null, $id));
> > > > }
>
> > > > /**
> > > > * add method
> > > > *
> > > > * @return void
> > > > */
> > > > public function add() {
> > > > if ($this->request->is('post')) {
> > > > $this->User->create();
> > > > if ($this->User->save($this->request->data)) {
> > > > $this->Session->setFlash(__('The user has
> > > > been saved'));
> > > > $this->redirect(array('action' => 'index'));
> > > > } else {
> > > > $this->Session->setFlash(__('The user could
> > > > not be saved. Please,
> > > > try again.'));
> > > > }
> > > > }
> > > > }
>
> > > > /**
> > > > * edit method
> > > > *
> > > > * @param string $id
> > > > * @return void
> > > > */
> > > > public function edit($id = null) {
> > > > $this->User->id = $id;
> > > > if (!$this->User->exists()) {
> > > > throw new NotFoundException(__('Invalid user'));
> > > > }
> > > > if ($this->request->is('post') || $this->request->is('put'))
> > > > {
> > > > if ($this->User->save($this->request->data)) {
> > > > $this->Session->setFlash(__('The user has
> > > > been saved'));
> > > > $this->redirect(array('action' => 'index'));
> > > > } else {
> > > > $this->Session->setFlash(__('The user could
> > > > not be saved. Please,
> > > > try again.'));
> > > > }
> > > > } else {
> > > > $this->request->data = $this->User->read(null, $id);
> > > > }
> > > > }
>
> > > > /**
> > > > * delete method
> > > > *
> > > > * @param string $id
> > > > * @return void
> > > > */
> > > > public function delete($id = null) {
> > > > if (!$this->request->is('post')) {
> > > > throw new MethodNotAllowedException();
> > > > }
> > > > $this->User->id = $id;
> > > > if (!$this->User->exists()) {
> > > > throw new NotFoundException(__('Invalid user'));
> > > > }
> > > > if ($this->User->delete()) {
> > > > $this->Session->setFlash(__('User deleted'));
> > > > $this->redirect(array('action'=>'index'));
> > > > }
> > > > $this->Session->setFlash(__('User was not deleted'));
> > > > $this->redirect(array('action' => 'index'));
> > > > }
> > > > }
>
> > > > login.ctp
> > > > <h2>Login</h2>
> > > > <div data-role="fieldcontain">
> > > > <?php echo $this->Form->create('User', array('action' => 'login')); ?
>
> > > > <?php echo $this->Form->input('username', array('label' =>
> > > > __('Benutzername'))); ?>
>
> > > > <?php echo $this->Form->input('password', array('label' =>
> > > > __('Passwort'))); ?>
>
> > > > <?php echo $this->Form->end(__('Login')); ?>
>
> > > > </div>
>
> > > > On 18 Nov., 10:48, Jeremy Burns | Class Outfit
> > > > <[email protected]> wrote:
> > > >> Fancy showing some code or shall we just guess?
>
> > > >> Jeremy Burns
> > > >> Class Outfit
>
> > > >>http://www.classoutfit.com
>
> > > >> On 18 Nov 2011, at 09:44, Gerrit wrote:
>
> > > >>> Hello everybody,
>
> > > >>> I've added the Auth-component, added the login-action, created a model
> > > >>> and created the login-view. And I've also created my user in the
> > > >>> Users-
> > > >>> table with my hashed-password. Now the login don't work. When I click
> > > >>> the login-button I receive the login-page with no message and no
> > > >>> executed sql-statement.
>
> > > >>> What could be the reason?
>
> > > >>> Thanks!
>
> > > >>> --
> > > >>> Our newest site for the community: CakePHP Video
> > > >>> Tutorialshttp://tv.cakephp.org
> > > >>> Check out the new CakePHP Questions
> > > >>> sitehttp://ask.cakephp.organdhelpotherswith their CakePHP related
> > > >>> questions.
>
> > > >>> To unsubscribe from this group, send email to
> > > >>> [email protected] For more options, visit this
> > > >>> group athttp://groups.google.com/group/cake-php
>
> > > > --
> > > > Our newest site for the community: CakePHP Video
> > > > Tutorialshttp://tv.cakephp.org
> > > > Check out the new CakePHP Questions
> > > > sitehttp://ask.cakephp.organdhelpothers with their CakePHP related
> > > > questions.
>
> > > > To unsubscribe from this group, send email to
> > > > [email protected] For more options, visit this
> > > > group athttp://groups.google.com/group/cake-php
--
Our newest site for the community: CakePHP Video Tutorials
http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others
with their CakePHP related questions.
To unsubscribe from this group, send email to
[email protected] For more options, visit this group at
http://groups.google.com/group/cake-php