/** * 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 create() { /** @var CardRecord $card */ $card = \Yii::createObject(CardRecord::className()); $card->HardID = $this->HardID; if ($card->save()) { \Yii::info('Зарегистрирована новая карта - ' . $card->HardID . ' ID:' . $card->id, 'info'); } else { \Yii::error('Не удалось зарегистрировать новую карту: ' . $card->getFirstError('HardID'), 'info'); } return $card; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = CardRecord::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['ID' => $this->ID]); $query->andFilterWhere(['like', 'HardID', $this->HardID]); return $dataProvider; }
/** @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; } }
public function getCard() { return $this->hasOne(CardRecord::className(), ['ID' => 'CardID']); }