简体   繁体   English

Google Apps Engine / Django,是否在用户登录后调用操作?

[英]Google Apps Engine / Django, calling action upon user login?

I'm new to Google Apps Engine (working on an existing project for someone else) and it seems a bit different than Django as far as the login as the login is handled by Google, I'm trying to make it so the app creates a custom cookie for a user upon their logging in but can't seem to find the handler for the login action... I apologize for the newbie question but would appreciate if anyone can point me in the right direction on how to accomplish this. 我是Google Apps Engine的新手(正在为其他人开发一个现有项目),就登录名而言,似乎与Django有点不同,因为登录名是由Google处理的,我正在尝试这样做,以便该应用为用户登录后创建的自定义Cookie,但似乎找不到用于登录操作的处理程序...对于新手问题,我深表歉意,但是如果有人能为我指出正确的实现方法,我们将不胜感激。 (just calling an action upon a user's login) (仅在用户登录时调用操作)

I'm looking at some tutorials, like this one: http://www.browse-tutorials.net/tutorial/login-register-logout-python-appengine and it basically says you just generate the links since google handles the login so I can't seem to figure a solution to an issue like this. 我正在看一些像这样的教程: http : //www.browse-tutorials.net/tutorial/login-register-logout-python-appengine ,它基本上说您只是生成了链接,因为Google处理了登录,所以我似乎无法找到解决此类问题的方法。

Thanks 谢谢

I solved that problem using the Django middleware system and a session. 我使用Django 中间件系统和一个会话解决了该问题。 I think the use of a session is the best way to guarantee that the action only happens on login (whereas an url can be reloaded manually). 我认为使用会话是确保操作仅在登录时发生的最佳方法(而url可以手动重新加载)。

Django sessions does not work out of the box, so I implemented my own sessions. Django会话无法立即使用,因此我实现了自己的会话。 However, there exists good appengine-specific implementation as this article points out: http://blog.notdot.net/2010/02/Webapps-on-App-Engine-Part-5-Sessions 但是,本文指出,存在特定于appengine的良好实现: http : //blog.notdot.net/2010/02/Webapps-on-App-Engine-Part-5-Sessions

I implemented my middleware class like this, and added it to MIDDLEWARE_CLASSES in settings.py: 我这样实现了中间件类,并将其添加到settings.py中的MIDDLEWARE_CLASSES中:

class LoginManager(object):
    def process_view(self, request, view_func, view_args, view_kwargs):
        user = users.get_current_user()
        if user is not None:
            marker = Session.get(user.user_id())
            if marker is None:
                login_action()
                Session.set(user.user_id(), "true")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM