本文整理汇总了Python中social_auth.models.UserSocialAuth.get_social_auth_for_user方法的典型用法代码示例。如果您正苦于以下问题:Python UserSocialAuth.get_social_auth_for_user方法的具体用法?Python UserSocialAuth.get_social_auth_for_user怎么用?Python UserSocialAuth.get_social_auth_for_user使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类social_auth.models.UserSocialAuth
的用法示例。
在下文中一共展示了UserSocialAuth.get_social_auth_for_user方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: disconnect
# 需要导入模块: from social_auth.models import UserSocialAuth [as 别名]
# 或者: from social_auth.models.UserSocialAuth import get_social_auth_for_user [as 别名]
def disconnect(self, user, association_id=None):
"""Deletes current backend from user if associated.
Override if extra operations are needed.
"""
if association_id:
UserSocialAuth.get_social_auth_for_user(user).get(id=association_id).delete()
else:
UserSocialAuth.get_social_auth_for_user(user).filter(provider=self.AUTH_BACKEND.name).delete()
示例2: disconnect
# 需要导入模块: from social_auth.models import UserSocialAuth [as 别名]
# 或者: from social_auth.models.UserSocialAuth import get_social_auth_for_user [as 别名]
def disconnect(self, user, association_id=None):
"""Deletes current backend from user if associated.
Override if extra operations are needed.
"""
name = self.AUTH_BACKEND.name
if UserSocialAuth.allowed_to_disconnect(user, name, association_id):
if association_id:
UserSocialAuth.get_social_auth_for_user(user)\
.get(id=association_id).delete()
else:
UserSocialAuth.get_social_auth_for_user(user)\
.filter(provider=name)\
.delete()
else:
raise NotAllowedToDisconnect()
示例3: home
# 需要导入模块: from social_auth.models import UserSocialAuth [as 别名]
# 或者: from social_auth.models.UserSocialAuth import get_social_auth_for_user [as 别名]
def home(request):
jsonSerializer = JSONSerializer()
#client_ip = _get_client_ip(request)
#lat, lon = _get_client_location(client_ip)
lat, lon = float(37), float(-94)
user = request.user
voter = None
if user.is_authenticated():
social_user = UserSocialAuth.get_social_auth_for_user(user)[0]
voter = _create_or_get_voter(social_user, lat, lon)
lat, lon = str(lat), str(lon)
# Grab the relevant voter
voter_json = {}
if voter is not None:
voter_data = jsonSerializer.serialize(voter)
voter_data = json.loads(voter_data)
voter_json = voter_data.copy()
voter_json["voter"] = _get_resource_uri("voter", voter_json["id"])
voter_json = SafeString(json.dumps(voter_json))
#app_json = _get_initial_response()
civic_api_key = settings.CIVIC_API_KEY
return render_to_response('openvote/templates/home.html', locals())
示例4: backends_data
# 需要导入模块: from social_auth.models import UserSocialAuth [as 别名]
# 或者: from social_auth.models.UserSocialAuth import get_social_auth_for_user [as 别名]
def backends_data(user):
"""Return backends data for given user.
Will return a dict with values:
associated: UserSocialAuth model instances for currently
associated accounts
not_associated: Not associated (yet) backend names.
backends: All backend names.
If user is not authenticated, then first list is empty, and there's no
difference between the second and third lists.
"""
available = get_backends().keys()
values = {'associated': [],
'not_associated': available,
'backends': available}
# user comes from request.user usually, on /admin/ it will be an instance
# of auth.User and this code will fail if a custom User model was defined
if hasattr(user, 'is_authenticated') and user.is_authenticated():
associated = UserSocialAuth.get_social_auth_for_user(user)
not_associated = list(set(available) -
set(assoc.provider for assoc in associated))
values['associated'] = associated
values['not_associated'] = not_associated
return values
示例5: settings
# 需要导入模块: from social_auth.models import UserSocialAuth [as 别名]
# 或者: from social_auth.models.UserSocialAuth import get_social_auth_for_user [as 别名]
def settings(request, settings_form=UserProfileForm):
"""
Presents the user a form with their settings, basically the register
form minus username minus password.
Uses the user_form_requested signal to gather additional forms from
other applications to present to the user.
"""
form_classes = [settings_form] + \
[form for receiver, form in
user_form_requested.send(sender=request, new_user=False)]
if request.method == "POST":
forms = [form(request.POST, user=request.user)
for form in form_classes]
if all(form.is_valid() for form in forms):
for form in forms:
form.save()
return redirect('account_settings')
else:
forms = [form(user=request.user) for form in form_classes]
return render(request, 'ksp_login/settings.html', {
'account_associations': UserSocialAuth.get_social_auth_for_user(request.user),
'forms': forms,
})
示例6: context_value
# 需要导入模块: from social_auth.models import UserSocialAuth [as 别名]
# 或者: from social_auth.models.UserSocialAuth import get_social_auth_for_user [as 别名]
def context_value():
keys = [key for key in get_backends().keys()]
accounts = dict(zip(keys, [None] * len(keys)))
user = request.user
if hasattr(user, 'is_authenticated') and user.is_authenticated():
accounts.update((assoc.provider, assoc)
for assoc in UserSocialAuth.get_social_auth_for_user(user))
return accounts
示例7: context_value
# 需要导入模块: from social_auth.models import UserSocialAuth [as 别名]
# 或者: from social_auth.models.UserSocialAuth import get_social_auth_for_user [as 别名]
def context_value():
keys = list(get_backends().keys())
accounts = dict(list(zip(keys, [None] * len(keys))))
user = request.user
if hasattr(user, "is_authenticated") and user.is_authenticated():
accounts.update(
(assoc.provider.replace("-", "_"), assoc) for assoc in UserSocialAuth.get_social_auth_for_user(user)
)
return accounts
示例8: maptest
# 需要导入模块: from social_auth.models import UserSocialAuth [as 别名]
# 或者: from social_auth.models.UserSocialAuth import get_social_auth_for_user [as 别名]
def maptest(request):
client_ip = _get_client_ip(request)
lat, lon = _get_client_location(client_ip)
user = request.user
voter = None
if user.is_authenticated():
social_user = UserSocialAuth.get_social_auth_for_user(user)[0]
voter = _create_or_get_voter(social_user, lat, lon)
return render_to_response('openvote/templates/maptest.html', locals())
示例9: home
# 需要导入模块: from social_auth.models import UserSocialAuth [as 别名]
# 或者: from social_auth.models.UserSocialAuth import get_social_auth_for_user [as 别名]
def home(request):
try:
link = UserSocialAuth.get_social_auth_for_user(request.user).get().tokens
access_token = link['access_token']
return render_to_response("logged-in.html", {'access_token': access_token}, RequestContext(request))
except:
return render_to_response("main.html", RequestContext(request))
示例10: home
# 需要导入模块: from social_auth.models import UserSocialAuth [as 别名]
# 或者: from social_auth.models.UserSocialAuth import get_social_auth_for_user [as 别名]
def home(request):
try:
link = UserSocialAuth.get_social_auth_for_user(request.user).get().tokens
print("got link")
access_token = link['access_token']
return render_to_response("loggedin.html", {'access_token': access_token}, RequestContext(request))
except AttributeError:
return render_to_response("main.html", RequestContext(request))
示例11: populate_social_auth_backend
# 需要导入模块: from social_auth.models import UserSocialAuth [as 别名]
# 或者: from social_auth.models.UserSocialAuth import get_social_auth_for_user [as 别名]
def populate_social_auth_backend(request):
associated = None
associated_name = None
user = request.user
if hasattr(user, 'is_authenticated') and user.is_authenticated():
associated = UserSocialAuth.get_social_auth_for_user(user)
if associated:
for name in ['Google', 'Facebook', 'Linkedin', 'Flickr']:
if name in str(associated):
associated_name = name
break;
return {'associated_auth_backend': associated_name }
示例12: disconnect
# 需要导入模块: from social_auth.models import UserSocialAuth [as 别名]
# 或者: from social_auth.models.UserSocialAuth import get_social_auth_for_user [as 别名]
def disconnect(request, backend, association_id):
"""
If the user has at least one other social account association or a
valid password, disconnects the given social account, otherwise asks
the user to set up a password before proceeding.
"""
associations = UserSocialAuth.get_social_auth_for_user(request.user)
has_assoc = associations.exclude(id=association_id).count()
has_pass = request.user.has_usable_password()
if has_assoc or has_pass:
return social_auth_disconnect(request, backend, association_id)
return render(request, 'ksp_login/invalid_disconnect.html')
示例13: loggedin
# 需要导入模块: from social_auth.models import UserSocialAuth [as 别名]
# 或者: from social_auth.models.UserSocialAuth import get_social_auth_for_user [as 别名]
def loggedin(request):
try:
link = UserSocialAuth.get_social_auth_for_user(request.user).get().tokens
access_token = link['access_token']
# OAuth dance
#credentials = AccessTokenCredentials(access_token, 'my-user-agent/1.0')
#http = httplib2.Http()
#http = credentials.authorize(http)
#service = build('calendar', 'v3', http=http)
# Snippet that lists all calendar events
#request = service.events().list(calendarId='primary')
#while request != None:
## Get the next page.
#response = request.execute()
## Accessing the response like a dict object with an 'items' key
## returns a list of item objects (events).
#for event in response.get('items', []):
## The event object is a dict object with a 'summary' key.
#print repr(event.get('summary', 'NO SUMMARY')) + '\n'
## Get the next request object by passing the previous request object to
## the list_next method.
#request = service.events().list_next(request, response)
#except AccessTokenRefreshError:
## The AccessTokenRefreshError exception is raised if the credentials
## have been revoked by the user or they have expired.
#print ('The credentials have been revoked or expired, please re-run'
#'the application to re-authorize')
# working event
#event = {
#'summary': "summary",
#'description': "description",
#'start' : { 'dateTime' : "2013-04-01T15:00:00.000Z"},
#'end' : { 'dateTime' : "2013-04-01T17:00:00.000Z"}
#}
#payload = json.dumps(event)
#created_event = service.events().insert(calendarId='primary', body=event).execute()
#print "Created Event: %s" % created_event['id']
return render_to_response("logged-in.html", RequestContext(request))
except:
return render_to_response("main.html", RequestContext(request))
示例14: post2
# 需要导入模块: from social_auth.models import UserSocialAuth [as 别名]
# 或者: from social_auth.models.UserSocialAuth import get_social_auth_for_user [as 别名]
def post2(request):
word = request.POST.get('word')
hint = request.POST.get('hint')
print word
print hint
print request.user
question = Question(word=word, hint=hint, created_by=request.user)
question.save()
fb_oauth_access_token = UserSocialAuth.get_social_auth_for_user(request.user).filter(provider='facebook')[0].tokens['access_token']
graph = facebook.GraphAPI(fb_oauth_access_token)
message = "http://localtest.me/q/%d" % question.id
graph.put_object("me", "feed", message=message)
return HttpResponse(status=201)
示例15: password
# 需要导入模块: from social_auth.models import UserSocialAuth [as 别名]
# 或者: from social_auth.models.UserSocialAuth import get_social_auth_for_user [as 别名]
def password(request):
"""
Sets, changes or removes the currently logged in user's passwords,
depending on whether they have any social account associations.
"""
has_assoc = UserSocialAuth.get_social_auth_for_user(request.user).count()
if request.user.has_usable_password():
def form(*args, **kwargs):
return PasswordChangeForm(not has_assoc, *args, **kwargs)
else:
form = SetPasswordForm
return password_change(request,
post_change_redirect=reverse('account_settings'),
password_change_form=form,
template_name='ksp_login/password.html')