public function sendSMS() { $user = Account::findOne(['phone' => $this->phone]); if ($user) { $passToken = $user->generatePasswordResetToken()->getPasswordResetToken(); $user->setScenario('reset-password'); if ($user->save()) { $mes = 'only3.ru Код:' . $passToken; $phoneClient = preg_replace('/[^0-9]/', '', $this->phone); $login = '******'; $password = '******'; $phone = $phoneClient; $from = 'only3'; $mes = iconv("UTF-8", "WINDOWS-1251", $mes); $msg = urlencode($mes); $checksumm = md5($login . md5($password) . $phone); $res = file_get_contents("http://sms48.ru/send_sms.php?login={$login}&to={$phone}&msg={$msg}&from={$from}&check2={$checksumm}"); if ($res == 1) { //sms was sending return $user->id; } } } return false; }
/** * @return array $reuslt['user','errors']; */ public function signupClient() { $result = ['user' => '', 'errors' => '']; $errors = ''; $user = ''; if ($this->validate()) { $user = new Account(); $user->setScenario('client-registration'); $user->setAttributes($this->getAttributes()); $user->setAttribute('status', 1); $user->password = Yii::$app->security->generateRandomString(8); $user->cleanPassword = $user->password; $user->setPassword($this->password); $user->generateAuthKey(); if ($user->save()) { $auth = Yii::$app->authManager; $authorRole = $auth->getRole('client'); $auth->assign($authorRole, $user->getId()); } else { $errors['user'] = $user->getErrors(); } } else { $errors['signup'] = $this->getErrors(); } $result['user'] = $user; $result['errors'] = $errors; return $result; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Account::find()->salons(); $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, 'city_id' => $this->city_id, 'lastLoginAt' => $this->lastLoginAt, 'createdAt' => $this->createdAt, 'updatedAt' => $this->updatedAt, 'status' => $this->status, 'balance' => $this->balance]); if ($this->getScenario() !== 'moderate') { $query->andFilterWhere(['like', 'slug_url', $this->slug_url]); } $query->andFilterWhere(['like', 'phone', $this->phone])->andFilterWhere(['like', 'username', $this->username])->andFilterWhere(['like', 'password', $this->password])->andFilterWhere(['like', 'password_reset_token', $this->password_reset_token])->andFilterWhere(['like', 'authKey', $this->authKey])->andFilterWhere(['like', 'email', $this->email])->andFilterWhere(['like', 'url', $this->url])->andFilterWhere(['like', 'xy', $this->xy])->andFilterWhere(['like', 'address', $this->address])->andFilterWhere(['like', 'thumb', $this->thumb])->andFilterWhere(['like', 'city_name', $this->city_name])->andFilterWhere(['like', 'place_delivery', $this->place_delivery])->andFilterWhere(['like', 'other', $this->other])->andFilterWhere(['like', 'contract', $this->contract])->andFilterWhere(['like', 'is_moderated', $this->is_moderated])->andFilterWhere(['like', 'is_salon', $this->is_salon]); // Create a command. You can get the actual SQL using $command->sql $command = $query->createCommand(); return $dataProvider; }
/** * @param $id * @return string * @throws NotFoundHttpException */ public function actionOurCars($slug_url) { $accountModel = Account::findOne(['slug_url' => $slug_url]); if (empty($accountModel)) { $this->setNotFoundHttpException(); } $params['AutoSearch']['account_id'] = $accountModel->id; $this->title = "Автопрокат - " . $accountModel->username; $searchModel = new AutoSearch(); $searchModel->setScenario('salon-cars'); $dataProvider = $searchModel->search($params); return $this->render('ourCars', ['dataProvider' => $dataProvider, 'accountModel' => $accountModel]); }
/** * @return \yii\db\ActiveQuery */ public function getAccount() { return $this->hasOne(Account::className(), ['id' => 'account_id']); }
/** * Resets password. * * @param string $token * @return mixed * @throws BadRequestHttpException */ public function actionResetPassword($id) { $user = Account::findOne($id); $model = new ResetPasswordForm($user); if ($model->load(Yii::$app->request->post()) && $model->validate()) { if (!$user->findByPasswordResetToken($model->password_reset_token)) { $model->addError('password_reset_token'); } else { $model->resetPassword(); Yii::$app->session->setFlash('success', 'Смена пароля была произведена успешно'); Yii::$app->user->login($user); return $this->redirect(Yii::$app->getUser()->getReturnUrl($this->goHome())); } } return $this->render('resetPassword', ['model' => $model]); /* try { $model = new ResetPasswordForm($token); } catch (InvalidParamException $e) { throw new BadRequestHttpException($e->getMessage()); } if ($model->load(Yii::$app->request->post()) && $model->validate() && $model->resetPassword()) { Yii::$app->session->setFlash('success', 'New password was saved.'); return $this->goHome(); } return $this->render('resetPassword', [ 'model' => $model, ]); */ }
/** * Returns the account associated with the value of the login attribute. * * @return Account model instance. */ public function getAccount() { if ($this->_account === null) { $this->_account = Account::findOne([Module::getInstance()->phoneAttribute => $this->phone]); } return $this->_account; }
public function actionCarRentals($city_url) { $city = $this->city; $salonModels = Account::getSalonsListModels($this->city); return $this->render('car-rentals', ['salonModels' => $salonModels]); }
public static function createUserDataToSalon($client_id, $salon_id) { $Account = Account::findOne($client_id); $UserData = new UsersData(); $UserData->loadDefaultValues(); $UserData->setAttribute('account_id', $Account->id); $UserData->setAttribute('salon_account_id', $salon_id); $UserData->setAttribute('name', $Account->username); $UserData->setAttribute('phone', $Account->phone); $UserData->save(); return $UserData; }
public function afterDelete() { $Account = Account::findOne(['id' => $this->account_id]); $Account->setAttribute('count_autos', self::getAccountCountAutos($this->account_id)); $Account->save(); return parent::afterDelete(); }
public static function getSalonsListModels($city_name = false, $top = false) { if ($top) { return Account::find()->andFilterWhere(["is_moderated" => '2', "city_name" => $city_name])->andWhere('balance > "-1"')->andWhere('count_autos > "0"')->limit(6)->orderBy(['balance' => SORT_DESC, 'username' => SORT_ASC])->all(); } else { return Account::find()->andFilterWhere(["is_moderated" => '2', "city_name" => $city_name])->orderBy(['balance' => SORT_DESC, 'username' => SORT_ASC])->all(); } }
protected function findModel($id) { if (($model = Account::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
protected function initClassMap() { $this->classMap = ArrayHelper::merge([self::CLASS_ACCOUNT => Account::className()], $this->classMap); }