Advertisement
Guest User

Untitled

a guest
Mar 3rd, 2012
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.12 KB | None | 0 0
  1. <?php
  2.  
  3. class SiteController extends Controller
  4. {
  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. /**
  25. * This is the action to handle external exceptions.
  26. */
  27. public function actionError()
  28. {
  29. if($error=Yii::app()->errorHandler->error)
  30. {
  31. if(Yii::app()->request->isAjaxRequest)
  32. echo $error['message'];
  33. else
  34. $this->render('error', $error);
  35. }
  36. }
  37.  
  38. /**
  39. * Displays the contact page
  40. */
  41. public function actionContact()
  42. {
  43. $model=new ContactForm;
  44. if(isset($_POST['ContactForm']))
  45. {
  46. $model->attributes=$_POST['ContactForm'];
  47. if($model->validate())
  48. {
  49. $headers="From: {$model->email}\r\nReply-To: {$model->email}";
  50. mail(Yii::app()->params['adminEmail'],$model->subject,$model->body,$headers);
  51. Yii::app()->user->setFlash('contact','Thank you for contacting us. We will respond to you as soon as possible.');
  52. $this->refresh();
  53. }
  54. }
  55. $this->render('contact',array('model'=>$model));
  56. }
  57.  
  58. /**
  59. * Displays the login page
  60. */
  61. public function actionLogin()
  62. {
  63. $model=new LoginForm;
  64.  
  65. // if it is ajax validation request
  66. if(isset($_POST['ajax']) && $_POST['ajax']==='login-form')
  67. {
  68. echo CActiveForm::validate($model);
  69. Yii::app()->end();
  70. }
  71.  
  72. // collect user input data
  73. if(isset($_POST['LoginForm']))
  74. {
  75. $model->attributes=$_POST['LoginForm'];
  76. // validate user input and redirect to the previous page if valid
  77. if($model->validate() && $model->login())
  78. $this->redirect(Yii::app()->user->returnUrl);
  79. }
  80. // display the login form
  81. $this->render('login',array('model'=>$model));
  82. }
  83.  
  84. /**
  85. * Logs out the current user and redirect to homepage.
  86. */
  87. public function actionLogout()
  88. {
  89. Yii::app()->user->logout();
  90. $this->redirect(Yii::app()->homeUrl);
  91. }
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement