public function actionIndex() { if (!Yii::app()->user->isGuest) { $message = ""; Yii::app()->page->title = Yii::t("user", "Избранное"); $userModel = CatalogUsers::fetch(Yii::app()->user->id); $del = (int) Yii::app()->request->getParam("del", 0); if ($del > 0) { Yii::app()->favorites->delete($del, "catalog_items"); } $list = Yii::app()->favorites->getListId("catalog=:catalog", array(":catalog" => "catalog_items")); if (sizeof($list) > 0) { $sql = " ( "; foreach ($list as $key => $value) { if ($sql != " ( ") { $sql .= " OR "; } $sql .= "id='" . $value . "'"; } $sql .= " )"; $items = CatalogItems::fetchAll(DBQueryParamsClass::CreateParams()->setConditions("status_id=1")->setConditions($sql)->setCache(0)); } else { $items = array(); } $this->render("index", array("message" => $message, "items" => $items, "userModel" => $userModel)); } }
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 beforeAction($action) { if (Yii::app()->user->isGuest) { $controller = Yii::app()->controller->getId(); if ($controller != "default" || $action->getId() != 'login' && $action->getId() != 'index' && $action->getId() != 'captcha') { $this->redirect('/console/default/login'); } } else { $userModel = CatalogUsers::fetch(Yii::app()->user->id); if (!$userModel || !$userModel->type_id) { Yii::app()->user->logout(); $this->redirect('/console/default/login'); } if ($userModel->type_id->id == 1) { $this->redirect('/'); } } /* if ($this->getBackendUser()->getState('expires') > 0 && $this->getBackendUser()->getState('expires') < time()) { $this->getBackendUser()->logout(false); $this->redirect('/console'); } else { $this->checkAccess(); }*/ return parent::beforeAction($action); }
public function checked_exists_user($attribute, $params) { if (!$this->hasErrors() && !empty($this->user_id) && $this->user_id > 0) { $exists = CatalogUsers::fetch($this->user_id); if (sizeof($exists) == 0) { $this->addErrors(array("0" => Yii::t("models", "Указан не существующий ID пользователя"))); } } }
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" => "У вас нет доступа для данного раздела")); } } }
public static function getAmount(CatalogUsers $user = null) { if (empty($user)) { $user = CatalogUsers::fetch(Yii::app()->user->id); } $amount = $user->amount; if (empty($amount)) { $amount = 0; } return $amount; }
public function actionIndex() { if (!Yii::app()->user->isGuest) { Yii::app()->page->title = "Мои заказы"; $user = CatalogUsers::fetch(Yii::app()->user->id); $orders = OrderRequest::fetchAll(DBQueryParamsClass::CreateParams()->setCache(0)->setConditions("user_id=:user_id")->setParams(array(":user_id" => Yii::app()->user->id))->setLimit(200)->setOrderBy("date")); $this->render("index", array("user" => $user, "orders" => $orders)); } else { $this->redirect(SiteHelper::createUrl("/")); } }
/** * 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 actionIndex() { if (!Yii::app()->user->isGuest) { $message = ""; Yii::app()->page->title = Yii::t("user", "Рабочий стол"); $userModel = CatalogUsers::fetch(Yii::app()->user->id); if (!empty($_POST["desktop_save"])) { $desktopID = (int) Yii::app()->request->getParam("desktopID", 0); $userModel->desktop = $desktopID; $userModel->save(); $userModel->formMessage = Yii::t("user", "Рабочий стол успешно сохранен"); } $items = CatalogDesktops::fetchAll(DBQueryParamsClass::CreateParams()->setCache(0)); $this->render("index", array("message" => $message, "items" => $items, "userModel" => $userModel)); } }
public function check_passwords($attribute, $params) { if (!$this->hasErrors()) { $key = !empty($_GET["key"]) ? SiteHelper::checkedVaribal($_GET["key"], "string") : ""; $confirm = CatalogUsersConfirm::findByAttributes(array("confirm_key" => $key)); if (!empty($confirm) && sizeof($confirm) == 1) { $userModel = CatalogUsers::fetch($confirm[0]->user_id->id); if ($userModel->active == 0) { $error = Yii::t("models", "Ваш аккаунт не активирован"); } } else { $error = Yii::t("models", "Указан не верный ключ"); } if (!empty($error)) { $this->addErrors(array("0" => $error)); } else { $confirm[0]->delete(); } } }
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 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")); }
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 run($args) { $countLimit = SiteHelper::getConfig("subscribee_count_send"); $emails = array(); $countSend = 0; $res = SubscribeItems::findByAttributes(array("status_id" => 2)); foreach ($res as $line) { // 1 - отправляем и зарегеным и подписчикам if ($line->users == 1 || $line->users == 2) { $lisUsers = CatalogUsers::sql("SELECT u.* FROM catalog_users u WHERE `active`=1 AND subscribe=1 AND !exists( SELECT id FROM subscribe_send WHERE email=u.email AND item_id='" . $line->id . "' AND is_reg=1 ) LIMIT " . $countLimit); foreach ($lisUsers as $userLine) { $emails[] = array("email" => $userLine["email"], "name" => $userLine["name"]); $newSend = new SubscribeSend(); $newSend->item_id = $line->id; $newSend->user_id = $userLine["id"]; $newSend->email = $userLine["email"]; $newSend->is_reg = 1; if (!$newSend->save()) { print_r($newSend->getErrors()); } } } if (sizeof($emails) < $countLimit && ($line->users == 1 || $line->users == 3)) { $lisUsers = CatalogUsers::sql("SELECT u.* FROM subscribe_users u WHERE !exists( SELECT id FROM subscribe_send WHERE email=u.email AND item_id='" . $line->id . "' AND is_reg=0 ) LIMIT " . ($countLimit - sizeof($emails))); foreach ($lisUsers as $userLine) { $emails[] = array("email" => $userLine["email"], "name" => $userLine["name"]); $newSend = new SubscribeSend(); $newSend->item_id = $line->id; $newSend->user_id = null; $newSend->email = $userLine["email"]; $newSend->is_reg = 0; if (!$newSend->save()) { print_r($newSend->getErrors()); } } } if ($line->users == 4) { $usersList = trim(strip_tags($line->users_list)); if (!empty($usersList)) { $listEmail = explode(",", $usersList); for ($m = 0; $m < sizeof($listEmail); $m++) { $listEmail[$m] = trim($listEmail[$m]); $ext = SubscribeSend::findByAttributes(array("item_id" => $line->id, "email" => $listEmail[$m])); if (sizeof($ext) == 0) { $emails[] = array("email" => $listEmail[$m], "name" => "пользователь"); $newSend = new SubscribeSend(); $newSend->item_id = $line->id; $newSend->user_id = null; $newSend->email = $listEmail[$m]; $newSend->is_reg = 0; if (!$newSend->save()) { print_r($newSend->getErrors()); } } } } } if (sizeof($emails) > 0) { for ($n = 0; $n < sizeof($emails); $n++) { $countSend++; $message = $line->description; $message = str_replace("@user_name@", $emails[$n]["name"], $message); SiteHelper::mailto($line->subject, $line->from, $emails[$n]["email"], stripslashes($message), "", "", array("<!-- @openSubscribeLink@ -->" => "<img src=\"" . Yii::app()->params["baseUrl"] . "site/subscribeOpen/subscribe/" . $line->id . "/email/" . $emails[$n]["email"] . "\" alt=\"\" style=\"width:0px;height:0px\" />")); } } // Сохраняем количество оптравленных, чтобы не считать каждый раз if ($countSend > 0) { $line->count_send += $countSend; $line->save(); } // Если адресатов нет или их количество меньше чем лимит то финализируем рассылку if (sizeof($emails) == 0 || $countSend < $countLimit) { $line->status_id = 3; $line->save(); } } }
static function lostPasswordConfirm($event) { $userSender = $event->sender[0]; $user = CatalogUsers::fetch($userSender->user_id->id); $user->password = md5($_POST["CatalogUsersLostConfirm"]["password"]); $user->save(); SiteHelper::setLog("catalog_users", "lost_password", $user->id); if ($user->hasErrors() && sizeof($user) > 0) { $errors = "Ошибка сохранение нового пароля: "; foreach ($user->getErrors() as $data) { foreach ($data as $key => $value) { $errors .= $value . ", "; } } throw new Exception($errors); } else { // Отправляем письмо уведомления о смене пароля Yii::app()->notifications->send("lostpassword_save", ["mail"], $user->id); } }
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <?php $this->renderPartial('//layouts/header'); ?> </head> <?php Yii::app()->session["otherStyle"] = false; $mainClass = ""; if (Yii::app()->controller->getId() != "site") { $mainClass = "MInnerPage"; } if (!Yii::app()->user->isGuest) { $userModel = CatalogUsers::fetch(Yii::app()->user->getId()); if ($userModel->desktop->id > 0 && $userModel->desktop->class_name) { if (!empty($mainClass)) { $mainClass .= " "; } $mainClass .= "otherStyle " . $userModel->desktop->class_name; Yii::app()->session["otherStyle"] = true; } } ?> <body> <div id="Main" <?php echo !empty($mainClass) ? ' class="' . $mainClass . '"' : ''; ?> >
public function actionGetUserInfo() { $id = (int) Yii::app()->request->getParam("id", 0); $field = Yii::app()->request->getParam("field", ""); if ($id > 0 && !empty($field)) { $userModel = CatalogUsers::fetch($id); if ($userModel->id > 0 && property_exists($userModel, $field)) { Yii::app()->ih->load($_SERVER['DOCUMENT_ROOT'] . '/f/temp/1.jpg')->text($userModel->{$field}, $_SERVER['DOCUMENT_ROOT'] . '/themes/classic/font/georgia.ttf', 11, array(2, 95, 160), CImageHandler::CORNER_LEFT_BOTTOM, 3, 3)->save($_SERVER['DOCUMENT_ROOT'] . '/f/temp/2.jpg'); echo '<img src="/f/temp/2.jpg" />'; } } }
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; }
<th>Все пользователи:</th> <td><input type="radio" name="SubscribeItems[users]" <?php echo $form->users == 1 ? "checked" : ""; ?> value="1" /> - <?php echo CatalogUsers::count(DBQueryParamsClass::CreateParams()->setLimit(-1)) + SubscribeUsers::count(DBQueryParamsClass::CreateParams()->setLimit(-1)); ?> </td> </tr> <tr> <th>Зерегестрированные пользователи:</th> <td><input type="radio" name="SubscribeItems[users]" <?php echo $form->users == 2 ? "checked" : ""; ?> value="2" /> - <?php echo CatalogUsers::count(DBQueryParamsClass::CreateParams()->setLimit(-1)); ?> </td> </tr> <tr> <th>Потенциальные пользователи:</th> <td><input type="radio" name="SubscribeItems[users]" <?php echo $form->users == 3 ? "checked" : ""; ?> value="3" /> - <?php echo SubscribeUsers::count(DBQueryParamsClass::CreateParams()->setLimit(-1)); ?> </td> </tr> <tr> <th>Определенные адрессаты:</th>
public static function step2() { $userModel = CatalogUsers::fetch(Yii::app()->user->getId()); Yii::app()->controller->widget("trainingsWidget", array("template" => "trainings_2Step", "param" => array("type_id" => $userModel->type_id->id))); }
public function updatePasswordHashMD5($attribute, $params) { if (!$this->hasErrors()) { $DBUser = CatalogUsers::fetch(Yii::app()->user->id); if ($this->password != $DBUser->password) { $this->password = md5($this->password); } } }
public function render($view, $data = array(), $return = false) { if ($this->beforeRender($view)) { if (!Yii::app()->user->isGuest) { $userModel = CatalogUsers::fetch(Yii::app()->user->getId()); if ($userModel->id > 0) { $USER = $userModel; } else { Yii::app()->user->logout(); $this->redirect(SiteHelper::createUrl("/")); } } else { $USER = new CatalogUsers(); } $data = array_merge($data, array("Theme" => Yii::app()->getTheme(), "controller" => $this, "USER" => $USER)); $output = $this->renderPartial($view, $data, true); if (($layoutFile = $this->getLayoutFile($this->layout)) !== false) { $output = $this->renderFile($layoutFile, array_merge($data, array("content" => $output)), true); } $this->afterRender($view, $output); $output = $this->processOutput($output); if ($return) { return $output; } else { echo $output; } } }
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)); } } }