Tuesday, January 29, 2013

Auth Login Redirect is not redirecting or encrypting user info

I'm using cakephp 2.3, and trying to use a table other than users(editors)
for user authentication. Using topics here, stackoverflow and the
documentation for reference, i've almost got it, just hung up on the login.
If I try to access anything, the app does display the login, however even
with correct credentials, it looks like it loads but doesn't move past the
login view. No error is displayed. And for some reason, any user(Editor in
my case) doesn't have an encrypted password in the DB. I've been at this for
a day and a half and don't know what to do at this point. The table fields
are the standard user fields just in a table named editors. and the login
view is standard. The code for the login/logout I used from the
documenation. Any suggestions? I would use Users, but another Cake 1.3 app
is using that table and i'm not sure how difficult it would be to use the
same table.(I tried but the user passwords weren't encrypted there
either..so it might be how i'm using auth?

References:

1.
http://stackoverflow.com/questions/9929129/cakephp-authentication-component-using-a-different-table-name-and-column-name

2.
http://stackoverflow.com/questions/6016044/cakephp-autentication-with-auth-table-other-than-user-problem

3. http://stackoverflow.com/questions/7258455/cakephp-login-redirect-problem

4.
http://book.cakephp.org/2.0/en/core-libraries/components/authentication.html#configuring-authentication-handlers

5.
http://book.cakephp.org/2.0/en/core-libraries/components/authentication.html#identifying-users-and-logging-them-in


AppController:

class AppController extends Controller {
public $components = array(
'Session',
'Security',
'Auth'=> array(
'loginAction' => array(
'controller' => 'editors',
'action' => 'login',
),
'authorize' => array('Controller'),
'authError' => 'You are not authorized to access that page.',
'authenticate' => array(
'Form'
)
)
);
//public $helpers = array('Form','Html','Session');

public function isAuthorized($user) {
return true;
}

public function beforeFilter() {
//$this->Auth->authenticate = ClassRegistry::init('Editor');
$this->Auth->loginAction =
array('controller'=>'editors','action'=>'login');
$this->Auth->loginRedirect =
array('controller'=>'drugs','action'=>'index');
$this->Auth->loginError = 'Incorrect Username/Password
Combination.';
$this->Auth->logoutRedirect =
array('controller'=>'editors','action'=>'login');
//$this->set('logged_in', $this->Auth->loggedIn());
//$this->set('current_user', $this->Auth->user());
}
}

Editors Controller:

public function beforeFilter() {
parent::beforeFilter();
//$this->Auth->allow('add');
//$this->Auth->autoRedirect = false;
}

public function beforeSave($options = array()) {
if (isset($this->data['Editor']['password'])) {
$this->data['Editor']['password'] =
AuthComponent::password($this->data['Editor']['password']);
}
return true;
}
public function login() {
if ($this->request->is('post')) {
if ($this->Auth->login()) {
return $this->redirect($this->Auth->redirectUrl());
//return $this->redirect($this->Auth->redirect());
} else {
$this->Session->setFlash(__('Username or password is
incorrect'), 'default', array(), 'auth');
}
}
}

public function logout() {
$this->redirect($this->Auth->logout());
}

Model:

<?php
App::uses('AppModel', 'Model');
/**
* Editor Model
*
*/
class Editor extends AppModel {

public $displayField = 'name';
}



--
View this message in context: http://cakephp.1045679.n5.nabble.com/Auth-Login-Redirect-is-not-redirecting-or-encrypting-user-info-tp5713474.html
Sent from the CakePHP mailing list archive at Nabble.com.

--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

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

No comments: