SiteController.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <?php
  2. class SiteController extends Controller
  3. {
  4. public $layout='column1';
  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. if($error=Yii::app()->errorHandler->error)
  29. {
  30. if(Yii::app()->request->isAjaxRequest)
  31. echo $error['message'];
  32. else
  33. $this->render('error', $error);
  34. }
  35. }
  36. /**
  37. * Displays the contact page
  38. */
  39. public function actionContact()
  40. {
  41. $model=new ContactForm;
  42. if(isset($_POST['ContactForm']))
  43. {
  44. $model->attributes=$_POST['ContactForm'];
  45. if($model->validate())
  46. {
  47. $headers="From: {$model->email}\r\nReply-To: {$model->email}";
  48. mail(Yii::app()->params['adminEmail'],$model->subject,$model->body,$headers);
  49. Yii::app()->user->setFlash('contact','Thank you for contacting us. We will respond to you as soon as possible.');
  50. $this->refresh();
  51. }
  52. }
  53. $this->render('contact',array('model'=>$model));
  54. }
  55. /**
  56. * Displays the login page
  57. */
  58. public function actionLogin()
  59. {
  60. if (!defined('CRYPT_BLOWFISH')||!CRYPT_BLOWFISH)
  61. throw new CHttpException(500,"This application requires that PHP was compiled with Blowfish support for crypt().");
  62. $model=new LoginForm;
  63. // if it is ajax validation request
  64. if(isset($_POST['ajax']) && $_POST['ajax']==='login-form')
  65. {
  66. echo CActiveForm::validate($model);
  67. Yii::app()->end();
  68. }
  69. // collect user input data
  70. if(isset($_POST['LoginForm']))
  71. {
  72. $model->attributes=$_POST['LoginForm'];
  73. // validate user input and redirect to the previous page if valid
  74. if($model->validate() && $model->login())
  75. $this->redirect(Yii::app()->user->returnUrl);
  76. }
  77. // display the login form
  78. $this->render('login',array('model'=>$model));
  79. }
  80. /**
  81. * Logs out the current user and redirect to homepage.
  82. */
  83. public function actionLogout()
  84. {
  85. Yii::app()->user->logout();
  86. $this->redirect(Yii::app()->homeUrl);
  87. }
  88. }