Created
November 6, 2009 18:30
-
-
Save envex/228167 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//AppController | |
<?php | |
class AppController extends Controller{ | |
var $name = 'App'; | |
var $components = array('Auth'); | |
var $helpers = array('Html','Form','Javascript','Vantage'); | |
function beforeFilter(){ | |
//we aren't using "users" model, so we want to change it to "member" | |
$this->Auth->userModel = 'Member'; | |
//where do we want to send the user? | |
$this->Auth->loginRedirect = array('controller' => 'members', 'action' => 'index'); | |
$this->Auth->logoutRedirect = array('controller' => 'pages', 'action' => 'index'); | |
//we want un-loggedin users to be able to signup | |
//$this->Auth->allow('signup','index'); | |
$this->Auth->authorize = 'controller'; | |
//change the username to the email field | |
//cakephp looks for the username as the default login | |
$this->Auth->fields = array('username' => 'email', 'password' => 'password'); | |
$this->set('user', $this->Auth->user()); | |
} | |
//we need this for Auth to work properly | |
function isAuthorized(){ | |
return true; | |
} | |
} | |
//MembersController | |
<?php | |
class MembersController extends AppController{ | |
var $name = 'Members'; | |
function beforeFilter(){ | |
$this->Auth->userModel = 'Member'; | |
$this->Auth->allow('signup'); | |
$this->set('area','members'); | |
} | |
//show the members section | |
function index(){ | |
} | |
//We need to signup new users | |
function signup() { | |
if (!empty($this->data)) { | |
//lets check to see if the password & confirm password are empty | |
if(isset($this->data['Member']['password']) && isset($this->data['Member']['password2'])){ | |
$this->data['Member']['passwordhashed'] = $this->Auth->password($this->data['Member']['password']); | |
$this->data['Member']['password2hashed'] = $this->Auth->password($this->data['Member']['password2']); | |
$this->data['Member']['password'] = $this->data['Member']['passwordhashed']; | |
} | |
$this->Member->create(); | |
$this->data['Member']['joined'] = date('Y-m-d'); | |
if ($this->Member->save($this->data)) { | |
$this->Session->setFlash('Your account has been created!'); | |
$this->redirect(array('action'=>'index'), null, true); | |
} else { | |
$this->Session->setFlash('You account could not be created. Try again!'); | |
} | |
} | |
} | |
//Let the user login | |
function login(){ | |
} | |
//Logout the user | |
function logout(){ | |
$this->Session->setFlash('You\'ve been logged out!'); | |
$this->redirect($this->Auth->logout()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment