Wednesday, February 25, 2015

Manual login with Auth->login()

I am getting a successful login with Opauth, and sending results to Auth for login, which is returning true, yet when I continue into the protected area I am notified "You are not authorized to access that location." and redirected to the login page. I'm sure I'm missing something obvious... Code follows, thanks for any help!

class User extends AppModel {
public $validate = array(
'provider' => array(
'rule' => 'notEmpty'
),
'uid' => array(
'rule' => 'notEmpty'
),
'name' => array(
'rule' => 'notEmpty'
),
'email' => array(
'rule' => 'notEmpty'
)
);
}

class AppController extends Controller {
public $components = array(
'Session',
'Auth' => array(
'loginRedirect' => array(
'controller' => 'pages',
'action' => 'index'
),
'logoutRedirect' => array(
'controller' => 'users',
'action' => 'login'
)
)
);
public function beforeFilter() {
$this->Auth->allow('opauth_complete', 'logout');
}
}

public function opauth_complete() {
// Find User
$user = $this->User->find('first', array(
'conditions' => array(
'provider' => $this->data['auth']['provider'],
'uid' => $this->data['auth']['uid']
)
));
     if (empty($user)) {
// Process user for access request, notify user of approval/disapproval when processed
}
elseif (empty($user['User']['role'])) {
        // Notify user request hasn't been processed yet; don't call us, we'll call you
}
elseif ($user['User']['role'] == "Denied") {
        // Notify user they have been denied access by the administrator
}
else {
// Authorized User, Login
if ($this->Auth->login($user)) {
// Welcome user back (this is happening)
}
else {
// Notify login failed (not happening)
}
}
}

--
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.
For more options, visit https://groups.google.com/d/optout.

No comments: