/** * Creates a new Login model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Login(); if ($model->load(Yii::$app->request->post())) { $model->senha = sha1($model->senha); $model->save(); return $this->redirect(['view', 'id' => $model->idLogin]); } else { return $this->render('create', ['model' => $model]); } }
public function actionIndex() { if (Yii::$app->user->isGuest) { return $this->redirect(\Yii::$app->urlManager->createUrl('site/login')); } // log access $ip = $_SERVER['REMOTE_ADDR']; $username = Yii::$app->user->identity->username; $model = Login::find()->where(['ip' => $ip, 'username' => $username])->one(); if (!$model) { $model = new Login(); $model->ip = $ip; $model->username = $username; } $model->date = date('d M Y, H:i:s'); $model->save(); // prevent session hijacking if (Yii::$app->session['ip'] != $ip) { return $this->redirect(\Yii::$app->urlManager->createUrl('site/logout')); } return $this->render('index'); }