Jump to content
Larry Ullman's Book Forums

Login Returns User To The Login Form Instead Of Home Page

Recommended Posts



I'm trying to implement the authentication techniques documented in Larry's awesome blog post. Here's the issue: Correct login credentials are entered into the AJAX login form on the home page. Upon pressing enter, a new Login form opens and no indication is present that user is authenticated. If that login form is then populated, again no further indication is present that we have authenticated.


UserController.php actionLogin:

public function actionLogin()
 $model= new Users();
//  Yii::app()->sessiion[username]= Yii::app()->model($username);
//  Yii:app()->session[password] = Yii::app()->model($password);
 // if it is ajax validation request
  echo CActiveForm::validate($model);
//			    print_r($_POST['Users']);
 // collect user input data
 $form =  new LoginForm;
//  if(isset($_POST['Users']))
//  {
//   $model->attributes=$_POST['Users'];	

  // validate user input and redirect to the previous page if valid
//   if($model->login())
//    $this->redirect(Yii::app()->user->getReturnUrl('index'));
//  }
 // display the login form
//  $this->render('login',array('model'=>$model));
  if($form->validate() && $form->login()) $this->redirect(Yii::app()->user->returnUrl);


LoginForm model authenticate:

public function authenticate($attribute,$params)
//   $this->_identity=new UserIdentity($this->username,$this->password);
//   if(!$this->_identity->authenticate())
//    $this->addError('password','Incorrect username or password.');
  $identity = new UserIdentity($this->username, $this->password);
   case UserIdentity::ERROR_NONE:
 $duration=$this->rememberMe ? 3600*24*30 : 0;  //30 days
   case UserIdentity::ERROR_USERNAME_INVALID:
 $this->addError('username', 'Username is incorrect.');
   default; // UserIdentity:ERROR_USERNAME_INVALID
 $this->addError('password','Password is incorrect.');



<div class="row">
  <?php echo $form->labelEx($model,'username'); ?>
 <?php echo $form->textField($model,'username'); ?>
 <?php echo $form->error($model,'username'); ?> 
<div class="row">
 <?php echo $form->labelEx($model,'password'); ?>
 <?php echo $form->passwordField($model,'password'); ?>
 <?php echo $form->error($model,'password'); ?>

<div class="row rememberMe">
 <?php echo $form->checkBox($model,'rememberMe'); ?>
 <?php echo $form->label($model,'rememberMe'); ?>
 <?php echo $form->error($model,'rememberMe'); ?>



public function authenticate()
//			    $username = $this->username;
//			    $password = $this->password;

		    $user = Users::model()->findbyAttributes(array($username=>$this->username));
		    if($user === NULL){

		    }else if ($user->password !== md5($this->password)){
//					    $this->username = $user->username;
//					   sess('SESS_USER_INFO', $user->attributes);
//					    $this->errorCode=self::ERROR_NONE;
  //invalid password
		    else {
		    return !$this->errorCode;


I feel like I'm so close to fixing this up, but yet cannot identify the root cause(s). Can anyone provide suggested resolutions?

Link to post
Share on other sites
  • 2 weeks later...
  • 2 weeks later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...