2011-12-30 16 views
5

Tôi sử dụng mô-đun auth từ webapp2 và tôi muốn biết cách thêm một auth_id như 'facebook: fbuserid12121212' và thêm vào danh sách auth_id: s cho người dùng. Nhưng tôi thấy không có chức năng từ API cho phép tôi làm điều này. Bạn có thể cho tôi biết làm thế nào để làm điều đó?Cách thêm auth_id bằng webapp2?

Cảm ơn

+1

Có thể đáng giá để di chuyển bản cập nhật/câu trả lời của bạn thành câu trả lời thực tế (để câu hỏi không hiển thị như chưa được trả lời). Cảm ơn bạn đã sắp xếp điều này :) –

+1

@jgeewax Tôi đã chuyển câu trả lời cho phần câu trả lời. – allyourcode

Trả lời

2

Đây là câu trả lời mà OP tìm thấy. Tôi sao chép nó ở đây để câu hỏi này sẽ không được trả lời:

This was answered in the google group, chức năng tôi đang tìm kiếm là user.auth_ids.append và mã tôi sử dụng hiện nay để tận dụng của nó là:

@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

Làm cách nào để truy xuất auth_id cho người dùng? – deltanine

Các vấn đề liên quan