How to delete from webapp2_extras.appengine.auth.models.Unique?

后端 未结 1 525
天涯浪人
天涯浪人 2021-01-06 09:21

I\'m using webapp2_extras.appengine.auth in my project and it creates 3 tables in datastore: User, UserToken and Unique. All is good and working as it should...

My q

相关标签:
1条回答
  • 2021-01-06 09:47

    I had trouble finding exactly what to delete, since Unique model doesn't hold references to User. Here's the solution (with reference to docs):

    from google.appengine.ext import ndb
    from webapp2_extras import auth
    
    class SomeUserHandler():
      def forget_user(self):
        auth = auth.get_auth()
        user_dict = auth.get_user_by_session()
        user = auth.store.user_model.get_by_id(user_dict['user_id'])
    
        # from webapp2_extras.appengine.auth.models.User
        # http://webapp-improved.appspot.com/_modules/webapp2_extras/appengine/auth/models.html#User
        # 
        # def add_auth_id(self, auth_id):
        #   ...
        #   unique = '%s.auth_id:%s' % (self.__class__.__name__, auth_id)
        #   ...
        Unique.delete_multi( map(lambda s: 'User.auth_id:' + s, user.auth_ids) )
    
    0 讨论(0)
提交回复
热议问题