tegarkurniawan

site

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