重写 symfony 中的 isAuthenticated()

发布于 2024-10-29 08:25:52 字数 1426 浏览 0 评论 0原文

我正在做 Practical symfony with Doctrine - Jobeet Job Website 只是想了解后端是如何工作的,我试图覆盖前端和后端中的 isAuthenticated() 函数,我所做的很简单,在我的 apps\frontend\lib\myUser.class.php 文件中,我这样做了 public

function isAuthenticated()
{
    return (bool)($this->authenticated && $this->getAttribute('is_customer', false, 'sfGuardSecurityUser'));
}

我还像这样覆盖了 sfDoctrineGuard 的登录功能,

public function signIn($user, $remember = false, $con = null)
{
    parent::signIn($user, $remember, $con);
    if($this->authenticated){
        $this->setAttribute('is_customer', true, 'sfGuardSecurityUser');
    }
}

我在 apps\backend\lib\myUser.class.php 中为后端做了相同的操作,但使用 < strong>is_admin,到目前为止一切都很完美,只是在后端,当我要编辑作业时,会话中的 sfGuardSecurityUser 丢失了,为什么,因为 isAuthenticated此页面中调用的 () 函数位于 apps\frontend\lib\myUser.class.php 中,因此当我尝试更改页面时,我会注销,因为调用的 isAuthenticated() 函数位于 apps 中\backend\lib\myUser.class.php,听起来很少见,但它只发生在乔布斯的编辑页面中,现在我被困在这里,希望大家理解我,更具体地说,当我去作业/编辑页面,在操作中我放置了 print_r($_SESSION),我可以看到这一部分,

[sfGuardSecurityUser] => Array
            (
                [user_id] => 1
                [is_admin] => 1
            )  

但是如果我重新加载页面,我就看不到这一部分了,所以,当我尝试时要更改页面,我会注销,等等,如果我从 apps\frontend\lib\myUser.class.php 中评论或删除 isAuthenticated ,后端中的所有内容都是完美的,但我需要覆盖后端中的函数并且前端

需要一些帮助

,谢谢

i'm doing the Practical symfony with Doctrine - Jobeet Job Website just trying to understand how backend works, i'm trying to overwrite the isAuthenticated() function in frontend and backend, what i did is simple, in my apps\frontend\lib\myUser.class.php file, i did this public

function isAuthenticated()
{
    return (bool)($this->authenticated && $this->getAttribute('is_customer', false, 'sfGuardSecurityUser'));
}

i also overwrite the signIn function of sfDoctrineGuard like this

public function signIn($user, $remember = false, $con = null)
{
    parent::signIn($user, $remember, $con);
    if($this->authenticated){
        $this->setAttribute('is_customer', true, 'sfGuardSecurityUser');
    }
}

i made the same for backend in apps\backend\lib\myUser.class.php but using is_admin, untill now everything is perfect, just that in the backend, when i'm going to edit a Job, the sfGuardSecurityUser in the session get lost, why, because the isAuthenticated() function that is called in this page, is the located in apps\frontend\lib\myUser.class.php, so when i try to change the page i get logged out, cuz isAuthenticated() function called is the located in apps\backend\lib\myUser.class.php, sounds rare, but it only happens in the edit page of the Jobs, now i'm stuck here, hope you all understand me, and to be more specific, when i go to the job/edit page and in the action i put a print_r($_SESSION), i can see this piece

[sfGuardSecurityUser] => Array
            (
                [user_id] => 1
                [is_admin] => 1
            )  

but if i reload the page, i can't see this piece anymore, so, when i try to change of page, i get logged out, and more, if i comment or remove the isAuthenticated from apps\frontend\lib\myUser.class.php everything in the backend is perfect, but i need to overwrite the function in the backend and frontend

need some help

thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

沉睡月亮 2024-11-05 08:25:52

尝试在应用的 factories.yml 中设置准确的会话名称:

all:
  storage:
      class: sfSessionStorage
      param:
        session_name: my_session_name
        session_cookie_domain: example.com

Try setting exact session names in your apps' factories.yml:

all:
  storage:
      class: sfSessionStorage
      param:
        session_name: my_session_name
        session_cookie_domain: example.com
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文