| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- <?php
- class SiteController extends Controller
- {
- public $layout='//layouts/site_index';
-
- /**
- * Declares class-based actions.
- */
- public function actions()
- {
- return array(
- // captcha action renders the CAPTCHA image displayed on the contact page
- 'captcha'=>array(
- 'class'=>'CCaptchaAction',
- 'backColor'=>0xFFFFFF,
- ),
- // page action renders "static" pages stored under 'protected/views/site/pages'
- // They can be accessed via: index.php?r=site/page&view=FileName
- 'page'=>array(
- 'class'=>'CViewAction',
- ),
- );
- }
- /**
- * This is the action to handle external exceptions.
- */
- public function actionError()
- {
- Helper::error('系统错误', 500, Yii::app()->errorHandler->error);
- }
- /**
- * Displays the login page
- */
- public function actionLogin()
- {
- $model=new LoginForm;
- if (isset($_POST['username'])) {
- $model->attributes=$_POST;
- if($model->validate() && $model->login()){
- Helper::ok(['token' => \Yii::app()->session->getSessionID(), 'refreshToken' => '']);
- } else {
- Helper::error('登入失败');
- }
- }
- Helper::error('参数错误');
- }
- /**
- * Logs out the current user and redirect to homepage.
- */
- public function actionLogout()
- {
- Yii::app()->user->logout();
- Helper::ok();
- }
- }
|