コード例 #1
0
    def login(self):
        self.user = self.serializer.validated_data['user']
        metamask_address = self.serializer.validated_data['address']
        try:
            p = Profile.objects.get(user=self.user)
        except ObjectDoesNotExist:
            init_profile(self.user, is_social=True, metamask_address=metamask_address,
                         lang=self.serializer.context['request'].COOKIES.get('lang', 'en'))
            self.user.save()

        return super().login()
コード例 #2
0
ファイル: views.py プロジェクト: dappcenter/rubic_backend
def FacebookAuth(request):
    print('new auth func', flush=True)
    input_token = request.data['access_token']
    host = request.get_host()
    print('input token:', input_token, flush=True)

    access_token = requests.get(
        'https://graph.facebook.com/oauth/access_token',
        params={
            'client_id': FACEBOOK_CLIENT_IDS[host],
            'client_secret': FACEBOOK_CLIENT_SECRETS[host],
            'grant_type': 'client_credentials'
        })

    print('access token', access_token, flush=True)

    response = requests.get('https://graph.facebook.com/debug_token',
                            params={
                                'access_token':
                                json.loads(
                                    access_token.content)['access_token'],
                                'input_token':
                                input_token
                            })

    user_id = json.loads(response.content)['data']['user_id']

    user = User.objects.filter(username=user_id).first()

    if user is None:
        res = requests.get(
            'https://graph.facebook.com/v4.0/{}'.format(user_id),
            params={'access_token': input_token})
        user_data = json.loads(res.content.decode('utf-8'))
        first_name, last_name = user_data['name'].split(' ')
        user = User.objects.create_user(username=user_id,
                                        first_name=first_name,
                                        last_name=last_name)
        init_profile(user,
                     is_social=True,
                     lang=request.COOKIES.get('lang', 'en'))
        user.save()

    login(request, user)

    return Response({'status': 'ok'})
コード例 #3
0
 def login(self):
     self.user = self.serializer.validated_data['user']
     try:
         p = self.user.profile
     except ObjectDoesNotExist:
         print('try create user', flush=True)
         self.user.username = str(self.user.id)
         init_profile(self.user, is_social=True, lang=self.serializer.context['request'].COOKIES.get('lang', 'en'))
         self.user.save()
         print('user_created', flush=True)
     if self.user.profile.use_totp:
         totp = self.serializer.validated_data.get('totp', None)
         if not totp:
             logout(self.request)
             raise PermissionDenied(1032)
         if not valid_totp(self.user, totp):
             logout(self.request)
             raise PermissionDenied(1033)
     return super().login()