Skip to content

Instantly share code, notes, and snippets.

@addingama
Created March 25, 2015 03:32
Show Gist options
  • Save addingama/ff9a74b256697fe65aa5 to your computer and use it in GitHub Desktop.
Save addingama/ff9a74b256697fe65aa5 to your computer and use it in GitHub Desktop.
// WpUser.php model
<?php
App::uses('AppModel', 'Model');
require(DIRNAME(ROOT).WP_DIR.'wp-load.php');
class WpUser extends AppModel {
}
// User controller: login
public function login() {
$this->loadModel('WpUser');
if($this->Auth->user()){
if($this->Auth->user('role') == 'follower'){
$this->redirect(array('controller' => 'users','action' => 'follower'));
}else{
$this->redirect(array('controller' => 'users','action' => 'index'));
}
}
if ($this->request->is('post')) {
if (null == user_exists($this->data['User']['email'])) {
debug('null'); die;
}
if ($this->Auth->login()) {
// check wp user, if null then create new
if($this->Auth->user('role') == 'follower'){
return $this->redirect(array('controller' => 'users','action' => 'follower'));
}else{
return $this->redirect($this->Auth->redirect());
}
}
$this->Session->setFlash(__('Invalid username or password, try again'),'auth_message',array('status' => 'danger'),'auth');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment