Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //MembersController
- class MembersController extends AppController{
- var $name = 'Members';
- var $components = array('Auth');
- function beforeFilter(){
- $this->Auth->loginRedirect = array('controller' => 'members', 'action' => 'index');
- $this->Auth->logoutRedirect = array('controller' => 'pages', 'action' => 'index');
- $this->Auth->loginAction = array('controller' => 'members', 'action' => 'login');
- $this->Auth->allow('signup');
- $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->Auth->autoRedirect = false;
- $this->set('user', $this->Auth->user());
- }
- //we need this for Auth to work properly
- function isAuthorized(){
- return true;
- }
- //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->redirect($this->Auth->redirect());
- }
- }
Add Comment
Please, Sign In to add comment