1

如何在后端由 Flask 提供支持的 iOS 应用程序中创建/维护临时会话。我使用烧瓶登录模块进行用户会话管理。我想让用户在没有用户注册/登录的情况下试用我的 iOS 应用程序。当用户匿名时,我的应用程序的行为类似于用户登录时的行为。

我想使用用户的设备令牌作为唯一 ID。是否可以仅使用设备令牌创建会话(通常我们提供用户 ID 和密码)

4

1 回答 1

0

Assuming that the device token is guaranteed to be unique and that the relationship between users and devices is one-to-one (although this could be adapted to work with a one-to-many situation as well):

@app.route("/authenticate", methods=("POST",))
def authenticate():
    if request.form.get("user_id") is not None:
        user = authenticate_user(request.form)
    else:
        user = create_user_for_device(request.form)

    login_user(user)
    # And so on

authenticate_user and create_user_for_device are functions that you will have to write - login_user is from Flask-Login.

于 2013-10-09T04:34:45.010 回答