Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace app\controllers;
- use app\models\Blogger;
- use app\models\RegisterForm;
- use Yii;
- use yii\filters\AccessControl;
- use yii\web\Controller;
- use yii\filters\VerbFilter;
- use app\models\LoginForm;
- use app\models\ContactForm;
- class SiteController extends Controller
- {
- /**
- * @inheritdoc
- */
- public function behaviors()
- {
- return [
- 'access' => [
- 'class' => AccessControl::className(),
- 'only' => ['logout'],
- 'rules' => [
- [
- 'actions' => ['logout'],
- 'allow' => true,
- 'roles' => ['@'],
- ],
- ],
- ],
- 'verbs' => [
- 'class' => VerbFilter::className(),
- 'actions' => [
- 'logout' => ['post'],
- ],
- ],
- ];
- }
- /**
- * @inheritdoc
- */
- public function actions()
- {
- return [
- 'error' => [
- 'class' => 'yii\web\ErrorAction',
- ],
- 'captcha' => [
- 'class' => 'yii\captcha\CaptchaAction',
- 'fixedVerifyCode' => YII_ENV_TEST ? 'testme' : null,
- ],
- ];
- }
- /**
- * Displays homepage.
- *
- * @return string
- */
- public function actionIndex()
- {
- return $this->render('index');
- }
- /**
- * Login action.
- *
- * @return string
- */
- public function actionLogin()
- {
- if (!Yii::$app->user->isGuest) {
- return $this->goHome();
- }
- $model = new LoginForm();
- if ($model->load(Yii::$app->request->post()) && $model->login()) {
- return $this->goBack();
- }
- return $this->render('login', [
- 'model' => $model,
- ]);
- }
- public function actionRegister()
- {
- $model = new RegisterForm();
- $user = new Blogger();
- if(isset($_POST['RegisterForm']))
- {
- $model->attributes = $_POST['RegisterForm'];
- if($model->validate())
- {
- $user->username = $model->username;
- $user->email = $model->email;
- $user->password = $model->password;
- $user->save();
- $this->redirect('index');
- }
- }
- return $this->render('register',[
- 'model' => $model,
- ]);
- }
- /**
- * Logout action.
- *
- * @return string
- */
- public function actionLogout()
- {
- Yii::$app->user->logout();
- return $this->goHome();
- }
- /**
- * Displays contact page.
- *
- * @return string
- */
- public function actionContact()
- {
- $model = new ContactForm();
- if ($model->load(Yii::$app->request->post()) && $model->contact(Yii::$app->params['adminEmail'])) {
- Yii::$app->session->setFlash('contactFormSubmitted');
- return $this->refresh();
- }
- return $this->render('contact', [
- 'model' => $model,
- ]);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement