Example #1
0
 public function authenticate()
 {
     $arrRecord = CatalogUsers::findByAttributes(array('email' => $this->username), 0);
     if (!empty($arrRecord) && sizeof($arrRecord) > 0) {
         $record = $arrRecord[0];
     } else {
         $record = null;
     }
     if ($record === null) {
         $this->errorCode = self::ERROR_USERNAME_INVALID;
         $this->errorMessage = "Вы ввели не правельный логин или пароль";
     } else {
         if ($record->password != md5($this->password)) {
             $this->errorCode = self::ERROR_PASSWORD_INVALID;
             $this->errorMessage = "Вы ввели не правельный логин или пароль";
         } else {
             if ($record->active == 1) {
                 $this->_id = $record->id;
                 $this->setState('title', $record->name);
                 $this->errorCode = self::ERROR_NONE;
             } else {
                 $this->errorMessage = "Ваш аккаунт не активен, обратитесь пожалуйста к администратору";
                 $this->errorCode = self::ERROR_UNKNOWN_IDENTITY;
             }
         }
     }
     return $this->errorCode;
 }
 public function check_type($attribute, $params)
 {
     if (!$this->hasErrors()) {
         $user = CatalogUsers::findByAttributes(array("email" => $this->email, "password" => md5($this->password)));
         $consoleType = CatalogUsersType::fetchByKeyWord("console");
         if ($user[0]->type_id != $consoleType->id) {
             $this->addErrors(array("0" => "У вас нет доступа для данного раздела"));
         }
     }
 }
Example #3
0
 /**
  * This is the default 'index' action that is invoked
  * when an action is not explicitly requested by users.
  */
 public function actionCheckUsers()
 {
     $this->render("index");
     $res = CatalogFirms::fetchAll(DBQueryParamsClass::CreateParams()->setConditions("email!='' AND user_id=0")->setLimit(-1)->setCache(0));
     $i = 0;
     foreach ($res as $item) {
         $email = "";
         if (strpos($item->email, ",")) {
             $item->email = trim(mb_substr($item->email, 0, strpos($item->email, ","), "utf-8"));
         }
         echo $item->id . " | " . $item->name . " - " . $item->email . "<br/>";
         $findUser = CatalogUsers::findByAttributes(array("email" => $item->email));
         if (sizeof($findUser) == 0) {
             echo "Create";
             $newUser = new CatalogUsers();
             $newUser->name = $item->name;
             $newUser->email = trim($item->email);
             $newUser->image = $item->image;
             $newUser->pass = rand(100, 999);
             $newUser->password = md5($newUser->pass);
             $newUser->active = 1;
             $newUser->country_id = $item->country_id->id;
             $newUser->type_id = 1;
             $newUser->site = $item->www;
             $newUser->phone = $item->tel;
             if (!$newUser->save()) {
                 print_r($newUser->getErrors());
             }
         } else {
             echo "Find - " . $findUser[0]->id;
             $newUser = $findUser[0];
         }
         if ($newUser->id > 0) {
             echo " save";
             $item->user_id = $newUser->id;
             $item->save();
         }
         echo "<br/>";
         $i++;
     }
 }
 public function check_exists_params($attribute, $params)
 {
     if (!$this->hasErrors()) {
         $userList = CatalogUsers::findByAttributes(array("email" => $this->email), 0);
         if (!empty($userList) && sizeof($userList) == 1) {
             // Если в базе уже сужествует запросы на восстановление, до удаляем его
             $existConfirm = CatalogUsersConfirm::findByAttributes(array("user_id" => $userList[0]->id, "type" => "lostpassword"));
             if (sizeof($existConfirm) > 0) {
                 $existConfirm[0]->delete();
             }
             if ($userList[0]->active == 0) {
                 $error = Yii::t("models", "Ваш аккаунт не активирован");
             }
         } else {
             $error = Yii::t("models", "Вы ввели не существующий EMAIL");
         }
         if (!empty($error)) {
             $this->addErrors(array("0" => $error));
         }
     }
 }
 public function send($key, $types, $userId, array $arrayParams = array())
 {
     $status = false;
     $notification = NotificationsType::fetchAll(DBQueryParamsClass::CreateParams()->setConditions("`key`=:key")->setParams(array(":key" => $key)));
     if (!empty($notification) && sizeof($notification) > 0) {
         $notificationMessage = NotificationsActions::fetchAll(DBQueryParamsClass::CreateParams()->setCache(0)->setConditions("type_id=:type_id")->setParams(array(":type_id" => $notification[0]->id)));
         if (!empty($notificationMessage) && sizeof($notificationMessage) > 0) {
             for ($i = 0; $i < sizeof($notificationMessage); $i++) {
                 if (strtolower($notificationMessage[$i]->key_word) == "info") {
                     $NItem = new Notifications();
                     $NItem->type_id = $notification[0]->id;
                     $NItem->is_new = 1;
                     $NItem->action_id = $notificationMessage[$i]->id;
                     $message = $notificationMessage[$i]->mesage;
                     $subject = $notificationMessage[$i]->subject;
                     foreach ($arrayParams as $key => $value) {
                         $message = str_replace("{" . $key . "}", $value, $message);
                         $subject = str_replace("{" . $key . "}", $value, $subject);
                     }
                     $NItem->message = $message;
                     $NItem->subject = $subject;
                     if (!$notificationMessage[$i]->to_user) {
                         $NItem->user_id = $userId;
                     } else {
                         $toUserModel = CatalogUsers::findByAttributes(array("email" => $notificationMessage[$i]->to_user));
                         if ($toUserModel[0]->id > 0) {
                             $NItem->user_id = $toUserModel[0]->id;
                         } else {
                             $this->errors[] = array("Ошибка обработки действвий", "Событие: #" . $notification[$i] . ", Действие: #" . $notificationMessage[$i] . " - Email указыыный в поле TO_USER не зарегестрирован в базе");
                         }
                     }
                     $NItem->date = time();
                     if (!empty($arrayParams["catalog"])) {
                         $NItem->catalog = $arrayParams["catalog"];
                     }
                     if (!empty($arrayParams["item_id"])) {
                         $NItem->item_id = $arrayParams["item_id"];
                     }
                     if (sizeof($this->errors) == 0) {
                         if (!$NItem->save()) {
                             $this->errors[] = print_r($NItem->getErrors(), true);
                         }
                     }
                 }
                 if (strtolower($notificationMessage[$i]->key_word) == "mail") {
                     if (!$notificationMessage[$i]->to_user) {
                         $userTo = CatalogUsers::fetch($userId);
                     } else {
                         $toUserModel = CatalogUsers::findByAttributes(array("email" => $notificationMessage[$i]->to_user));
                         if ($toUserModel[0]->id > 0) {
                             $userTo = $toUserModel[0];
                         } else {
                             $this->errors[] = array("Ошибка обработки действвий", "Событие: #" . $notification[$i] . ", Действие: #" . $notificationMessage[$i] . " - Email указыыный в поле TO_USER не зарегестрирован в базе");
                         }
                     }
                     if (!empty($userTo) && $userTo->id > 0) {
                         $messages = $notificationMessage[$i]->mesage;
                         foreach ($arrayParams as $key => $value) {
                             $messages = str_replace("{" . $key . "}", $value, $messages);
                         }
                         SiteHelper::mailto($notificationMessage[$i]->subject, $notificationMessage[$i]->send_from, $userTo->email, $messages, $notificationMessage[$i]->copy_sender);
                         $status = true;
                     } else {
                         $this->errors[] = array("Ошибка отправки сообщения", "Указан не верный ID пользователя");
                         return false;
                     }
                 }
             }
         } else {
             $this->errors[] = array("Ошибка события", "Для данного соьытия ( #" . $notification[0]->id . " ) не указы события");
         }
     } else {
         $this->errors[] = array("Ошибка события", "Ошибка определения типа события");
     }
     if (is_array($this->errors) && sizeof($this->errors) > 0) {
         throw new Exception(print_r($this->errors, true));
     }
     return $status;
 }
Example #6
0
 public function actionUnSubscribe()
 {
     $email = Yii::app()->request->getParam("email", "");
     $hash = Yii::app()->request->getParam("hash", "");
     $hashCheck = substr(md5(md5($email)), 3, 8);
     $error = "";
     if ($hash == $hashCheck) {
         Yii::import("modules.subscribe.models.*");
         $emailModel = CatalogUsers::findByAttributes(["email" => $email]);
         if ($emailModel[0]->subscribe == 1) {
             $emailModel[0]->subscribe = 0;
             $emailModel[0]->save();
         }
         $emailModel2 = SubscribeUsers::findByAttributes(["email" => $email]);
         if (sizeof($emailModel2)) {
             $emailModel2[0]->delete();
         }
         $this->render("unSubscribe");
     } else {
         throw new CHttpException("Ошибка", Yii::t("page", "Неправильный адрес, проверьте адрес") . ".");
     }
 }
 public function actionUserUpdate()
 {
     $id = (int) Yii::app()->request->getParam("id", 0);
     if (!empty($id)) {
         $model = SubscribeUsers::fetch($id);
     } else {
         $model = new SubscribeUsers();
     }
     $message = "";
     // Сохрание полей
     if (isset($_POST["SubscribeUsers"])) {
         $model->setAttributesFromArray($_POST["SubscribeUsers"]);
         // проверяем email среди уже существующих
         $checkEmail = CatalogUsers::findByAttributes(array("email" => $model->email));
         if (sizeof($checkEmail) == 0) {
             if ($model->save()) {
                 $this->redirect(SiteHelper::createUrl("/console/subscribe/userEdit", array("id" => $model->id, "save" => "ok")));
             } else {
                 $this->actionUserEdit(print_r($model->getErrors(), true));
             }
         } else {
             $this->actionUserEdit(print_r("Такой Email уже зарегестрирован в системе", true));
         }
     }
 }
 public function actionResend()
 {
     $email = SiteHelper::checkedVaribal(Yii::app()->request->getParam("email", ""), "string");
     if (!empty($email)) {
         $userModel = CatalogUsers::findByAttributes(array("email" => $email));
         if (is_array($userModel) && sizeof($userModel) > 0 && $userModel[0]->active == 0) {
             $userModel[0]->onRegistration(new CModelEvent($userModel[0]), array());
             $this->render("resend", array("user" => $userModel));
         }
     }
     //        die;
     $this->redirect(SiteHelper::createUrl("/user"));
 }