Guest User

SiteController.php

a guest
Dec 22nd, 2015
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.10 KB | None | 0 0
  1. <?php
  2.  
  3. class SiteController extends Controller
  4. {
  5. private $instanceId;
  6.  
  7.  
  8. public function init()
  9. {
  10. $this->instanceId = '139e8d93-03b7-a089-276c-5a5eaacea691';
  11. }
  12.  
  13.  
  14. /**
  15. * Declares class-based actions.
  16. */
  17. public function actions()
  18. {
  19. return array(
  20. // captcha action renders the CAPTCHA image displayed on the contact page
  21. 'captcha'=>array(
  22. 'class'=>'CCaptchaAction',
  23. 'backColor'=>0xFFFFFF,
  24. ),
  25. // page action renders "static" pages stored under 'protected/views/site/pages'
  26. // They can be accessed via: index.php?r=site/page&view=FileName
  27. 'page'=>array(
  28. 'class'=>'CViewAction',
  29. ),
  30. );
  31. }
  32.  
  33. /**
  34. * This is the default 'index' action that is invoked
  35. * when an action is not explicitly requested by users.
  36. */
  37. public function actionIndex()
  38. {
  39. // adding the user or using the existing one
  40. $user = User::model()->with(array('locale'))->find(array(
  41. 'condition' => 'instanceId=:instanceId',
  42. 'params' => array(':instanceId' => $this->instanceId),
  43. 'order'=>'t.id DESC'
  44. ));
  45.  
  46. // renders the view file 'protected/views/site/index.php'
  47. // using the default layout 'protected/views/layouts/main.php'
  48. $this->render('index');
  49. }
  50.  
  51. /**
  52. * This is the action to handle external exceptions.
  53. */
  54. public function actionError()
  55. {
  56. if($error=Yii::app()->errorHandler->error)
  57. {
  58. if(Yii::app()->request->isAjaxRequest)
  59. echo $error['message'];
  60. else
  61. $this->render('error', $error);
  62. }
  63. }
  64.  
  65. /**
  66. * Displays the contact page
  67. */
  68. public function actionContact()
  69. {
  70. $model=new ContactForm;
  71. if(isset($_POST['ContactForm']))
  72. {
  73. $model->attributes=$_POST['ContactForm'];
  74. if($model->validate())
  75. {
  76. $name='=?UTF-8?B?'.base64_encode($model->name).'?=';
  77. $subject='=?UTF-8?B?'.base64_encode($model->subject).'?=';
  78. $headers="From: $name <{$model->email}>\r\n".
  79. "Reply-To: {$model->email}\r\n".
  80. "MIME-Version: 1.0\r\n".
  81. "Content-Type: text/plain; charset=UTF-8";
  82.  
  83. mail(Yii::app()->params['adminEmail'],$subject,$model->body,$headers);
  84. Yii::app()->user->setFlash('contact','Thank you for contacting us. We will respond to you as soon as possible.');
  85. $this->refresh();
  86. }
  87. }
  88. $this->render('contact',array('model'=>$model));
  89. }
  90.  
  91. /**
  92. * Displays the login page
  93. */
  94. public function actionLogin()
  95. {
  96. $model=new LoginForm;
  97.  
  98. // if it is ajax validation request
  99. if(isset($_POST['ajax']) && $_POST['ajax']==='login-form')
  100. {
  101. echo CActiveForm::validate($model);
  102. Yii::app()->end();
  103. }
  104.  
  105. // collect user input data
  106. if(isset($_POST['LoginForm']))
  107. {
  108. $model->attributes=$_POST['LoginForm'];
  109. // validate user input and redirect to the previous page if valid
  110. if($model->validate() && $model->login())
  111. $this->redirect(Yii::app()->user->returnUrl);
  112. }
  113. // display the login form
  114. $this->render('login',array('model'=>$model));
  115. }
  116.  
  117. /**
  118. * Logs out the current user and redirect to homepage.
  119. */
  120. public function actionLogout()
  121. {
  122. Yii::app()->user->logout();
  123. $this->redirect(Yii::app()->homeUrl);
  124. }
  125. }
Add Comment
Please, Sign In to add comment