Sorry just noticed a mistake, the database field for e-mail is named
"email" NOT "e-mail" as originally posted.

On Jul 17, 3:31 pm, Felix <fe...@felixfennell.co.uk> wrote:
> Hi,
>
> I'm trying to add the Auth component to my app,
>
> I'm using a custom database/model called accounts (database/table:
> accounts, model: Account).
>
> The database uses the fields;
>
> = e-mail (acts as username)
> = password
> = ( ... other non-important fields)
>
> I've configured the app controller as such;
>
> ==
>
> <?php
> class AppController extends Controller {
>
>     var $components = array('Auth','Session');
>
>     function beforeFilter() {
>        parent::beforefilter();
>        //configure AUTH component
>        $this->Auth->userModel = 'Account';
>        $this->Auth->loginAction = '/Accounts/login';
>        $this->Auth->fields =
> array('username'=>'email','password'=>'password');
>        $this->Auth->allow('*');
>        $this->Auth->userScope = array('Account.status' => 'normal');
>        $this->Auth->loginError = 'Invalid login details - please try
> again / reset password';
>        $this->Auth->authError = 'You must be logged in to visit -
> please login / register';
>     }}
>
> ?>
>
> ==
>
> In the accounts controller I've got;
>
> ==
>
> <?php
>
> class AccountsController extends AppController {
>     var $name = 'Accounts';
>
>     function beforeFilter() {
>        parent::beforeFilter();
>        $this->Auth->deny('index');
>     }
>
>     function login() {
>     }
>
>     function logout() {
>         $this->redirect($this->Auth->logout());
>     }
>
> }
>
> ?>
>
> ==
>
> And finally made the login view
>
> ==
>
> <?php echo $form->create('Account', array('action' => 'login')); ?>
>         <fieldset>
>         <legend><?php __('Login'); ?></legend>
>         <?php
>         echo $this->Form->input('email', array('div' => 'v input',
> 'label' => array('text' => 'E-mail', 'class' => 'label')));
>         echo $this->Form->input('password', array('div' => 'v input',
> 'label' => array('text' => 'Password', 'class' => 'label')));
>         ?>
>         </fieldset>
> <?php echo $this->Form->end(array('label' => 'Login', 'div' =>
> 'span-2'));?>
>
> ==
>
> The problem I have is, if I visit "example.com/Accounts/" I get sent
> to "example.com/Accounts/login" as expected complete with error
> message, this is fine.
>
> However when I login I end up back at "example.com/accounts/login".
> Every time I login I get sent back to this action, there is no error
> message so I assume it is correctly checking the database or I'd get
> an ugly php error, and cake doesn't produce an auth error.
>
> So I thought either the login is working and for some reason always
> redirects back to the login page, or the login is nether actually
> being done.
>
> In regards to the '$this->Auth->fields =
> array('username'=>'email','password'=>'password');' bit in the app
> controller I'm unsure as to what I then use in the login form, I've
> tried using "email" and "username" in the login view but it makes no
> difference.
>
> Does anybody know why this is happening or how I can fix it? I found
> the cake documentation a little light passed the setting up the
> database part, and couldn't find any guides that dealt with
> straightforward authentication, they all involve using ACL and or some
> other permissions based system on top of auth.
>
> Anyway if anyone has any advice it would be appreciated,
>
> thanks, Felix.

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en

Reply via email to