portal entryPoint changes

This commit is contained in:
yuri
2016-02-18 11:27:13 +02:00
parent dbb29f25ab
commit 5f376304ce
6 changed files with 51 additions and 12 deletions

View File

@@ -93,7 +93,7 @@ class Application
$this->getContainer()->get('clientManager')->display();
}
public function runEntryPoint($entryPoint, $data = array())
public function runEntryPoint($entryPoint, $data = array(), $final = false)
{
if (empty($entryPoint)) {
throw new \Error();
@@ -107,8 +107,18 @@ class Application
$entryPointManager = new \Espo\Core\EntryPointManager($container);
try {
$auth = new \Espo\Core\Utils\Auth($this->container, $entryPointManager->checkNotStrictAuth($entryPoint));
$apiAuth = new \Espo\Core\Utils\Api\Auth($auth, $entryPointManager->checkAuthRequired($entryPoint), true);
$authRequired = $entryPointManager->checkAuthRequired($entryPoint);
$authNotStrict = $entryPointManager->checkNotStrictAuth($entryPoint);
if ($authRequired && !$authNotStrict) {
if (!$final && $portalId = $this->detectedPortalId()) {
$app = new \Espo\Core\Portal\Application($portalId);
$app->setBasePath($this->getBasePath());
$app->runEntryPoint($entryPoint, $data, true);
exit;
}
}
$auth = new \Espo\Core\Utils\Auth($this->container, $authNotStrict);
$apiAuth = new \Espo\Core\Utils\Api\Auth($auth, $authRequired, true);
$slim->add($apiAuth);
$slim->hook('slim.before.dispatch', function () use ($entryPoint, $entryPointManager, $container, $data) {
@@ -293,5 +303,25 @@ class Application
{
$this->getContainer()->get('clientManager')->setBasePath($basePath);
}
public function getBasePath()
{
return $this->getContainer()->get('clientManager')->getBasePath();
}
public function detectedPortalId()
{
if (!empty($_GET['portalId'])) {
return $_GET['portalId'];
}
if (!empty($_COOKIE['auth-token'])) {
$token = $this->getContainer()->get('entityManager')->getRepository('AuthToken')->where(array('token'=>$_COOKIE['auth-token']))->findOne();
if ($token && $token->get('portalId')) {
return $token->get('portalId');
}
}
return null;
}
}

View File

@@ -36,7 +36,7 @@ use \Espo\Core\Exceptions\Error;
class Avatar extends Image
{
public static $authRequired = true;
public static $authRequired = false;
public static $notStrictAuth = true;

View File

@@ -36,7 +36,7 @@ Espo.define('app-portal', ['app', 'acl-portal-manager'], function (Dep, AclPorta
createAclManager: function () {
return new AclPortalManager(this.user);
}
},
});

View File

@@ -386,6 +386,8 @@ Espo.define(
this.auth = Base64.encode(data.auth.userName + ':' + data.auth.token);
this.storage.set('user', 'auth', this.auth);
this.setCookieAuthToken(data.auth.token);
this.initUserData(data, function () {
this.trigger('auth');
}.bind(this));
@@ -419,12 +421,25 @@ Espo.define(
this.doAction({action: 'login'});
this.language.clearCache();
this.unsetCookieAuthToken();
xhr = new XMLHttpRequest;
xhr.open('GET', this.url + '/', !1, 'logout', 'logout');
xhr.send('');
xhr.abort();
},
setCookieAuthToken: function (token) {
var date = new Date();
date.setTime(date.getTime() + (1000 * 24*60*60*1000));
console.log(token);
document.cookie = 'auth-token='+token+'; expires='+date.toGMTString()+'; path=/';
},
unsetCookieAuthToken: function () {
document.cookie = 'auth-token' + '=; expires=Thu, 01 Jan 1970 00:00:01 GMT; path=/';
},
initUserData: function (options, callback) {
options = options || {};
@@ -478,7 +493,7 @@ Espo.define(
url: 'App/user',
}).done(function (data) {
callback(data);
});
}.bind(this));
},
setupAjax: function () {

View File

@@ -36,9 +36,6 @@ if (!$app->isInstalled()) {
}
if (!empty($_GET['entryPoint'])) {
if (!empty($_GET['portalId'])) {
$app = new \Espo\Core\Portal\Application($_GET['portalId']);
}
$app->runEntryPoint($_GET['entryPoint']);
exit;
}

View File

@@ -35,9 +35,6 @@ if (!$app->isInstalled()) {
}
if (!empty($_GET['entryPoint'])) {
if (!empty($_GET['portalId'])) {
$app = new \Espo\Core\Portal\Application($_GET['portalId']);
}
$app->setBasePath('../');
$app->runEntryPoint($_GET['entryPoint']);
exit;