mirror of
https://github.com/yiisoft/yii.git
synced 2026-03-04 07:14:06 +01:00
56 lines
1.2 KiB
PHP
56 lines
1.2 KiB
PHP
<?php
|
|
|
|
class SiteController extends CController
|
|
{
|
|
/**
|
|
* Declares class-based actions.
|
|
*/
|
|
public function actions()
|
|
{
|
|
return array(
|
|
// captcha action renders the CAPTCHA image
|
|
'captcha'=>array(
|
|
'class'=>'CCaptchaAction',
|
|
'backColor'=>0xEBF4FB,
|
|
),
|
|
);
|
|
}
|
|
|
|
/**
|
|
* This is the default 'index' action that is invoked
|
|
* when an action is not explicitly requested by users.
|
|
*/
|
|
public function actionIndex()
|
|
{
|
|
// renders the view file 'protected/views/site/index.php'
|
|
// using the default layout 'protected/views/layouts/main.php'
|
|
$this->render('index');
|
|
}
|
|
|
|
/**
|
|
* Displays a login form to login a user.
|
|
*/
|
|
public function actionLogin()
|
|
{
|
|
$form=new LoginForm;
|
|
// collect user input data
|
|
if(isset($_POST['LoginForm']))
|
|
{
|
|
$form->attributes=$_POST['LoginForm'];
|
|
// validate user input and redirect to previous page if valid
|
|
if($form->validate())
|
|
$this->redirect(Yii::app()->user->returnUrl);
|
|
}
|
|
// display the login form
|
|
$this->render('login',array('form'=>$form));
|
|
}
|
|
|
|
/**
|
|
* Logout the current user and redirect to homepage.
|
|
*/
|
|
public function actionLogout()
|
|
{
|
|
Yii::app()->user->logout();
|
|
$this->redirect(Yii::app()->homeUrl);
|
|
}
|
|
} |