/** * Recovery password */ public function actionRecovery () { $form = new UserRecoveryForm; if (Y::userId()) { $this->redirect(Y::module()->returnUrl); Y::end(); } $email = isset($_GET['email']) ? $_GET['email'] : ''; $activkey = isset($_GET['activkey']) ? $_GET['activkey'] : ''; if ($email&&$activkey) { //get new pass $find = User::model()->notsafe()->findByAttributes(array('email'=>$email)); if(isset($find)&&$find->activkey==$activkey) { $form2 = new UserChangePassword; if(isset($_POST['UserChangePassword'])) { $form2->attributes=$_POST['UserChangePassword']; if($form2->validate()) { $find->password = UserModule::encrypting($form2->password); if ($find->status==0) { $find->status = 1; } $find->save(); Y::flash('recoveryMessage',Users::t("New password is saved.")); $this->redirect(Y::module()->recoveryUrl); } } $this->render('changepassword',array('form'=>$form2)); } else { Y::flash('recoveryMessage',Users::t("Incorrect recovery link.")); $this->redirect(Y::module()->recoveryUrl); } } else { //send email if(isset($_POST['UserRecoveryForm'])) { $form->attributes=$_POST['UserRecoveryForm']; if($form->validate()) { $user = User::model()->notsafe()->findbyPk($form->user_id); $user->activkey = Y::module()->encrypting(microtime().$user->password); $user->save(); $activation_url = 'http://' . $_SERVER['HTTP_HOST'].$this->siteUrl('user/recovery',array("activkey" => $user->activkey, "email" => urldecode($user->email))); $subject = Users::t("You have requested the password recovery site {site_name}", array( '{site_name}'=>Yii::app()->name, )); $message = Users::t("You have requested the password recovery site {site_name}. To receive a new password, go to {activation_url}.", array( '{site_name}'=>Yii::app()->name, '{activation_url}'=>$activation_url, )); UserModule::sendMail($user->email,$subject,$message); Y::flash('recoveryMessage',Users::t("Please check your email. An instructions was sent to your email address.")); $this->refresh(); } } $this->render('recovery',array('form'=>$form)); } }
public function actionUpdate($dir, $fileName) { if (isset($_POST['fileContent'])) { FileSystem::write('./'.$dir.'/'.$fileName, $_POST['fileContent'], 'w'); Y::end(); } $content = ''; $info = FileSystem::getInfo('./'.$dir.'/'.$fileName, array('name', 'ext')); if (in_array($info['ext'], array('js', 'css'))) { if (substr($dir, 0, 2) == 'js' || substr($dir, 0, 3) == 'css') { $content = FileSystem::read('./'.$dir.'/'.$fileName); } } $output = $this->renderPartial('fileDetails', array( 'fileName' => $fileName, 'content' => $content, 'type' => $info['ext'] == 'css' ? 'css' : 'javascript', 'filePath' => './'.$dir.'/'.$fileName ), true); Y::tab('Содержимое файла', $output); $output = Y::getTabs('cssFileForm', true); Y::clientScript()->render($output); echo CHtml::tag('div', array(), $output); }
public function init() { if(Y::isGuest()) $this->redirect(Admin::url('login')); if(!Y::checkAccess('moderator')) Y::end($this->render('accessDenied')); parent::init(); $folder = Y::asset('admin.assets'); Y::clientScript() ->registerCoreScript('jquery') ->registerCoreScript('jquery.ui'); Y::clientScript()->ajaxExclude(array( 'jquery.js', 'jquery-ui.min.js', 'jquery-ui.css', //treeview 'jquery.treeview.js', 'jquery.cookie.js', 'jquery.treeview.edit.js', 'jquery.treeview.async.js', )); }
/** * Registration user */ public function actionRegistration() { if(Y::module()->isRegistrationClose) $this->redirect('close'); $model = new RegistrationForm; $profile=new Profile; $profile->regMode = true; // ajax validator if(isset($_POST['ajax']) && $_POST['ajax']==='registration-form') Y::end(UActiveForm::validate(array($model,$profile))); if (Y::userId()) { $this->redirect(Y::module()->cabinetUrl); } else { if(isset($_POST['RegistrationForm'])) { $model->attributes=$_POST['RegistrationForm']; $profile->attributes= isset($_POST['Profile'])?$_POST['Profile']:array(); if($model->validate()&&$profile->validate()) { $soucePassword = $model->password; $model->activkey=UserModule::encrypting(microtime().$soucePassword); $model->password=UserModule::encrypting($soucePassword); $model->verifyPassword=UserModule::encrypting($model->verifyPassword); $model->createtime=time(); $model->lastvisit=((Y::module()->loginNotActiv||(Y::module()->activeAfterRegister&&Y::module()->sendActivationMail==false))&&Y::module()->autoLogin)?time():0; $model->superuser=0; $model->status=((Y::module()->activeAfterRegister)?User::STATUS_ACTIVE:User::STATUS_NOACTIVE); if ($model->save()) { $profile->user_id=$model->id; $profile->save(); if (Y::module()->sendActivationMail) { $activation_url = $this->createAbsoluteUrl('/user/activation',array("activkey" => $model->activkey, "email" => $model->email)); UserModule::sendMail($model->email,Users::t("You registered from {site_name}",array('{site_name}'=>Yii::app()->name)),Users::t("Please activate you account go to {activation_url}",array('{activation_url}'=>$activation_url))); } if ((Y::module()->loginNotActiv||(Y::module()->activeAfterRegister&&Y::module()->sendActivationMail==false))&&Y::module()->autoLogin) { $identity=new UserIdentity($model->username,$soucePassword); $identity->authenticate(); Y::user()->login($identity,0); $this->redirect(Y::module()->returnUrl); } else { if (!Y::module()->activeAfterRegister&&!Y::module()->sendActivationMail) { Y::flash('/user/registration',Users::t("Thank you for your registration. Contact Admin to activate your account.")); } elseif(Y::module()->activeAfterRegister&&Y::module()->sendActivationMail==false) { Y::flash('/user/registration',Users::t("Thank you for your registration. Please {{login}}.",array('{{login}}'=>CHtml::link(Users::t('Login'),Y::module()->loginUrl)))); } elseif(Y::module()->loginNotActiv) { Y::flash('/user/registration',Users::t("Thank you for your registration. Please check your email or login.")); } else { Y::flash('/user/registration',Users::t("Thank you for your registration. Please check your email.")); } $this->refresh(); } } } else $profile->validate(); } $this->render('/user/registration',array('model'=>$model,'profile'=>$profile,'lang'=>Yii::app()->language)); } }
public function actionUpdate($catPk, $pk = null, $otherParams = array()) { $model = $this->loadModel($catPk, $pk, 'update'); if (Y::isAjaxRequest()) { //ajax validation $this->performAjaxValidation($model); if (isset($_POST[get_class($model)])) { $model->attributes = $_POST[get_class($model)]; if ($model->save()) Y::hooks()->cmsDataTypeUpdateSuccess($this, array('model'=>$model)); else Y::hooks()->cmsDataTypeUpdateError($this, array('model'=>$model)); } Y::end(); } $opts = CMap::mergeArray($otherParams, array( 'model' => $model )); if (!isset($opts['cat']) && isset($model->category)) $opts['cat'] = $model->category; $this->render('update', $opts); }
protected function renderContent() { $alias = $this->alias; if (($menuRoot = Category::model()->menuRoot($alias)) == null) { Y::end("Параметр alias для menu не верен. Шаблон $alias"); } if ($this->expand) { echo $menuRoot->makeTreeHtml($this->category, true); } else { $params = array( 'items' => $menuRoot->makeMenu($this->category) ); Y::controller()->widget('CMenu', $params); } }
public function renderContent() { if (Y::isAjaxRequest()) { $this->$_GET['do']; Y::end(); } $route = isset($_GET['users']) ? urldecode($_GET['users']) : ''; if (Y::isGuest()) { Yii::app()->runController('users/'.$route); } else { //cabinet $model = $this->module->user(); $this->render('user-info',array( 'model'=>$model, 'profile'=>$model->profile, )); } }
public function run() { if (isset($_GET['rte'])) { $this->tInP($_GET['rte']); Y::end(); } $model = new $_POST['model'](); $cat_id = $_POST['cat_id']; if (isset($_POST['el'], $_POST['cat_id'])) { list($prev, $curr, $next) = explode('.', $_POST['el']); $model->setOrderPositions($prev, $curr, $next, $cat_id); $this->outPocket($this->getName($cat_id), $curr); } if (isset($_POST['in_pocket'])) { $this->inPocket($this->getName($cat_id)); } if (isset($_POST['out_pocket'])) { $this->outPocket($this->getName($cat_id)); } }
/** * Change password */ public function actionChangepassword() { $model = new UserChangePassword; if (Y::userId()) { // ajax validator if(isset($_POST['ajax']) && $_POST['ajax']==='changepassword-form') Y::end(UActiveForm::validate($model)); if(isset($_POST['UserChangePassword'])) { $model->attributes=$_POST['UserChangePassword']; if($model->validate()) { $new_password = User::model()->notsafe()->findbyPk(Y::userId()); $new_password->password = UserModule::encrypting($model->password); $new_password->activkey=UserModule::encrypting(microtime().$model->password); $new_password->save(); Y::flashRedir('profileMessage',Users::t("New password is saved."),$this->module->profileUrl); } } $this->render('changepassword',array('model'=>$model)); } }
public function actionCreate() { if (isset($_POST['newWidgets'])) { $widgets = array(); $transaction = Yii::app()->db->beginTransaction(); foreach ($_POST['newWidgets'] as $class) { $model = TemplateWidget::model(); $model->class = $class; $widgetName = $class.'Widget'; $model->settings = $widgetName::getDefaultSettings(); $widgets[] = $model; } //save all widgets in transaction try { foreach ($widgets as $model) if (!$model->save()) throw new CException('Sorry, adding widgets proved unsuccessful. Try again'); $transaction->commit(); } catch(Exception $e) { $transaction->rollBack(); Y::end(Admin::t($e->getMessage())); } //some output $content = Admin::link('', 'widgets/see', array('pk'=>$model->pk), array('class'=>'widget-preview')); $content.= Admin::link('', 'widgets/settings', array('pk'=>$model->pk), array('class'=>'widget-settings')); $content.= CHtml::tag('div', array(), $model->alias); $content.= Admin::link('x', 'widgets/delete', array('pk'=>$model->pk), array('class'=>'widget-delete')); echo CHtml::tag('li', array('class'=>'widget'), $content); } else { //make list of widgets $widgets = Y::resources()->registeredWidgets; $list = CHtml::listData($widgets, 'pk', 'title'); $this->renderPartial("/widgets/widgetChangeForm", array('widgets'=>$list, 'action'=>Admin::url('widgets/create')), false, true); } }
public function actionBisec() { $c = Yii::app()->db->getCommandBuilder()->createFindCommand('edge', new CDbCriteria(array('condition' => 't.edge="associate"'))); $data = $c->limit(1000)->query(); $n = Node::model()->count(); $tmp = array_fill(0, $n, 10000); $W = array_fill(0, $n, $tmp); $k = 0; foreach ($data as $item) { $i = (int) $item['source']; $j = (int) $item['target']; $W[$i][$j] = $W[$j][$i] = 1; if (++$k > 100) { break; } } Y::end(round(memory_get_peak_usage() / (1024 * 1024), 2) . "MB"); $f = Yii::getPathOfAlias('application') . '/../gr.txt'; Y::dump(file_put_contents($f, json_encode($W))); // Initialization for ($i = 0; $i < $n; $i++) { $W[$i][$i] = INF; } $f = Yii::getPathOfAlias('application') . '/../gr.txt'; Y::dump(file_put_contents($f, json_encode($W))); // Algorithm for ($k = 0; $k < $n; $k++) { for ($i = 0; $i < $n; $i++) { for ($j = 0; $j < $n; $j++) { $W[$i][$j] = min($W[$i][$j], $W[$i][$k] + $W[$k][$j]); } } if ($k == 10) { break; } } Y::end($W); }
public function actionIndex() { $a = file_get_contents('php://input'); echo Y::end(CJSON::decode($a)); }
/** * Ярлык для функции dump класса CVarDumper для отладки приложения * @param mixed $var переменная для вывода * @param boolean $toDie остановить ли дальнейшее выполнение приложения, по умолчанию - true */ public static function dump($var, $skipCount = 0, $depth = 2) { if (self::$startSkipCount == 0) self::$startSkipCount = self::$skipCount = $skipCount; else self::$skipCount--; if (self::$skipCount == 0) { self::$startSkipCount = 0; echo '<pre>'; CVarDumper::dump($var, $depth, true); echo '</pre>'; // Y::end(debug_backtrace()); Y::end(); } }
public function actionGetRelevantCategories() { if (!Y::isAjaxRequest()) Y::end(); if(!isset($_POST['catId'])) throw new CException("Не найден параметр catId"); if(!isset($_POST['action'])) throw new CException("Не найден параметр catId"); $cat = Category::model()->findByPk($_POST['catId']); $name = ModelFactory::t($cat->type); if (ModelFactory::isAllowCopy($cat->type)) { echo "<p>Категория имеет тип '$name', поэтому все '$name' могут быть скопированы в одну из следующих категорий.</p>". "<hr/><p>Все шаблоны с одинаковыми алиасами будут утеряны</p>"; } else { echo "Категория имеет тип '$name', данные такого типа не могут быть сохранены в другой категории."; Y::end(); } $cats = Category::model()->findAll("type='".$cat->type."' AND id!=".$cat->pk); $res = '<ul>'; foreach ($cats as $target) { if ($_POST['action'] == 'copy') $res .= '<li>'.$cat->getCopyDataLink($target).'</li>'; elseif ($_POST['action'] == 'cut') $res .= '<li>'.$cat->getCutDataLink($target).'</li>'; } echo $res.'</ul>'; }
/** * set $model->$field in next value, using $values array * @param string $query_id * @param model $model * @param string $field * @param array $values */ protected function ajaxSetNextValue($query_id, $model, $field, $values) { if (Y::isAjaxRequest() && isset($_GET[$query_id])){ $model->scenario = $query_id; $model = $model->find(array('condition' => $model->idAttr . '=' . (int)$_GET['model_id'])); //cycle shift while ($model->$field != ($values[] = array_shift($values))) {} //set next value $model->$field = array_shift($values); if ($model->save()) echo $model->$field; else print_r($model->getErrors()); Y::end(); } }