开发者

cakephp: signup link on register page not working

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开发者_JAVA百科'=>'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))
}
}
?>


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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜