2011-12-30 10 views
5

Webapp2'den auth modülünü kullanıyorum ve 'facebook: fbuserid12121212' gibi bir auth_id eklemeyi ve bunu bir kullanıcı için auth_id: s listesine eklemeyi öğrenmek istiyorum. Ancak API’nın bunu yapmamı sağlayan bir işlevi göremiyorum. Lütfen bana nasıl yapılacağını söyler misin?Webapp2 ile auth_id nasıl eklenir?

Teşekkür

+1

Güncellemenizi/cevabınızı gerçek bir cevaba taşımaya değecek (soru, cevapsız olarak gösterilmeyecek). Bu sıralama için teşekkürler :) –

+1

@jgeewax Cevabını cevaplar bölümüne taşıdım. – allyourcode

cevap

2

Bu OP bulundu cevaptır. Bu soru cevapsız olmayacak bu yüzden buraya taklit ediyorum: Ben arıyordu fonksiyon user.auth_ids.append

This was answered in the google group ve bundan yararlanmak için artık kullanıma koddur:

@user_required 
def post(self, **kwargs): 
    email = self.request.POST.get('email') 
    auser = self.auth.get_user_by_session() 
    userid = auser['user_id'] 
    user = auth_models.User.get_by_id(auser['user_id']) 
    existing_user = auth_models.User.get_by_auth_id(email) 

    if existing_user is not None: 
     # You need to handle duplicates. 
     # Maybe you merge the users? Maybe you return an error? 
     pass 

    # Test the uniqueness of the auth_id. We must do this to 
    # be consistent with User.user_create() 
    unique = '{0}.auth_id:{1}'.format(auth_models.__class__.__name__, email) 

    if auth_models.User.unique_model.create(unique): 
     # Append email to the auth_ids list 
     user.auth_ids.append(email) 
     user.put() 
     return "Email updated" 
    else: 
     return 'some error' 
+0

Bir kullanıcı için auth_id'i nasıl alırsınız? – deltanine