Example #1
0
 public function actionLogin()
 {
     if (!\Yii::$app->user->isGuest) {
         return $this->goHome();
     }
     $model = new \app\models\LoginForm();
     if ($model->load(Yii::$app->request->post()) && $model->login()) {
         return $this->goBack();
     }
     return $this->render('login', ['model' => $model]);
 }
Example #2
0
 public function actionLogin()
 {
     $loginForm = new \app\models\LoginForm();
     if ($loginForm->load(Yii::$app->request->post()) && $loginForm->login()) {
         if (Yii::$app->user->identity->isModerator() || Yii::$app->user->identity->isClient()) {
             return $this->redirect(["/admin/index"]);
         } else {
             return $this->goHome();
         }
     }
     return $this->render('login', ['loginForm' => $loginForm]);
 }
 public function actionActivate($cvcode)
 {
     /**
      * @var $model \app\modules\discount\models\Card
      */
     $model = Card::findByCvcode($cvcode);
     if (!$model) {
         throw new HttpException('404', 'Карта с таким кодом не найдена!');
     }
     $user = new User();
     $user->scenario = 'client.create';
     $user->role = 'client';
     $profile = new Profile();
     $profile->scenario = 'client.create';
     $partner = new \app\modules\cms\models\Partner();
     $partner->scenario = 'card.activate';
     $partner->load($_POST);
     $partnerValidate = $partner->email ? $partner->validate() : true;
     //        var_dump($partnerValidate);
     if ($user->load($_POST) && $profile->load($_POST) && $partnerValidate) {
         $model->status = Card::STATUS_ACTIVE;
         $user->dateCreate = date(DATE_FORMAT_DB);
         if ($user->save()) {
             $model->userId = $user->id;
             $profile->file = UploadedFile::getInstance($profile, 'file');
             $profile->userId = $user->id;
             if ($profile->file) {
                 $filename = $user->id . '.' . $profile->file->extension;
                 $filepath = \Yii::getAlias(Profile::PHOTO_DIR_ALIAS) . '/' . $filename;
                 $profile->file->saveAs($filepath, false);
                 $profile->photo = $filename;
             }
             $profile->save();
             $model->dateActivate = date('Y-m-d H:i:s');
             $model->save(false, ['status', 'userId', 'dateActivate']);
             if ($partnerValidate) {
                 $partner->create($user);
             }
             $loginModel = new \app\models\LoginForm();
             $loginModel->username = $user->username;
             $loginModel->password = $user->password2;
             $loginModel->login();
             $this->redirect(['card', 'cvcode' => $cvcode]);
         }
     }
     return $this->render('activate', ['model' => $model, 'user' => $user, 'profile' => $profile, 'partner' => $partner]);
 }