簡體   English   中英

我搜索了FOSUserBundle私人資料,但無濟於事

[英]I have searched for FOSUserBundle private profile, to no avail

所以我試圖創建一個包含私有配置文件的symfony項目,我使用FriendsOfSymfony,但如果我創建了兩個用戶,每個用戶都可以看到其他人上傳的文件。 我試圖在多個網站上搜索,但未能找到對我有用的東西。 示例: 將擴展配置文件實體添加到FOS UserBundle

我想為每個用戶創建私有配置文件來上傳文件,除了他們之外沒有人能夠看到它們(只有管理員和特定用戶)。

問題非常廣泛。

您需要為您的應用程序引入身份驗證。

並為您上傳的文件添加user iduser relation 然后在控制器中列出/顯示文件( /profile/my-uploads ) - 僅加載屬於此特定(登錄)用戶的文件。

對於管理員訪問 - 最好是創建特殊的后台或實施用戶模擬

在Symfony文檔中閱讀更多相關信息: http//symfony.com/doc/current/components/security/authentication.html

如果你有擴展

Symfony的\\包\\ FrameworkBundle \\控制器\\控制器

或FOSUserBundle控制器你可以嘗試做這樣的事情:

public function publicProfileAction($handleOrHash = '')
{
    if ($handleOrHash == '') {
        throw new NotFoundHttpException("Unable to find this user");
    }

    $user = $this->getUserService()->getUserByHandleOrHash($handleOrHash);

    if (!$user) {
        throw new NotFoundHttpException("Unable to find this user");
    }

    if ($user != $this->getUser()) {
        throw new AccessDeniedException("You cannot see this user profile");
    }

    return $this->render('MyUserBundle:Default:public-profile.html.twig',
        array('user' => $user)
    );
}

其中getUserService()將返回一個對象,該對象可以通過名為getUserByHandleOrHash()的方法訪問userRepository,該方法使用存儲庫來進行學說查詢。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM