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;
 }
Ejemplo n.º 2
0
 /**
  * @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;
 }
Ejemplo n.º 3
0
 /**
  * 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;
 }
Ejemplo n.º 4
0
 /**
  * @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]);
 }
Ejemplo n.º 5
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getAccount()
 {
     return $this->hasOne(Account::className(), ['id' => 'account_id']);
 }
Ejemplo n.º 6
0
 /**
  * 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,
     ]);
     */
 }
Ejemplo n.º 7
0
 /**
  * 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;
 }
Ejemplo n.º 8
0
 public function actionCarRentals($city_url)
 {
     $city = $this->city;
     $salonModels = Account::getSalonsListModels($this->city);
     return $this->render('car-rentals', ['salonModels' => $salonModels]);
 }
Ejemplo n.º 9
0
 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;
 }
Ejemplo n.º 10
0
 public function afterDelete()
 {
     $Account = Account::findOne(['id' => $this->account_id]);
     $Account->setAttribute('count_autos', self::getAccountCountAutos($this->account_id));
     $Account->save();
     return parent::afterDelete();
 }
Ejemplo n.º 11
0
 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();
     }
 }
Ejemplo n.º 12
0
 protected function findModel($id)
 {
     if (($model = Account::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Ejemplo n.º 13
0
 protected function initClassMap()
 {
     $this->classMap = ArrayHelper::merge([self::CLASS_ACCOUNT => Account::className()], $this->classMap);
 }