Reputation: 26652
I use the auth module from webapp2 and I want to know how to add an auth_id like 'facebook:fbuserid12121212' and add that to the list of auth_id:s for a user. But I see no function from the API that allows me to do this. Could you please tell me how to do it?
Thanks
Upvotes: 5
Views: 581
Reputation: 22603
This is the answer that the OP found. I'm copying it here so that this question will not be unanswered:
This was answered in the google group, the function I was looking for is user.auth_ids.append and the code I use now to make use of it is:
@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'
Upvotes: 2