Created
June 27, 2009 07:22
-
-
Save jdp/136935 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
<?php | |
if ($session->check('Message.auth')) { | |
$session->flash('auth'); | |
} | |
echo $form->create('User', array('action'=>'login')); | |
echo $form->input('email'); | |
echo $form->input('password'); | |
echo $form->end('Login'); | |
?> |
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
<?php | |
class User extends AppModel { | |
var $name = 'User'; | |
var $hasMany = 'Playlist'; | |
var $validate = array( | |
'id' => array( | |
'rule' => 'blank', | |
'on' => 'create' | |
), | |
'email' => array( | |
'cuz-its-required' => array( | |
'rule' => 'email', | |
'required' => true, | |
'message' => 'Please enter a valid email' | |
), | |
'steal-an-email' => array( | |
'rule' => 'isUnique', | |
'message' => 'Somebody is already using that email', | |
'on' => 'create' | |
) | |
), | |
// passwd is the name of the form element | |
// it gets hashed and put into password db field | |
'passwd' => array( | |
'rule' => array('confirmPassword', 'password'), | |
'message' => 'Passwords do not match', | |
'on' => 'create' | |
), | |
'password_confirm' => array( | |
'rule' => 'alphanumeric', | |
'required' => true | |
) | |
); | |
/* Makes more sense than doing it in controller */ | |
function confirmPassword($data) { | |
return ($data['passwd'] == $this->data['User']['password_confirm']); | |
} | |
/* Override for Auth's hashPassword function, to work w/ old users */ | |
function hashPasswords($data) { | |
$data[$this->alias]['password'] = md5($data[$this->alias]['password']); | |
return $data; | |
} | |
} | |
?> |
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
<?php | |
class UsersController extends AppController { | |
var $name = 'Users'; | |
var $helpers = array('Html', 'Form'); | |
var $components = array('Auth'); | |
function beforeFilter() { | |
//$this->Auth->authenticate = ClassRegistry::init('User'); | |
$this->Auth->fields = array( | |
'username' => 'email', | |
'password' => 'password' | |
); | |
$this->Auth->allow('signup'); | |
} | |
function dashboard() { | |
} | |
function login() { | |
} | |
function signup() { | |
if (!empty($this->data)) { | |
$this->data['User']['password'] = md5($this->data['User']['passwd']); | |
$this->User->create($this->data); | |
if ($this->User->save()) { | |
// Auth::login doesn't pay attention to Auth->fields | |
$this->data['User']['username'] = $this->data['User']['email']; | |
$login_result = $this->Auth->login($this->data); | |
$this->Session->del('Message.auth'); | |
//$this->Session->setFlash("Signup successful!"); | |
//$this->redirect($this->Auth->redirect()); | |
} | |
} | |
} | |
function logout() { | |
$this->redirect($this->Auth->logout()); | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment