SiteController.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. class SiteController extends Controller
  3. {
  4. public $layout='//layouts/site_index';
  5. /**
  6. * Declares class-based actions.
  7. */
  8. public function actions()
  9. {
  10. return array(
  11. // captcha action renders the CAPTCHA image displayed on the contact page
  12. 'captcha'=>array(
  13. 'class'=>'CCaptchaAction',
  14. 'backColor'=>0xFFFFFF,
  15. ),
  16. // page action renders "static" pages stored under 'protected/views/site/pages'
  17. // They can be accessed via: index.php?r=site/page&view=FileName
  18. 'page'=>array(
  19. 'class'=>'CViewAction',
  20. ),
  21. );
  22. }
  23. /**
  24. * This is the action to handle external exceptions.
  25. */
  26. public function actionError()
  27. {
  28. Helper::error('系统错误', 500, Yii::app()->errorHandler->error);
  29. }
  30. /**
  31. * Displays the login page
  32. */
  33. public function actionLogin()
  34. {
  35. $model=new LoginForm;
  36. if (isset($_POST['username'])) {
  37. $model->attributes=$_POST;
  38. if($model->validate() && $model->login()){
  39. Helper::ok(['token' => \Yii::app()->session->getSessionID(), 'refreshToken' => '']);
  40. } else {
  41. Helper::error('登入失败');
  42. }
  43. }
  44. Helper::error('参数错误');
  45. }
  46. /**
  47. * Logs out the current user and redirect to homepage.
  48. */
  49. public function actionLogout()
  50. {
  51. Yii::app()->user->logout();
  52. Helper::ok();
  53. }
  54. }