views.py 文件源码

python
阅读 28 收藏 0 点赞 0 评论 0

项目:heatherr 作者: praekeltfoundation 项目源码 文件源码
def authorize(request):
    if request.session['authorize_state'] != request.GET['state']:
        return render(request, "account/authorize_fail.html", {
            "error": "Invalid state token.",
        })

    response = requests.post('https://slack.com/api/oauth.access', data={
        'client_id': settings.SLACK_CLIENT_ID,
        'client_secret': settings.SLACK_CLIENT_SECRET,
        'code': request.GET['code'],
        'redirect_uri': request.session['authorize_request_uri'],
    })
    data = response.json()

    account, created = SlackAccount.objects.update_or_create(
        user=request.user, team_id=data['team_id'], defaults={
            'access_token': data['access_token'],
            'scope': data['scope'],
            'team_name': data['team_name'],
            'incoming_webhook_url': data['incoming_webhook']['url'],
            'incoming_webhook_channel': data['incoming_webhook']['channel'],
            'incoming_webhook_configuration_url': (
                data['incoming_webhook']['configuration_url']),
            'bot_user_id': data['bot']['bot_user_id'],
            'bot_access_token': data['bot']['bot_access_token'],
        }
    )

    messages.success(request, "Heatherr is now linked to %s." % (
        account.team_name,))
    return redirect(reverse('accounts:profile'))
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号