Exemplo n.º 1
0
 public function actionLogin()
 {
     $model = new Login();
     if ($model->load(Yii::$app->request->getBodyParams(), '') && $model->validate()) {
         if ($model->validate()) {
             return $model;
         }
     } else {
         return $model;
     }
 }
Exemplo n.º 2
0
 /**
  * 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 actionLogin()
 {
     $model = new Login();
     //print_r(Yii::$app->request->post());
     //exit;
     $data = $model->load(Yii::$app->request->post());
     $msg = "";
     //print_r($model);
     if ($model->login()) {
         // Get the actual logged user
         //echo "login";
         //print_r( Yii::$app->user->getIdentity() );
         //exit;
         //Yii::$app->user->getIdentity()
         //return $this->goBack();
         //return $this->actionIndex();
         $this->redirect(array('server/index'));
     } else {
         $msg = "Please verify  user and password.";
     }
     $this->layout = 'login';
     return $this->render('login', array('model' => $model, 'msg' => $msg));
 }
Exemplo n.º 4
0
 public function actionLogin()
 {
     $model = new Login();
     if ($model->load(Yii::$app->request->post())) {
         $user = $model->getUser();
         if ($user) {
             $can = $user->canLogin();
             if ($can && $user->validatePassword($model->password)) {
                 if ($user->status > 0) {
                     Yii::$app->user->login($user);
                     return $this->redirect(['view', 'name' => $user->name]);
                 } else {
                     Yii::$app->session->setFlash('error', Yii::t('app', 'Ваш аккаунт заблокирован'));
                 }
             } else {
                 Journal::write('user', 'login_fail', $user->id);
                 if ($can) {
                     Yii::$app->session->setFlash('error', Yii::t('app', 'Invalid username or password'));
                 } else {
                     $record = Record::find()->where(['object_id' => $user->id, 'event' => 'login_fail'])->orderBy(['time' => SORT_DESC])->one();
                     Yii::$app->session->setFlash('error', "Вы превысили максимальное количество попыток входа, вы сможете войти после {$record->time}");
                 }
             }
         } else {
             Yii::$app->session->setFlash('error', Yii::t('app', 'Invalid username or password'));
         }
     }
     return $this->render('login', ['model' => $model]);
 }
Exemplo n.º 5
0
 public function actionLogin()
 {
     $model = new Login();
     if ($model->load(Yii::$app->request->post())) {
         $user = $model->getUser();
         if ($user) {
             if (empty($user->hash)) {
                 Yii::$app->session->setFlash('error', Yii::t('app', Yii::t('app', 'Your account is not activated. Check your email')));
             } else {
                 $can = $user->canLogin();
                 if ($can && $user->validatePassword($model->password)) {
                     if ($user->status > 0) {
                         if (empty($user->auth)) {
                             $user->generateAuthKey();
                             $user->save();
                         }
                         if (Yii::$app->user->login($user, $model->remember ? $user->duration * 60 : 0)) {
                             $bundle = $user->getBundle();
                             if ($bundle && isset($bundle['node_id'])) {
                                 $node_id = (int) $bundle['node_id'];
                                 $user->setBundle(null);
                                 $user->save();
                                 if (Node::find()->where(['id' => $node_id])->count() > 0) {
                                     Yii::$app->session->addFlash('success', Yii::t('app', 'Congratulation! You receive a gift'));
                                     return $this->redirect(['/pyramid/node/index', 'id' => $node_id]);
                                 }
                             }
                             return $this->redirect(['view']);
                             //                                return $this->actionView($user->name);
                         } else {
                             Yii::$app->session->addFlash('error', Yii::t('app', 'Something wrong happened'));
                         }
                     } else {
                         Yii::$app->session->setFlash('error', Yii::t('app', Yii::t('app', 'Your account is blocked')));
                     }
                 } else {
                     Journal::write('user', 'login_fail', $user->id);
                     if ($can) {
                         Yii::$app->session->setFlash('error', Yii::t('app', 'Invalid username or password'));
                     } else {
                         $record = Record::find()->where(['object_id' => $user->id, 'event' => 'login_fail'])->orderBy(['time' => SORT_DESC])->one();
                         Yii::$app->session->setFlash('error', Yii::t('app', 'You have exceeded the maximum number of login attempts, you will be able to enter after {time}', ['time' => $record->time]));
                     }
                 }
             }
         } else {
             Yii::$app->session->setFlash('error', Yii::t('app', 'Invalid username or password'));
         }
     }
     return $this->render('login', ['model' => $model]);
 }