代码之家  ›  专栏  ›  技术社区  ›  adamJLev

Django和自定义认证后端(Web服务)+无数据库。如何在会话中保存内容?

  •  1
  • adamJLev  · 技术社区  · 15 年前

    我一直在到处搜索,根据 this answer 我把你看到的放在一起。
    它可以用,但我需要在用户会话中放一些东西,就在里面 authenticate .

    我要怎么储存 acme_token 在用户的会话中,以便在他们注销时将其清除?这个 request 对象在此上下文中不可用

    class AcmeUserBackend(object):
        # Create a User object if not already in the database?
        create_unknown_user = False
    
        def get_user(self, username):
            return AcmeUser(id=username)
    
        def authenticate(self, username=None, password=None):
            """ Check the username/password and return an AcmeUser. """
            acme_token = ask_another_site_about_creds(username, password)
    
            if acme_token:
                return AcmeUser(id=username)
            return None
    
    1 回复  |  直到 15 年前
        1
  •  2
  •   Ignacio Vazquez-Abrams    15 年前
    推荐文章