外部检测用户自己的云会话

时间:2016-12-12 05:27:16

标签: php session login external owncloud

我有两个网站在同一台服务器上运行,第一个是自己的云服务器,第二个是从头开始构建的网站。第二个站点只能由当前登录到他们自己的云帐户的用户访问,但我很难让公共lib为我工作。到目前为止我所拥有的。

<?php
   require_once '/var/www/owncloud9/html/lib/base.php';
   require_once '/var/www/owncloud9/html/lib/public/user.php';

    if ( \OCP\User::isLoggedIn() )
        echo( "Hi ".\OCP\User::getDisplayName()."\n" );
    else
        echo( "You are not logged in.\n");
?>

结果始终是“您尚未登录”,即使情况并非如此。如何让第二个站点检测用户自己的云会话?

1 个答案:

答案 0 :(得分:0)

您必须添加一些评论,例如https://github.com/pbek/qownnotesapi/blob/develop/controller/noteapicontroller.php

/**
 * Returns information about the ownCloud server
 *
 * @NoAdminRequired
 * @NoCSRFRequired
 * @CORS
 *
 * @return string
 */
public function getAppInfo() {
    $appManager = \OC::$server->getAppManager();
    $versionsAppEnabled = $appManager->isEnabledForUser('files_versions');
    $trashAppEnabled = $appManager->isEnabledForUser('files_trashbin');
    $notesPathExists = false;
    $notesPath = $this->request->getParam( "notes_path", "" );
    // check if notes path exists
    if ($notesPath !== "")
    {
        $notesPath = "/files" . (string)$notesPath;
        $view = new \OC\Files\View('/' . $this->user);
        $notesPathExists = $view->is_dir($notesPath);
    }
    return [
        "versions_app" => $versionsAppEnabled,
        "trash_app" => $trashAppEnabled,
        "versioning" => true,
        "app_version" => \OC::$server->getConfig()->getAppValue('qownnotesapi', 'installed_version'),
        "server_version" => \OC::$server->getSystemConfig()->getValue('version'),
        "notes_path_exists" => $notesPathExists,
    ];
}
上述注释中的

@NoAdminRequired@NoCSRFRequired会关闭安全检查。 (见:https://doc.owncloud.org/server/9.0/developer_manual/app/tutorial.html

如果您现在使用简单的身份验证来处理您的请求,它应该可以正常工作。 示例:https://user:password@your-server/path/to/your/controller

我在OwnCloudService::checkAppInfo https://github.com/pbek/QOwnNotes/blob/develop/src/services/owncloudservice.cpp#L322

<div class="parent"><DIV class="outer-left-bm">Reference Transaction Number:&nbsp;</DIV><DIV class="outer-right-bm"><form:input path="refTranNbr" maxlength="20" size="20" /></DIV></div> 中执行此操作