Exemplo n.º 1
0
    def is_logged(self, request):
        """
        This endpoint is used to check if the user is logged in and can be treated
        as a player. If user is logged in, additional information is provided.

        Response body: \n
        `is_logged` (boolean) \n
        `player_id` (integer) - this ID should be used to consume the user API \n
        `is_new` (boolean) - true if the player model is newly created.
            Can be used to implement a "welcome message"
        """

        # administrator is not the user!
        is_logged = Player.is_user_logged(request.user)

        result = {
            "is_logged": is_logged,
        }

        if is_logged:
            player, is_new = Player.objects.get_or_create(user=request.user)

            result["player_id"] = player.pk
            result["is_new"] = is_new

        return Response(result)
Exemplo n.º 2
0
def main_page(request):
    if Player.is_user_logged(request.user):
        return redirect("/game")

    return redirect("/")