I've hosted my Yii webapp on AWS. The login isn't working and redirects to the logged out homepage. Debugging on AWS is proving difficult.
My app implements Yii-users for the authentication system and the following controller acton is run for the login view:
public function actionLogin()
{
if (Yii::app()->user->isGuest) {
$model=new UserLogin;
// collect user input data
if(isset($_POST['UserLogin'])){
$model->attributes=$_POST['UserLogin'];
// validate user input and redirect to previous page if valid
if($model->validate()) {
$this->lastViset();
if (Yii::app()->user->returnUrl=='/index.php'){
$this->redirect(Yii::app()->controller->module->returnUrl);
} else {
$time = date('h:i:s A');
mail('my-email@gmail.com','Debugging',"BP3 $time");
$this->redirect(Yii::app()->user->returnUrl);
}
}
}
// display the login form
$this->render('/user/login',array('model'=>$model));
} else {
$this->redirect(Yii::app()->controller->module->returnUrl);
}
}
The code runs OK the POST data is being passed, the problem appears to be with the $model->validate() not evaluating to true. I believe this to be the case as I've followed which parts of the login action run "if($model->validate())" runs, but the code within the loop doesn't making me think it hasn't evaluated to true.
The UserLogin model is like so:
<?php
/**
* LoginForm class.
* LoginForm is the data structure for keeping
* user login form data. It is used by the 'login' action of 'SiteController'.
*/
class UserLogin extends CFormModel
{
public $email;
public $password;
public $rememberMe;
/**
* Declares the validation rules.
* The rules state that username and password are required,
* and password needs to be authenticated.
*/
public function rules()
{
return array(
// username and password are required
array('email, password', 'required'),
// rememberMe needs to be a boolean
array('rememberMe', 'boolean'),
// password needs to be authenticated
array('password', 'authenticate'),
);
}
/**
* Declares attribute labels.
*/
public function attributeLabels()
{
return array(
'rememberMe'=>UserModule::t("Remember me next time"),
'username'=>UserModule::t("email"),
'password'=>UserModule::t("password"),
);
}
/**
* Authenticates the password.
* This is the 'authenticate' validator as declared in rules().
*/
public function authenticate($attribute,$params)
{
if(!$this->hasErrors()) // we only want to authenticate when no input errors
{
$identity=new UserIdentity($this->email,$this->password);
$identity->authenticate();
switch($identity->errorCode)
{
case UserIdentity::ERROR_NONE:
$duration=$this->rememberMe ? Yii::app()->controller->module->rememberMeTime : 0;
Yii::app()->user->login($identity,$duration);
break;
case UserIdentity::ERROR_EMAIL_INVALID:
$this->addError("username",UserModule::t("Email is incorrect."));
break;
case UserIdentity::ERROR_USERNAME_INVALID:
$this->addError("username",UserModule::t("Username is incorrect."));
break;
case UserIdentity::ERROR_STATUS_NOTACTIV:
$this->addError("status",UserModule::t("You account is not activated."));
break;
case UserIdentity::ERROR_STATUS_BAN:
$this->addError("status",UserModule::t("You account is blocked."));
break;
case UserIdentity::ERROR_PASSWORD_INVALID:
$this->addError("password",UserModule::t("Password is incorrect."));
break;
}
}
}
}
I don't understand what would not work with this code on AWS that works fine on a shared/local environments. I'm using the Elastic Beanstalk environment and have overridden several settings of the php.ini file with the following:
files:
"/etc/php.d/project.ini" :
mode: "000644"
owner: ec2-user
group: ec2-user
content: |
error_reporting = E_ALL & ~E_STRICT & ~E_NOTICE & ~E_WARNING
display_errors = On
post_max_size = 32M
enable_dl = On
How should I go about debugging this code on AWS? Admittedly my knowledge of Yii-users is not as good as it should be.