0

I'm trying to use the Auth component only for viewing the progress report of a student. For all other links, authentication is not required. For the discussion board i already have a separate forum plugin.

When the user clicks the progress report link on the navigation bar, the user is directed to /merry_parents/register. Here, new users will click on signup link and existing users will click on login link.

However, my signup link is not working. I'm not being directed to the signup page when I click on signup. What am I doing wrong? any help is much appreciated.

The following is my code:

register.ctp

<?php
    echo $this->Html->link('Sign Up','/merry_parents/signup').' for new user |'.$this->Html->link('Login','/merry_parents/login',array()).' for existing user';
  ?>

merry_parents_controller.php

  <?php
     class MerryParentsController extends AppController{

var $name='MerryParents';
var $components=array('Auth','Session');

function beforeFilter(){
    //$this->Auth->authorize='actions';
    $this->Auth->loginAction=array('controller'=>'merry_parents','action'=>'register');
    //$this->Auth->loginRedirect=array('controller'=>'merry_parents','action'=>'report_card');

}

function register(){

}

function login(){
}

function logout(){
}

function signup(){
    if (!empty($this->data)){
        //$this->Auth->password($this->data['MerryParent']['password2'] used to get what the hashed password2 would look like.
        if ($this->data['MerryParent']['password']==$this->Auth->password($this->data['MerryParent']['password2'])){

                 $merryparent_id=$this->MerryParent->field('id',
                                                array('MerryParent.name'=>$this->data['MerryParent']['name'],
                                                'MerryParent.email'=>$this->data['MerryParent']['email'])
                                                );
                echo $merryparent_id;

                print_r($this->data);
                if ($this->MerryParent->save($this->data))//record with $merryparent_id is updated
                    {
                    $this->Session->setFlash('You will be receiving an email shortly confirming your login and password.');
                    $this->Auth->login($this->data); //automatically logs a user in after registration
                    $this->redirect(array('controller'=>'pages','action'=>'home'));
                    }
                else
                    echo $this->Session->setFlash(__('Your admission could not be saved, please try again!',true));


            }//end if ($this->data['MerryParent']['password']....
            else
                echo $this->Session->setFlash('Typed passwords did not match');
    }//end if (!empty($this->data))
}
}
?>
1
  • where are you directed to then?
    – Anh Pham
    Sep 16, 2011 at 7:29

1 Answer 1

1

You have to use following code in your MerryParentsController controller.

function beforeFilter() {
    $this->Auth->allow('signup');
}

This will allow your register method to get register. For more information please read http://book.cakephp.org/view/1255/AuthComponent-Methods

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.