I want to drop all user sessions when user resets his password, but I can't find a way to do that. My idea was to get all UserTokens of the specific user and delete them, but it seems impossible, because of
user = model.StringProperty(required=True, indexed=False)
in UserToken model
Any ideas how to do that?
I see two ways how to do that.
First is to inherit from the
UserToken
class makinguser
an indexed property. Then you can set thetoken_model
class property to your new token model in your user class. Here is the code:Don't forget to set the user model used by webapp2 to your user class if you do not do it already:
The second way is to make a complicated datastore query based on the token key name. Since the key names are of the form
<user_id>.<scope>.<random>
, it is possible to retrieve all the entities starting with a specific user ID. Have a look at the code:This uses the fact that the query by key names works in the lexicographical order.