Advertisement
Guest User

SiteController.php

a guest
Jul 3rd, 2013
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.69 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 default 'index' action that is invoked
  26. * when an action is not explicitly requested by users.
  27. */
  28. public function actionIndex()
  29. {
  30. // renders the view file 'protected/views/site/index.php'
  31. // using the default layout 'protected/views/layouts/main.php'
  32. $this->render('index');
  33. }
  34.  
  35. /**
  36. * This is the action to handle external exceptions.
  37. */
  38. public function actionError()
  39. {
  40. if($error=Yii::app()->errorHandler->error)
  41. {
  42. if(Yii::app()->request->isAjaxRequest)
  43. echo $error['message'];
  44. else
  45. $this->render('error', $error);
  46. }
  47. }
  48.  
  49. /**
  50. * Displays the contact page
  51. */
  52. public function actionContact()
  53. {
  54. $model=new ContactForm;
  55. if(isset($_POST['ContactForm']))
  56. {
  57. $model->attributes=$_POST['ContactForm'];
  58. if($model->validate())
  59. {
  60. $name='=?UTF-8?B?'.base64_encode($model->name).'?=';
  61. $subject='=?UTF-8?B?'.base64_encode($model->subject).'?=';
  62. $headers="From: $name <{$model->email}>\r\n".
  63. "Reply-To: {$model->email}\r\n".
  64. "MIME-Version: 1.0\r\n".
  65. "Content-type: text/plain; charset=UTF-8";
  66.  
  67. mail(Yii::app()->params['adminEmail'],$subject,$model->body,$headers);
  68. Yii::app()->user->setFlash('contact','Thank you for contacting us. We will respond to you as soon as possible.');
  69. $this->refresh();
  70. }
  71. }
  72. $this->render('contact',array('model'=>$model));
  73. }
  74.  
  75. public function actionRegistersuccess()
  76. {
  77. $this->render('registersuccess');
  78. }
  79.  
  80. public function actionRegister()
  81. {
  82. $model = new RegisterForm;
  83. if (isset($_POST['ajax']) && $_POST['ajax']==='register-form')
  84. {
  85. echo CActiveForm::validate($model);
  86. Yii::app()->end();
  87. }
  88. if (isset($_POST['RegisterForm']))
  89. {
  90. $model->attributes=$_POST['RegisterForm'];
  91. if ($model->validate() && $model->register())
  92. $this->redirect(Yii::app()->user->returnUrl);
  93. }
  94. $this->render('register', array('model'=>$model));
  95. }
  96.  
  97. /**
  98. * Displays the login page
  99. */
  100. public function actionLogin()
  101. {
  102. $model=new LoginForm;
  103.  
  104. // if it is ajax validation request
  105. if(isset($_POST['ajax']) && $_POST['ajax']==='login-form')
  106. {
  107. echo CActiveForm::validate($model);
  108. Yii::app()->end();
  109. }
  110.  
  111. // collect user input data
  112. if(isset($_POST['LoginForm']))
  113. {
  114. $model->attributes=$_POST['LoginForm'];
  115. // validate user input and redirect to the previous page if valid
  116. if($model->validate() && $model->login())
  117. {
  118. $this->redirect(Yii::app()->user->returnUrl);
  119. }
  120. }
  121. // display the login form
  122. $this->render('login',array('model'=>$model));
  123. }
  124.  
  125. /**
  126. * Logs out the current user and redirect to homepage.
  127. */
  128. public function actionLogout()
  129. {
  130. Yii::app()->user->logout();
  131. $this->redirect(Yii::app()->homeUrl);
  132. }
  133.  
  134. public function actionConfirm($st)
  135. {
  136. $c = Yii::app()->db->createCommand()->select()->from('users')->where("confirm_string='" . $st . "'")->query();
  137. if ($c->rowCount == 0)
  138. {
  139. $this->redirect(Yii::app()->baseUrl);
  140. }
  141. else
  142. {
  143. Yii::app()->db->createCommand()->update('users', array('confirmed'=>1), 'confirm_string = :conf', array(':conf'=>$st));
  144. $this->redirect(Yii::app()->loginUrl);
  145. }
  146. }
  147. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement