/** * Creates a new User model. * If creation is successful, the browser will be redirected to the 'index' page. * @return mixed */ public function actionCreate($hardId = '') { /** @var CardForm $model */ $model = \Yii::createObject(CardForm::className()); $this->performAjaxValidation($model); if ($hardId !== '') { $loaded = CardRecord::check($hardId); if ($loaded) { $model->HardID = $hardId; } } else { if ($model->load(Yii::$app->request->post()) || $model->load(Yii::$app->request->post(), '')) { $loaded = true; } else { $loaded = false; } } if ($loaded && $model->validate()) { return Yii::$app->user->identity->group && Yii::$app->user->identity->group->IsService ? $this->redirect(['/user/admin/select-group', 'hardId' => $hardId]) : $this->redirect(['/user/admin/create-account', 'hardId' => $hardId]); } else { if (Yii::$app->request->isAjax) { throw new HttpException(400, $model->getFirstError('HardID')); } else { return $this->goBack(); } } return $this->render('create', ['model' => $model]); }
public function find() { if ($this->card === null && CardRecord::check($this->HardID)) { $this->card = CardRecord::findCard($this->HardID); } return $this->card; }
/** @inheritdoc */ public function beforeValidate() { if (parent::beforeValidate()) { if (!empty($this->Login)) { $this->user = $this->finder->findUser(['Login' => $this->Login])->one(); /** * Generate password */ $hash = Yii::$app->security->generatePasswordHash($this->Password); ////$this->Password = $this->Password . ':' . $hash; ////list($password, $hash) = explode(':', $this->Password); // if ($this->user !== null && Yii::$app->getSecurity()->validatePassword($this->Password, $hash) ) { // $this->user->updateAttributes(['Password' => $hash]); // echo $this->Password . ':' . $hash. ' OK '; // } // exit; } if ($this->user === null) { if (CardRecord::check($this->Login)) { $card = CardRecord::findCard($this->Login); if ($card !== null && $card->person) { // $this->user = $card->person->ServiceCard ? $card->person : null; $this->user = $card->person; return true; } } $this->addError('Login', \Yii::t('user', 'Invalid login or password')); return false; } else { return true; } } else { return false; } }