Yii Framework Forum: Login Empty - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Login Empty Rate Topic: -----

#1 User is offline   wnmd1987 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 5
  • Joined: 10-April 14

Posted 10 April 2014 - 02:26 PM

Buenas tardes, si alguien me pudiera colaborar; tengo una aplicacion hecha en yii, en local me corre perfectamente; pero cuando paso el sistema a produccion en un servidor linux; tengo problema con el login.. con la clase UserIdentity en especifico la funcion authenticate; cuando hago el retorno de return $this->errorCode==self::ERROR_NONE; no me guarda el id del usuario, es como si la funcion ocasionara un error.. si alguien le ha pasado o ha sabido de este problema.. gracias de ante mano

UserIdentity.php
<?php
class UserIdentity extends CUserIdentity
{
	 private $_id;

	public function authenticate()
	{
		
		$user=Usuario::model()->find('LOWER(username)=?',array(strtolower($this->username)));
                if($user===null)
                        $this->errorCode=self::ERROR_USERNAME_INVALID;
                else if(!$user->validatePassword($this->password))
                        $this->errorCode=self::ERROR_PASSWORD_INVALID;
                else
                {  
			$this->_id=$user->id;
                        $this->setState('nombre', $user->nombre);                      
                        $this->username=$user->username;
		       $this->errorCode=self::ERROR_NONE;
                }
                return $this->errorCode==self::ERROR_NONE;
			
		
	}
	
	 public function getId()
        {
                return $this->_id;
        }
}


LoginForm.php

<?php

class LoginForm extends CFormModel
{
	public $username;
	public $password;
	public $rememberMe;
	public $password2;
	public $password3;

	private $_identity;


	public function rules()
	{
		return array(
			// username and password are required
			array('username, password', 'required'),
			// rememberMe needs to be a boolean
			array('rememberMe', 'boolean'),
			// password needs to be authenticated
			array('password', 'authenticate'),
			array('password3','compare','compareAttribute'=>'password2','allowEmpty'=>false, 'on'=>'cambio'),
			array('username, password, password2, password3', 'required', 'on'=>'cambio'),
		);
	}


	public function attributeLabels()
	{
		return array(
			'rememberMe'=>'Recuerdame la Proxima vez',
			'password2'=> 'Introduzca el Nuevo Password',
			'password3'=> 'Repita el Nuevo Password',
		);
	}

	public function authenticate($attribute,$params)
	{
		if(!$this->hasErrors())
		{
			$this->_identity=new UserIdentity($this->username,$this->password);
			if(!$this->_identity->authenticate())
				$this->addError('password','Usuario o Password Incorrecto.');
		}
	}

	public function login()
	{
		if($this->_identity===null)
		{
			$this->_identity=new UserIdentity($this->username,$this->password);
			$this->_identity->authenticate();
		}
		if($this->_identity->errorCode===UserIdentity::ERROR_NONE)
		{
			$duration=$this->rememberMe ? 3600 : 0; // 1 hora
			Yii::app()->user->login($this->_identity,$duration);
			return true;
		}
		else
			return false;
	}
	
	public function getpassword($password)
        {
                return md5($password);
        }
}



Cuando redireciona al Main lo hace de manera vacia por lo tanto no entra en el Menu
0

#2 User is offline   wnmd1987 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 5
  • Joined: 10-April 14

Posted 23 April 2014 - 11:29 AM

$duration=$this->rememberMe ? 3600 : 0; // 1 hora
Yii::app()->user->login($this->_identity,$duration);


el error estaba en esta linea de codigo
0

#3 User is offline   lagogz 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 478
  • Joined: 30-November 12
  • Location:Galiza

Posted 06 May 2014 - 01:36 AM

View Postwnmd1987, on 23 April 2014 - 11:29 AM, said:

$duration=$this->rememberMe ? 3600 : 0; // 1 hora
Yii::app()->user->login($this->_identity,$duration);


el error estaba en esta linea de codigo


Y como lo solucionaste?
-----------------------------------------------------------------------------------------------
------------------------------- VISITEN FOCUCHASART --------------------------------
-----------------------------------------------------------------------------------------------
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users