/**
  * @param $_GET['redirect'] should be urlencoded
  * @param $_POST['LoginForm'] data to login
  */
 public function actionIndex($ref = null)
 {
     if (!empty($ref)) {
         Yii::$app->session->set('accountRef', $ref);
     }
     if (!$this->module->getUserIdentity()->isGuest) {
         if (Yii::$app->session->get('accountRef')) {
             $url = Yii::$app->session->get('accountRef');
             Yii::$app->session->remove('accountRef');
         } else {
             $url = Url::toManager('account/settings/index');
         }
         $this->redirect($url);
     }
     $model = new LoginForm();
     // see if values are sent via post
     if (Yii::$app->request->post('LoginForm')) {
         $model->attributes = Yii::$app->request->post('LoginForm');
         if (($userObject = $model->login()) !== false) {
             if ($this->module->getUserIdentity()->login($userObject)) {
                 $url = Yii::$app->session->get('accountRef');
                 if (!$url) {
                     $url = Url::toManager('account/settings/index');
                 } else {
                     Yii::$app->session->remove('accountRef');
                 }
                 $this->redirect($url);
             }
         }
     }
     return $this->renderLayout('index', ['model' => $model]);
 }
Пример #2
0
 public function getDetailUrl($contextNavItemId = null)
 {
     if ($contextNavItemId) {
         return \cms\helpers\Url::toMenuItem($contextNavItemId, 'news/default/detail', ['id' => $this->id, 'title' => \yii\helpers\Inflector::slug($this->title)]);
     }
     return \luya\helpers\Url::toManager('news/default/detail', ['id' => $this->id, 'title' => \yii\helpers\Inflector::slug($this->title)]);
 }
Пример #3
0
 public function getDetailUrl($contextNavItemId = null)
 {
     if ($contextNavItemId) {
         return \luya\helpers\Url::toModule($contextNavItemId, 'gallery/album/index', ['albumId' => $this->id, 'title' => \yii\helpers\Inflector::slug($this->title)]);
     }
     return \luya\helpers\Url::to('gallery/album/index', ['albumId' => $this->id, 'title' => \yii\helpers\Inflector::slug($this->title)]);
 }
Пример #4
0
 public function testAjaxStaticHelper()
 {
     Yii::$app->request->baseUrl = '';
     $this->assertEquals('/de/not/exists/action', Url::toAjax('not/exists/action'));
     Yii::$app->composition->hidden = true;
     $this->assertEquals('/not/exists/action', Url::toAjax('not/exists/action'));
 }
 public function actionIndex()
 {
     Yii::$app->session->removeAll();
     if (YII_ENV_DEV && YII_DEBUG) {
         $process = new PaymentProcess(['amount' => 200, 'orderId' => 'Order-' . uniqid(), 'currency' => 'CHF', 'successLink' => Url::toRoute(['/payment/test/test-success'], true), 'errorLink' => Url::toRoute(['/payment/test/test-error'], true), 'abortLink' => Url::toRoute(['/payment/test/test-abort'], true), 'transactionConfig' => []]);
         Yii::$app->session->set('storeTransactionId', $process->getId());
         return $process->dispatch($this);
     }
 }
Пример #6
0
 public function actionIndex()
 {
     // redirect logged in users
     if (!Yii::$app->adminuser->isGuest) {
         return $this->redirect(['/admin/default/index']);
     }
     $this->view->registerJs("\$(function(){ \$('#email').focus(); observeLogin('#loginForm', '" . Url::toAjax('admin/login/async') . "', '" . Url::toAjax('admin/login/async-token') . "'); });", \luya\web\View::POS_END);
     return $this->render('index');
 }
Пример #7
0
 public function getBaseUrl()
 {
     $base = $this->getCrawler()->filter('base');
     $data = $base->extract(array('href'));
     if (isset($data[0])) {
         return Url::trailing($data[0]);
     }
     return false;
 }
Пример #8
0
 public function testHelperEqualsAbsoluteInternal()
 {
     Yii::$app->request->baseUrl = '';
     Yii::$app->request->scriptUrl = '';
     Yii::$app->composition->hidden = true;
     $this->assertEquals(Url::to(['/admin/login/index'], true), Url::toInternal(['admin/login/index'], true));
     Yii::$app->composition->hidden = false;
     $this->assertEquals(Url::to(['/admin/login/index'], true), Url::toInternal(['admin/login/index'], true));
 }
 public function eventBeforeRender($event)
 {
     if ($this->value === 1) {
         if (Yii::$app->getModule('account')->getUserIdentity()->isGuest) {
             $event->isValid = false;
             Yii::$app->response->redirect(Url::toManager('account/default/index'));
         }
     }
 }
Пример #10
0
 /**
  * Send the array data to the api server.
  *
  * @param array $data The array to be sent to the server.
  * @return boolean|null true/false if data has been sent to the api successfull or not, null if the transfer is disabled.
  */
 private function apiServerSendData(array $data)
 {
     if ($this->transferException) {
         $curl = new Curl();
         $curl->post(Url::ensureHttp(rtrim($this->api, '/')) . '/create', ['error_json' => Json::encode($data)]);
         return !$curl->error;
     }
     return null;
 }
Пример #11
0
 public function testControllerMap()
 {
     Yii::$app->getModule('admin')->controllerMap = ['api-admin-user' => '\\admin\\apis\\UserController'];
     $rule = new \admin\components\UrlRule();
     $this->assertEquals(true, is_array($rule->controller));
     $this->assertArrayHasKey('admin/api-admin-user', $rule->controller);
     $this->assertEquals($rule->controller['admin/api-admin-user'], 'admin/api-admin-user');
     $this->assertEquals(Url::to(['/admin/login/index']), Url::toManager('admin/login/index'));
 }
Пример #12
0
 public function testEnsureHttp()
 {
     $this->assertEquals('http://luya.io', Url::ensureHttp('luya.io'));
     $this->assertEquals('http://www.luya.io', Url::ensureHttp('www.luya.io'));
     $this->assertEquals('http://luya.io', Url::ensureHttp('http://luya.io'));
     $this->assertEquals('http://www.luya.io', Url::ensureHttp('http://www.luya.io'));
     $this->assertEquals('https://luya.io', Url::ensureHttp('luya.io', true));
     $this->assertEquals('https://www.luya.io', Url::ensureHttp('www.luya.io', true));
     $this->assertEquals('https://luya.io', Url::ensureHttp('https://luya.io', true));
     $this->assertEquals('https://www.luya.io', Url::ensureHttp('https://www.luya.io', true));
 }
Пример #13
0
 public function testBaseHelper()
 {
     $a = Url::toManager('urlmodule/bar/index');
     $this->assertEquals($a, Url::to(['/urlmodule/bar/index']));
     $this->assertEquals($a, Url::toRoute('/urlmodule/bar/index'));
     $b = Url::toManager('urlmodule/default/index');
     $this->assertEquals($b, Url::to(['/urlmodule/default/index']));
     $this->assertEquals($b, Url::toRoute('/urlmodule/default/index'));
     $c = Url::toManager('news/default/detail', ['id' => 1, 'title' => 'foo-bar']);
     $this->assertEquals($c, Url::to(['/news/default/detail', 'id' => 1, 'title' => 'foo-bar']));
     $this->assertEquals($c, Url::toRoute(['/news/default/detail', 'id' => 1, 'title' => 'foo-bar']));
 }
 public function actionIndex()
 {
     // register auth token
     $this->view->registerJs("var authToken='" . Yii::$app->adminuser->identity->authToken . "';", \luya\web\View::POS_HEAD);
     $this->view->registerJs("var homeUrl='" . Url::home(true) . "';", \luya\web\View::POS_HEAD);
     // register admin js translations from module
     $this->view->registerJs('var i18n=' . Json::encode($this->module->jsTranslations), \luya\web\View::POS_HEAD);
     // Init ElementQueries after page load
     // $this->view->registerJs('setTimeout( function() {ElementQueries.listen(); ElementQueries.init();}, 1500);', \luya\web\View::POS_LOAD);
     // return and render index view file
     return $this->render('index');
 }
Пример #15
0
 public function init()
 {
     if ($this->baseUrl === null) {
         throw new InvalidConfigException("argument 'baseUrl' can not be null.");
     }
     $this->baseUrl = Url::trailing($this->baseUrl);
     $this->baseHost = parse_url($this->baseUrl, PHP_URL_HOST);
     Yii::$app->db->createCommand()->truncateTable('crawler_builder_index')->execute();
     // init base url
     $this->urlStatus($this->baseUrl);
     $this->find();
 }
Пример #16
0
 /**
  * Generate the Link Tag.
  *
  * @param string $value The Brackets value `[]`.
  * @param string $sub The optional Parentheses value `()`
  * @see \luya\tag\TagInterface::parse()
  * @return string The parser tag.
  */
 public function parse($value, $sub)
 {
     if (substr($value, 0, 2) == '//') {
         $value = StringHelper::replaceFirst('//', Url::base(true) . '/', $value);
         $external = false;
     } else {
         $external = true;
     }
     $value = Url::ensureHttp($value);
     $label = empty($sub) ? $value : $sub;
     return Html::a($label, $value, ['class' => $external ? 'link-external' : 'link-internal', 'target' => $external ? '_blank' : null]);
 }
Пример #17
0
 public function renderException($exception)
 {
     if ($exception instanceof NotFoundHttpException || !$this->transferException) {
         return parent::renderException($exception);
     }
     $data = json_encode($this->getExceptionArray($exception));
     $curl = new \Curl\Curl();
     $rsp = $curl->post(Url::trailing($this->api) . 'create', ['error_json' => $data]);
     if (!YII_DEBUG) {
         return '<html><head><title>Fehler</title></head><body style="padding:40px;"><h2>Seiten Fehler</h2><p>Es ist ein unerwartet Fehler passiert, wir bitten um Entschuldigung. Bitte versuchen Sie es später erneut.</p></body></html>';
     }
     return parent::renderException($exception);
 }
Пример #18
0
 public function testModuleContextUrls()
 {
     Yii::$app->urlManager->contextNavItemId = 1;
     $url = Url::toManager('news/default/detail', ['id' => 1, 'title' => 'foo-bar']);
     $this->assertEquals('/1/foo-bar', $url);
     Yii::$app->urlManager->contextNavItemId = 2;
     $url = Url::toManager('news/default/detail', ['id' => 1, 'title' => 'foo-bar']);
     $this->assertEquals('/en/page-1/1/foo-bar', $url);
     Yii::$app->urlManager->contextNavItemId = 2;
     $url = Url::toManager('news/default/detail', ['id' => 1, 'title' => 'foo-bar', 'pa' => 'ram']);
     $this->assertEquals('/en/page-1/1/foo-bar?pa=ram', $url);
     Yii::$app->urlManager->contextNavItemId = 1;
     $url = Url::toManager('news/default/detail', ['id' => 1, 'title' => 'page-2-news-title', 'news' => 'page']);
     $this->assertEquals('/1/page-2-news-title?news=page', $url);
 }
Пример #19
0
 public function sendMail($message, $email, $name)
 {
     $email = Html::encode($email);
     $name = Html::encode($name);
     $html = "<p>You have recieved an E-Mail via Form Block on " . Url::base(true) . "</p>";
     $html .= "<p>From: " . $name . " ({$email})<br />Time:" . date("d.m.Y - H:i") . "<br />";
     $html .= "Message:<br />" . nl2br(Html::encode($message)) . "</p>";
     $mail = Yii::$app->mail;
     $mail->fromName = $name;
     $mail->from = $email;
     $mail->compose($this->getVarValue('subjectText', $this->defaultMailSubject), $html);
     $mail->address($this->getVarValue('emailAddress'));
     if (!$mail->send()) {
         return 'Error: ' . $mail->error;
     } else {
         return 'success';
     }
 }
Пример #20
0
 public function init()
 {
     if ($this->baseUrl === null) {
         throw new InvalidConfigException("argument 'baseUrl' can not be null.");
     }
     $this->baseUrl = Url::trailing($this->baseUrl);
     $this->baseHost = parse_url($this->baseUrl, PHP_URL_HOST);
     $this->verbosePrint('baseUrl', $this->baseUrl);
     $this->verbosePrint('baseHost', $this->baseHost);
     $this->verbosePrint('useH1', $this->useH1);
     $this->verbosePrint('filterRegex', $this->filterRegex);
     $this->verbosePrint('doNotFollowExtensions', $this->doNotFollowExtensions);
     Yii::$app->db->createCommand()->truncateTable('crawler_builder_index')->execute();
     $this->verbosePrint('truncate of table crawerl_builder_index', 'yes');
     // init base url
     $this->urlStatus($this->baseUrl);
     $this->find();
 }
Пример #21
0
 public function getRemote()
 {
     $url = Url::trailing($this->url);
     $data = Yii::$app->cache->get($url);
     if ($data === false) {
         $curl = new \Curl\Curl();
         if ($this->auth_is_enabled) {
             $curl->setBasicAuthentication($this->auth_user, $this->auth_pass);
         }
         $curl->get($url . 'admin/api-admin-remote?token=' . sha1($this->token));
         if ($curl->error) {
             $data = false;
         } else {
             $data = json_decode($curl->response, true);
         }
         Yii::$app->cache->set($url, $data, 60 * 2);
     }
     return $data;
 }
Пример #22
0
 public function actionIndex()
 {
     $url = Url::base(true) . '/admin';
     // redirect logged in users
     if (!Yii::$app->adminuser->isGuest) {
         return $this->redirect($url);
     }
     // get the login form model
     $model = new \admin\models\LoginForm();
     // see if values are sent via post
     if (Yii::$app->request->post('login')) {
         $model->attributes = Yii::$app->request->post('login');
         if (($userObject = $model->login()) !== false) {
             if (Yii::$app->adminuser->login($userObject)) {
                 return $this->redirect($url);
             }
         }
     }
     $this->view->registerJs("\$(function(){ \$('#email').focus(); observeLogin('#loginForm', '" . Url::toAjax('admin/login/async') . "', '" . Url::toAjax('admin/login/async-token') . "'); });", \luya\web\View::POS_END);
     return $this->render('index', ['model' => $model]);
 }
Пример #23
0
 /**
  * @param $_GET['redirect'] should be urlencoded
  * @param $_POST['LoginForm'] data to login
  */
 public function actionIndex()
 {
     if (!$this->module->getUserIdentity()->isGuest) {
         return $this->redirect(Url::toManager('account/settings/index'));
     }
     $model = new LoginForm();
     // see if values are sent via post
     if (Yii::$app->request->post('LoginForm')) {
         $model->attributes = Yii::$app->request->post('LoginForm');
         if (($userObject = $model->login()) !== false) {
             if ($this->module->getUserIdentity()->login($userObject)) {
                 $redirect = Yii::$app->request->get('redirect', false);
                 if (!$redirect) {
                     $redirect = Url::toManager('account/settings/index');
                 }
                 return $this->redirect($redirect);
             }
         }
     }
     return $this->render('index', ['model' => $model]);
 }
Пример #24
0
 public function actionIndex()
 {
     $url = YiiUrl::to(Url::to('admin'), true);
     // redirect logged in users
     if (!Yii::$app->adminuser->isGuest) {
         return $this->redirect($url);
     }
     // get the login form model
     $model = new \admin\models\LoginForm();
     // see if values are sent via post
     if (isset($_POST['login'])) {
         $model->attributes = $_POST['login'];
         if (($userObject = $model->login()) !== false) {
             if (Yii::$app->adminuser->login($userObject)) {
                 return $this->redirect($url);
             }
         }
     }
     $this->view->registerJs("\$('#email').focus();");
     return $this->render('index', ['model' => $model]);
 }
Пример #25
0
 /**
  * @param $_GET['redirect'] should be urlencoded
  * @param $_POST['LoginForm'] data to login
  */
 public function actionIndex()
 {
     if (!$this->module->getUserIdentity()->isGuest) {
         return $this->redirect(\luya\helpers\Url::to('account/settings/index'));
     }
     $model = new \account\models\LoginForm();
     // see if values are sent via post
     if (isset($_POST['LoginForm'])) {
         $model->attributes = $_POST['LoginForm'];
         if (($userObject = $model->login()) !== false) {
             if ($this->module->getUserIdentity()->login($userObject)) {
                 $redirect = \yii::$app->request->get('redirect', false);
                 if (!$redirect) {
                     $redirect = \luya\helpers\Url::to('account/settings/index');
                 }
                 return $this->redirect($redirect);
             }
         }
     }
     return $this->render('index', ['model' => $model]);
 }
 public function actionIndex()
 {
     $model = Yii::createObject(['class' => $this->module->registerFormClass]);
     if (!$model instanceof \account\RegisterInterface) {
         throw new Exception("Register form class must be instance of register interface.");
     }
     $state = false;
     if (Yii::$app->request->post()) {
         $model->load(Yii::$app->request->post());
         if (($user = $model->register()) !== false) {
             $state = null;
             if ($this->module->registerConfirmEmail) {
                 // send mail
                 $hashKey = Yii::$app->security->generateRandomString();
                 $user->verification_hash = $hashKey;
                 $user->update(false);
                 $mail = $this->renderPartial('mail/_validationlink.php', ['hashKey' => $hashKey, 'user' => $user, 'link' => Url::to(['/account/register/activate', 'hash' => $hashKey], true)]);
                 $state = 1;
             }
             if ($this->module->validateRegistration) {
                 $mail = $this->renderPartial('mail/_waituntilvalidation.php', ['user' => $user]);
                 // send mail to admin and user
                 $user->update(false);
                 $state = 2;
             }
             if ($state === null) {
                 $mail = $this->renderPartial('mail/_login.php', ['user' => $user]);
                 // the user is registered directly.
                 $user->is_mail_verified = 1;
                 $user->is_active = 1;
                 $user->update(false);
                 $state = 3;
             }
             Yii::$app->mail->compose('Registration', $mail)->address($user->email)->send();
         }
     }
     return $this->renderLayout('index', ['model' => $model, 'state' => $state]);
 }
Пример #27
0
 /**
  * Get the Payment Gateway Notify link.
  *
  * This method is used to retrieve the link for dispatching to the requested url.
  *
  * @return string
  */
 public function getTransactionGatewayNotifyLink()
 {
     return Url::toInternal(['/payment/default/notify', 'lpToken' => $this->model->auth_token, 'lpKey' => $this->model->random_key], true);
 }
Пример #28
0
 /**
  * Prepare a temp file to
  * @todo added very basic csv support, must be stored as class, just a temp solution
  * @return array
  */
 public function actionExport()
 {
     $tempData = null;
     // first row
     $header = [];
     $i = 0;
     foreach ($this->model->find()->all() as $key => $value) {
         $row = [];
         $attrs = $value->getAttributes();
         foreach ($value->extraFields() as $field) {
             $attrs[$field] = $value->{$field};
         }
         foreach ($attrs as $k => $v) {
             if (is_object($v)) {
                 if ($v instanceof Arrayable) {
                     $v = $v->toArray();
                 } else {
                     continue;
                 }
             }
             if ($i === 0) {
                 $header[] = $this->model->getAttributeLabel($k);
             }
             if (is_array($v)) {
                 $tv = [];
                 foreach ($v as $kk => $vv) {
                     if (is_object($vv)) {
                         if ($vv instanceof Arrayable) {
                             $tv[] = implode(" | ", $vv->toArray());
                         } else {
                             continue;
                         }
                     } elseif (is_array($vv)) {
                         $tv[] = implode(" | ", $vv);
                     } else {
                         $tv[] = $vv;
                     }
                 }
                 $v = implode(" - ", $tv);
             }
             $row[] = '"' . str_replace('"', '\\"', $v) . '"';
         }
         if ($i === 0) {
             $tempData .= implode(",", $header) . "\n";
         }
         $tempData .= implode(",", $row) . "\n";
         $i++;
     }
     $key = uniqid('ngre', true);
     $store = FileHelper::writeFile('@runtime/' . $key . '.tmp', $tempData);
     if ($store) {
         Yii::$app->session->set('tempNgRestFileName', Inflector::slug($this->model->tableName()));
         Yii::$app->session->set('tempNgRestKey', $key);
         return ['url' => Url::toRoute(['/admin/ngrest/export-download', 'key' => base64_encode($key)])];
     }
     throw new ErrorException("Unable to write the temporary file for the csv export. Make sure the runtime folder is writeable.");
 }
Пример #29
0
 /**
  * Return link for usage in ajax request, the link will call the defined callback inside
  * this block. All callback methods must start with `callback`. An example for a callback method:.
  * 
  * ```php
  * public function callbackTestAjax($arg1)
  * {
  *     return 'hello callback test ajax with argument: arg1 ' . $arg1;
  * }
  * ```
  * 
  * The above defined callback link can be created with the follow code:
  * 
  * ```php
  * $this->createAjaxLink('TestAjax', ['arg1' => 'My Value for Arg1']);
  * ```
  * 
  * The most convient way to assign the variable is via extraVars
  * 
  * ```php
  * public function extraVars()
  * {
  *     return [
  *         'ajaxLinkToTestAjax' => $this->createAjaxLink('TestAjax', ['arg1' => 'Value for Arg1']),
  *     ];
  * }
  * ```
  * 
  * @param string $callbackName The callback name in uppercamelcase to call. The method must exists in the block class.
  * @param array  $params       A list of parameters who have to match the argument list in the method.
  *
  * @return string
  */
 public function createAjaxLink($callbackName, array $params = [])
 {
     $params['callback'] = Inflector::camel2id($callbackName);
     $params['id'] = $this->getEnvOption('id', 0);
     return Url::toAjax('cms/block/index', $params);
 }
Пример #30
0
use yii\helpers\Markdown;
$user = Yii::$app->adminuser->getIdentity();
$this->beginPage();
?>
<!DOCTYPE html>
<html ng-app="zaa" ng-controller="LayoutMenuController">
<head>
    <meta charset="utf-8">
    <meta http-equiv="x-ua-compatible" content="ie=edge">
    <title><?php 
echo Yii::$app->siteTitle;
?>
 &rsaquo; {{currentItem.alias}}</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <base href="<?php 
echo Url::base(true);
?>
/admin" />
    <style type="text/css">
        [ng\:cloak], [ng-cloak], [data-ng-cloak], [x-ng-cloak], .ng-cloak, .x-ng-cloak {
  			display: none !important;
		}
		
		.dragover {
		    border: 5px dashed #2196F3;
		}
    </style>
    <?php 
$this->head();
?>
</head>