Commits

A Lee committed 4964391

naive first cut at socialauth signal handlers for new registrants.

Should replace automated experiment with a dashboard that lets you join different experiment apps?

might also need a way to specify "auto-join" experiments

Comments (0)

Files changed (3)

vcweb/core/models.py

 from django.utils.translation import ugettext_lazy as _
 from string import Template
 from vcweb.core import signals, simplecache
+from social_auth.backends.facebook import FacebookBackend
+import social_auth.signals 
 
 import base64
 import hashlib
         '''
         return self.max_group_size == 0
 
+    @is_open.setter
+    def is_open(self, value):
+        self.max_group_size = 0
+
     @property
     def final_sequence_number(self):
         # FIXME: or max round_configurations.sequence_number (degenerate data)
 
     def add_participant(self, participant, current_group=None):
         if current_group is None:
-            current_group = self.group_set.reverse()[0]
+            if self.group_set.count() > 0:
+# pick the last group in group_set
+                current_group = self.group_set.reverse()[0]
+            else:
+                current_group = self.group_set.create(number=1, max_size=self.experiment_configuration.max_group_size)
         return current_group.add_participant(participant)
 
 
     returns true if user.participant exists and is a Participant instance.
     """
     return hasattr(user, 'participant') and isinstance(user.participant, Participant)
+
+# signal handlers for socialauth
+@receiver(social_auth.signals.socialauth_registered, sender=None)
+def handle_new_socialauth_user(sender, user, response, details, **kwargs):
+    logger.debug("new socialauth user: %s, %s, %s, %s", user, response, details, kwargs)
+    participant = Participant.objects.create(user=user)
+# add participant to each available open experiment
+    for experiment in Experiment.objects.filter(experiment_configuration__max_group_size=0):
+        experiment.add_participant(participant)
+
+
+@receiver(social_auth.signals.pre_update, sender=FacebookBackend)
+def facebook_extra_values(sender, user, response, details, **kwargs):
+    user.gender = response.get('gender')
+    return True
+

vcweb/settings.py

         'social_auth.backends.twitter.TwitterBackend',
         'social_auth.backends.facebook.FacebookBackend',
 #        'social_auth.backends.google.GoogleOAuthBackend',
-#        'social_auth.backends.google.GoogleOAuth2Backend',
+        'social_auth.backends.google.GoogleOAuth2Backend',
         'social_auth.backends.google.GoogleBackend',
         'social_auth.backends.yahoo.YahooBackend',
 #        'social_auth.backends.browserid.BrowserIDBackend',
 #        'social_auth.backends.contrib.dropbox.DropboxBackend',
         'social_auth.backends.contrib.flickr.FlickrBackend',
 #        'social_auth.backends.contrib.instagram.InstagramBackend',
-#        'social_auth.backends.OpenIDBackend',
+        'social_auth.backends.OpenIDBackend',
         "vcweb.core.auth.AuthenticationBackend",
         "django.contrib.auth.backends.ModelBackend",
         )
     url(r'^sanitation/', include('vcweb.sanitation.urls', namespace='sanitation', app_name='sanitation')),
     url(r'^lighterprints/', include('vcweb.lighterprints.urls', namespace='lighterprints', app_name='lighterprints')),
     url(r'^admin/', include(admin.site.urls)),
+    # social auth urls for logging in via fb, google, foursquare, etc.
     url(r'', include('social_auth.urls')),
     # core catches everything else
     url(r'', include('vcweb.core.urls', namespace='core', app_name='core')),