Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeffwinesett/3791860 to your computer and use it in GitHub Desktop.
Save jeffwinesett/3791860 to your computer and use it in GitHub Desktop.
Yii Web Dev Book, Chapter 12, section: Adding a login message log
/**
* Displays the login page
*/
public function actionLogin()
{
Yii::trace("The actionLogin() method is being requested", "application.controllers.SiteController");
//if they are already logged in, redirect them to the home page
if(!Yii::app()->user->isGuest)
{
$this->redirect(Yii::app()->homeUrl);
}
$model=new LoginForm;
// if it is ajax validation request
if(isset($_POST['ajax']) && $_POST['ajax']==='login-form')
{
echo CActiveForm::validate($model);
Yii::app()->end();
}
// collect user input data
if(isset($_POST['LoginForm']))
{
$model->attributes=$_POST['LoginForm'];
// validate user input and redirect to the previous page if valid
if($model->validate() && $model->login())
{
Yii::log("Successful login of user: " . Yii::app()->user->id, "info", "application.controllers.SiteController");
$this->redirect(Yii::app()->user->returnUrl);
}
else
{
Yii::log("Failed login attempt", "warning", "application.controllers.SiteController");
}
}
// display the login form
$this->render('login',array('model'=>$model));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment