phildini / cards-against-django

CAH done as a Django web app.
Other
8 stars 4 forks source link

Password protected game support #31

Open clach04 opened 11 years ago

clach04 commented 11 years ago

either with a auto generated or user specified password

clach04 commented 10 years ago

I started to implement some support for this but not the actual "you can't view/join with out a password" logic:

diff --git a/cards/forms/game_forms.py b/cards/forms/game_forms.py
index dfebdf0..6afee0d 100644
--- a/cards/forms/game_forms.py
+++ b/cards/forms/game_forms.py
@@ -80,6 +80,11 @@ class LobbyForm(forms.Form):
                 queryset=CardSet.objects.all().order_by('-name'),
                 required=False
             )
+    password = forms.CharField(
+        max_length=140,
+        label="Optional password protection",
+        required=False
+    )

     def __init__(self, *args, **kwargs):
         self.game_list = kwargs.pop('game_list', [])
@@ -99,6 +104,7 @@ class LobbyForm(forms.Form):
             # XXX: We should feature-flag this code when we get feature flags working.
             # this is not very clever :-(
             self.fields['card_set'].widget = HiddenInput()
+            self.fields['password'].widget = HiddenInput()

     def clean_new_game(self):
         new_game = self.cleaned_data.get('new_game')
diff --git a/cards/models.py b/cards/models.py
index 65084b6..8646372 100644
--- a/cards/models.py
+++ b/cards/models.py
@@ -92,7 +92,8 @@ class Game(TimeStampedModel):
         white_deck = [ of card white numbers ],
         used_black_deck = [ of card black numbers ],
         used_white_deck = [ of card white numbers ],
-        filled_in_texts = None | [ (player name, filled in black card text), ]
+        filled_in_texts = None | [ (player name, filled in black card text), ],
+        password = None|string,  # TODO NOTE probably want a bool/str in model too/instead, for reporting (e.g. listing active games and whether they have a password)
     }

     """
@@ -249,7 +250,7 @@ class Game(TimeStampedModel):
             for x in white_submissions[tmp_name]:
                 self.gamedata['used_white_deck'].append(x)

-    def create_game(self, card_sets=None):
+    def create_game(self, card_sets=None, password=None):
         """Where `card_sets` is an iterable collection of CardSet."""

         log.logger.debug('New Game called')
@@ -301,6 +302,7 @@ class Game(TimeStampedModel):
             'mode': 'submitting',
             'filled_in_texts': None,
             'prev_filled_in_question': None,
+            'password': password,
         }

     # FIXME should be using a player object
diff --git a/cards/views/game_views.py b/cards/views/game_views.py
index 35c821f..8b52d3c 100644
--- a/cards/views/game_views.py
+++ b/cards/views/game_views.py
@@ -164,13 +164,15 @@ class LobbyView(FormView):
                 # XXX: We should feature-flag this code when we get feature flags working.
                 if self.request.user.is_staff:
                     card_set = form.cleaned_data['card_set']
+                    password = form.cleaned_data['password'] or None
                 else:
                     card_set = []
+                    password = None
                 if not card_set:
                     # Are not staff or are staff and didn't select cardset(s)
                     # Either way they get default
                     card_set = ['v1.0', 'v1.2', 'v1.3', 'v1.4']
-                new_game = tmp_game.create_game(card_set)
+                new_game = tmp_game.create_game(card_set, password=password)
                 tmp_game.gamedata = new_game
                 tmp_game.save()
                 self.game = tmp_game
@@ -431,7 +433,7 @@ class GameJoinView(GameViewMixin, FormView):
     We want to support real user accounts but also anonymous, which is why
     this is a debug routine for now.

-    TODO password protection check on join.
+    TODO password protection check on join. Should this be part of GameViewMixin or GameView?
     TODO create a game (with no players, redirect to join game for game creator).

     """
clach04 commented 10 years ago

See issue #65