tags:

views:

28

answers:

1

I have a login portlet up and running that's based on this tutorial. It works just fine, however, if there is an error with the login form the error messages are displayed within the portlet and they aren't very prominent.

The portlet follows:

class UserLogin extends Portlet
{
    public $title='Login';

    protected function renderContent()
    {
        $form=new LoginForm;
        if(isset($_POST['LoginForm']))
        {
            $form->attributes=$_POST['LoginForm'];
            if($form->validate())
                $this->controller->refresh();
        }
        $this->render('userLogin',array('form'=>$form));
    }
}

I would prefer any error to cause the login attempt to redirect to a full login form where the errors can be displayed prominently and it will be clear to the user something has gone wrong.

Something along the lines of:

if($form->validate())
    $this->controller->refresh();
else                
    $this->render('login',array('form'=>$form));

The else bit isn't correct, however, and I can't seem to figure out how to make it happen.

+1  A: 

You could try to use something like

else
{
    Yii::app()->user->setFlash('login', 'Login error');
    $this->controller->redirect(array('account/login'));
}

where account/login is the controller/action pair for separate login page. CWebUser's flash messages system is used to deliver error message into new action (See Yii cookbook How to work with flash messages).

Grey Teardrop
Works beautifully. I simply passed the entire form with Yii::app()->user->setFlash('login', $form);.
Jason George