Compare commits

..

No commits in common. "3b864412597742fc27af235f340de11e81001752" and "eac835bef51cfa7565bc5f9bf1d4931dcf7c8ed2" have entirely different histories.

1 changed files with 28 additions and 31 deletions

View File

@ -10,46 +10,43 @@ import os
oauth = OAuth()
oauth.register(
name='discord',
client_id=os.getenv('OAUTH2_DISCORD_CLIENT_ID'),
client_secret=os.getenv('OAUTH2_DISCORD_CLIENT_SECRET'),
access_token_url='https://discord.com/api/oauth2/token',
authorize_url='https://discord.com/api/oauth2/authorize',
client_kwargs={'scope': 'identify'},
api_base_url='https://discord.com/api/'
name='discord',
client_id=os.getenv('OAUTH2_DISCORD_CLIENT_ID'),
client_secret=os.getenv('OAUTH2_DISCORD_CLIENT_SECRET'),
access_token_url='https://discord.com/api/oauth2/token',
authorize_url='https://discord.com/api/oauth2/authorize',
client_kwargs={'scope': 'identify'},
api_base_url='https://discord.com/api/'
)
@login_required
@require_POST
def connect(request):
if request.user.userprofileinfo.discord_id:
return bad_request(request, "Already connected")
site = Site.objects.get_current()
redirect_uri = reverse('accounts:connections-connect-discord-authorize')
redirect_uri = "https://" + site.domain + redirect_uri[3:] # remove language code
print(redirect_uri)
return oauth.discord.authorize_redirect(request, redirect_uri)
if request.user.userprofileinfo.discord_id:
return bad_request(request, "Already connected")
site = Site.objects.get_current()
redirect_uri = reverse('accounts:connections-connect-discord-authorize')
redirect_uri = "https://" + site.domain + redirect_uri[3:] # remove language code
print(redirect_uri)
return oauth.discord.authorize_redirect(request, redirect_uri)
@login_required
def authorize(request):
if request.user.userprofileinfo.discord_id:
return bad_request(request, "Already connected")
try:
token = oauth.discord.authorize_access_token(request)
except:
bad_request(request, "Connection refused")
response = oauth.discord.get('users/@me', token=token)
response = response.json()
discord_id = response['id']
request.user.userprofileinfo.discord_id = discord_id
request.user.userprofileinfo.save()
return redirect('accounts:edit')
if request.user.userprofileinfo.discord_id:
return bad_request(request, "Already connected")
token = oauth.discord.authorize_access_token(request)
response = oauth.discord.get('users/@me', token=token)
response = response.json()
discord_id = response['id']
request.user.userprofileinfo.discord_id = discord_id
request.user.userprofileinfo.save()
return redirect('accounts:edit')
@login_required
@require_POST
def disconnect(request):
if not request.user.userprofileinfo.discord_id:
return bad_request(request, "Already disconnected")
request.user.userprofileinfo.discord_id = None
request.user.userprofileinfo.save()
return redirect('accounts:edit')
if not request.user.userprofileinfo.discord_id:
return bad_request(request, "Already disconnected")
request.user.userprofileinfo.discord_id = None
request.user.userprofileinfo.save()
return redirect('accounts:edit')