示例#1
0
 /**
  * AJAX
  * Создает подписку для авторизованного или неавторизованного пользователя
  * Высылает письмо подтверждения email
  *
  * @return string json
  *                error
  *                101, 'Такая почта уже зарегистрирована'
  */
 public function actionMail()
 {
     $email = self::getParam('email');
     $name = self::getParam('name');
     if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
         return self::jsonErrorId(101, 'Не корректный формат адреса');
     }
     $email = strtolower($email);
     $user = User::find(['email' => $email, 'subscribe_is_tesla' => 1]);
     if ($user) {
         $user->update(['subscribe_is_tesla' => 1]);
     } else {
         $fields = ['email' => $email, 'datetime_reg' => gmdate('YmdHis'), 'is_active' => 1, 'is_confirm' => 0, 'name_first' => $name, 'subscribe_is_tesla' => 1];
         $user = User::insert($fields);
         $fields = RegistrationDispatcher::add($user->getId());
         \cs\Application::mail($email, 'Подтверждение почты', 'subscribe_activate', ['url' => Url::to(['subscribe/activate', 'code' => $fields['code']], true), 'user' => $user, 'datetime' => \Yii::$app->formatter->asDatetime($fields['date_finish'])]);
     }
     return self::jsonSuccess();
 }
示例#2
0
 /**
  * Делает заказ
  *
  * @param  int $id идентификатор генератора
  *
  * @return boolean whether the model passes validation
  */
 public function insert($fieldsCols = null)
 {
     $id = $fieldsCols;
     $request = parent::insert(['beforeInsert' => function ($fields) {
         $fields['email'] = strtolower($fields['email']);
         $fields['datetime'] = time();
         $fields['status'] = \app\models\Request::STATUS_1_WAIT;
         return $fields;
     }]);
     if ($request === false) {
         return false;
     }
     $request['product_id'] = $id;
     $this->email = strtolower($this->email);
     if (!Yii::$app->user->isGuest) {
         $user = Yii::$app->user->identity;
         $request = new \app\models\Request($request);
         $request->update(['user_id' => Yii::$app->user->getId(), 'product_id' => $id]);
         // письмо клиенту
         $result = \cs\Application::mail($user->getEmail(), 'Вы сделали очередной заказ', 'next_request_client', ['user' => $user, 'request' => $request]);
     } else {
         $fields = ['email' => $this->email, 'datetime_reg' => gmdate('YmdHis'), 'is_active' => 1, 'is_confirm' => 0, 'subscribe_is_tesla' => 1, 'name_first' => $this->name, 'phone' => $this->phone];
         $user = User::insert($fields);
         $fields = \app\services\RegistrationDispatcher::add($user->getId());
         $request = new \app\models\Request($request);
         $request->update(['user_id' => $user->getId(), 'product_id' => $id]);
         // письмо им
         \cs\Application::mail($this->email, 'Поздравляем вы сделали первый шаг к своему полю коллективного счастья', 'new_request_client', ['url' => Url::to(['site/activate', 'code' => $fields['code']], true), 'user' => $user, 'request' => $request]);
     }
     foreach (\Yii::$app->params['requestMailList'] as $item) {
         // письмо нам
         $result = Application::mail($item, 'Появился заказ на TeslaGen', 'new_request', ['request' => $request, 'user' => $user]);
         //            VarDumper::dump([$result,$item]);
     }
     return $request;
 }
示例#3
0
 /**
  * AJAX
  * Создает подписку для авторизованного или неавторизованного пользователя
  * Высылает письмо подтверждения email
  *
  * @return string json
  *                error
  *                101, 'Такая почта уже зарегистрирована'
  */
 public function actionMail()
 {
     $email = self::getParam('email');
     $name = self::getParam('name');
     $email = strtolower($email);
     if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
         return self::jsonErrorId(101, 'Не корректная почта');
     }
     if (User::query(['email' => $email])->exists()) {
         return self::jsonErrorId(101, 'Такая почта уже зарегистрирована');
     }
     if (Yii::$app->user->isGuest) {
         $fields = ['email' => $email, 'datetime_reg' => gmdate('YmdHis'), 'is_active' => 0, 'is_confirm' => 0, 'name_first' => $name];
         foreach (Subscribe::$userFieldList as $field) {
             $fields[$field] = 1;
         }
         $user = User::insert($fields);
     } else {
         /** @var \app\models\User $user */
         $user = Yii::$app->user->identity;
         $fields = ['email' => $email, 'datetime_reg' => gmdate('YmdHis'), 'is_active' => 0, 'is_confirm' => 0];
         foreach (Subscribe::$userFieldList as $field) {
             $fields[$field] = 1;
         }
         $user->update($fields);
     }
     $fields = RegistrationDispatcher::add($user->getId());
     \cs\Application::mail($email, 'Подтверждение почты', 'subscribe_activate', ['url' => Url::to(['subscribe/activate', 'code' => $fields['code']], true), 'user' => $user, 'datetime' => \Yii::$app->formatter->asDatetime($fields['date_finish'])]);
     return self::jsonSuccess();
 }
示例#4
0
 /**
  * Регистрирует пользователей
  *
  * @param $email
  * @param $password
  *
  * @return static
  */
 public static function registration($email, $password)
 {
     $email = strtolower($email);
     $fields = ['email' => $email, 'password' => self::hashPassword($password), 'is_active' => 0, 'is_confirm' => 0, 'datetime_reg' => gmdate('YmdHis'), 'referal_code' => Security::generateRandomString(20)];
     // добавляю поля для подписки
     foreach (\app\services\Subscribe::$userFieldList as $field) {
         $fields[$field] = 1;
     }
     \Yii::info('REQUEST: ' . \yii\helpers\VarDumper::dumpAsString($_REQUEST), 'gs\\user_registration');
     \Yii::info('Поля для регистрации: ' . \yii\helpers\VarDumper::dumpAsString($fields), 'gs\\user_registration');
     $user = self::insert($fields);
     $fields = RegistrationDispatcher::add($user->getId());
     \cs\Application::mail($email, 'Подтверждение регистрации', 'registration', ['url' => Url::to(['auth/registration_activate', 'code' => $fields['code']], true), 'user' => $user, 'datetime' => \Yii::$app->formatter->asDatetime($fields['date_finish'])]);
     return $user;
 }
示例#5
0
文件: User.php 项目: dram1008/bogdan
 /**
  * Регистрирует пользователей
  *
  * @param $email
  * @param $password
  * @param $fields
  *
  * @return static
  */
 public static function registration($email, $password, $fields = [])
 {
     $email = strtolower($email);
     $fields = ArrayHelper::merge($fields, ['email' => $email, 'password' => self::hashPassword($password), 'is_active' => 1, 'is_confirm' => 0, 'datetime_reg' => gmdate('YmdHis'), 'referal_code' => Security::generateRandomString(20), 'subscribe_is_bogdan' => 1]);
     $user = self::insert($fields);
     $fields = \app\services\RegistrationDispatcher::add($user->getId());
     \cs\Application::mail($email, 'Подтверждение регистрации', 'registration', ['url' => Url::to(['auth/registration_activate', 'code' => $fields['code']], true), 'user' => $user, 'password' => $password, 'datetime' => \Yii::$app->formatter->asDatetime($fields['date_finish'])]);
     return $user;
 }