示例#1
0
文件: auth.py 项目: marianvlad/lctva
    def get(self, request):
        access_code = request.GET.get('code')
        token, refresh = LiveCodingAuthClient(access_code).get_auth_token(request.user)
        livetvuser = LiveCodingClient.get_user_from_token(token)

        try:
            user = User.objects.get(username=livetvuser.username)
            user.set_password(access_code)
            user.save()
        except User.DoesNotExist:
            user = User.objects.create_user(livetvuser.username, '', access_code)
            user.userprofile.livetvusername = livetvuser.username.lower()
            user.userprofile.user = user
            user.userprofile.oauth_token = token
            user.userprofile.save()

        if user.is_superuser:
            try:
                access_token = ApiAccessToken.objects.get(user=user)
            except ApiAccessToken.DoesNotExist:
                access_token = ApiAccessToken(user=user)
            access_token.access_code = access_code
            access_token.access_token = token
            access_token.refresh_token = refresh
            access_token.save()

        user = authenticate(username=livetvuser.username, password=access_code)
        login(request, user)
        return HttpResponseRedirect(reverse("live_view"))
示例#2
0
    def get(self, request):
        access_code = request.GET.get('code')
        state = request.GET.get('state')
        try:
            token, refresh = LiveCodingAuthClient(access_code).get_auth_token(request.user)
        except KeyError:
            return HttpResponseRedirect(reverse("index_view"))
        livetvuser = LiveCodingClient.get_user_from_token(token)

        try:
            user = User.objects.get(username=livetvuser.username)
            user.set_password(state)
            user.save()
        except User.DoesNotExist:
            user = User.objects.create_user(livetvuser.username, '', state)
            user.userprofile.livetvusername = livetvuser.username.lower()
            user.userprofile.user = user
        finally:
            user.userprofile.oauth_token = token
            user.userprofile.oauth_refresh_token = refresh
            user.userprofile.oauth_access_code = access_code
            user.userprofile.save()

        user = authenticate(username=livetvuser.username, password=state)
        login(request, user)
        return HttpResponseRedirect(reverse("live_view"))
示例#3
0
    def get(self, request):
        access_code = request.GET.get('code')
        state = request.GET.get('state')
        try:
            token, refresh = LiveCodingAuthClient(access_code).get_auth_token(
                request.user)
        except KeyError:
            return HttpResponseRedirect(reverse("index_view"))
        livetvuser = LiveCodingClient.get_user_from_token(token)

        try:
            user = User.objects.get(username=livetvuser.username)
            user.set_password(state)
            user.save()
        except User.DoesNotExist:
            user = User.objects.create_user(livetvuser.username, '', state)
            user.userprofile.livetvusername = livetvuser.username.lower()
            user.userprofile.user = user
        finally:
            user.userprofile.oauth_token = token
            user.userprofile.oauth_refresh_token = refresh
            user.userprofile.oauth_access_code = access_code
            user.userprofile.save()

        user = authenticate(username=livetvuser.username, password=state)
        login(request, user)
        return HttpResponseRedirect(reverse("live_view"))
示例#4
0
def watch_viewers():
    streams = LiveCodingClient("taddeimania").get_onair_streams().results
    streamers = dict([(stream['user__slug'], stream['viewers_live'])
                      for stream in streams])
    total_viewers = sum(streamers.values())
    for livetvusername in streamers.keys():
        viewer_count = streamers[livetvusername]
        Node.objects.create(current_total=viewer_count,
                            total_site_streamers=total_viewers,
                            livetvusername=livetvusername)
示例#5
0
文件: auth.py 项目: Craytor/lctva
    def get(self, request):
        code = request.GET.get("code")
        client = LiveCodingAuthClient(code)
        token = client.get_auth_token(request.user)
        livetvuser = LiveCodingClient.get_user_from_token(token)

        user = self.request.user
        try:
            user.userprofile.livetvusername = livetvuser.username.lower()
            user.userprofile.verified = True
            user.userprofile.save()
        except AttributeError:
            return HttpResponseRedirect("{}?api_error={}".format(reverse("account_verify"), livetvuser.detail))
        return HttpResponseRedirect(reverse("live_view"))
示例#6
0
    def get(self, request):
        code = request.GET.get("code")
        client = LiveCodingAuthClient(code)
        token = client.get_auth_token(request.user)
        livetvuser = LiveCodingClient.get_user_from_token(token)

        user = self.request.user
        try:
            user.userprofile.livetvusername = livetvuser.username.lower()
            user.userprofile.verified = True
            user.userprofile.save()
        except AttributeError:
            return HttpResponseRedirect("{}?api_error={}".format(
                reverse("account_verify"), livetvuser.detail))
        return HttpResponseRedirect(reverse("live_view"))
示例#7
0
 def get_context_data(self, datestamp):
     context = super().get_context_data()
     day = datetime.datetime.strptime(datestamp, "%Y-%m-%d").date()
     livetvusername = self.request.user.userprofile.livetvusername
     day_nodes = Node.objects.filter(livetvusername=livetvusername,
                                     timestamp__contains=day)
     x_data, y_data = unzip_data(
         prepare_data_for_plot(
             day_nodes.values_list("timestamp", "current_total"),
             livetvusername))
     context["breakdown"] = daily_aggregator(day_nodes)[0]
     context["y_data"] = y_data
     context["x_data"] = x_data
     context["videos"] = [
         vid for generator in LiveCodingClient(
             livetvusername).get_user_videos()
         for vid in generator if datetime.datetime.strptime(
             vid.creation_time[:10], "%Y-%m-%d").date() == day
     ]
     context["max_y"] = max(y_data)
     return context
示例#8
0
文件: auth.py 项目: marianvlad/lctva
 def get_redirect_url(self, *args, **kwargs):
     return LiveCodingClient.get_redirect_url()
示例#9
0
 def get_redirect_url(self, *args, **kwargs):
     return LiveCodingClient.get_redirect_url()