Handling Sessions on Google App Engine with Android/IPhone

前端 未结 6 590
借酒劲吻你
借酒劲吻你 2021-02-04 07:11

I\'m starting to write an app whereby a mobile app (Android/IPhone) will communicate with the GAE backend (Python) through a series of Web API calls using JSON.

I can\'t

6条回答
  •  轮回少年
    2021-02-04 07:28

    If you dont explicitly want to use Sessions etc. you can simply use the Datastore. Try following this:

    1. Get a unique deviceID/email to identify each unique user.
    2. On request from a specific user, generate a random authentication key, and store it attached to the user's email/deviceID and probably the current timestamp and a loggedIn flag.

    SO you have:

    User email/id: someone@example.com
    password: xxxxxxxxxx
    Key : 2131231312313123123213
    Timestamp: 20:00 12-02-2013
    loggedIn : boolean value
    

    This can be database model. Now whenever the user logs in:

    • Check email, password combination.
    • If valid, generate random key, and update the datastore with the new key
    • update timestamp with current time, and set loggedIn to True
    • Now return the key back to the client (Android/iPhone) in a JSON object.

    Now on every request, Check the received key against the one in your datastore, and if loggedIn flag is set to true. If both OK, process the request.

    Also, on Logout:

    • Just set the loggedIn flag in the datastore to False.

    Hope this helps :)

提交回复
热议问题