Commit 2c0dead3 by Jason Bau Committed by Sef Kloninger

Revert "experiment for unauthenticated access"

This reverts commit e987b11d.
parent 7d277708
from django.utils.crypto import get_random_string
from .models import AnonymousUserExpt
from django.db import transaction
from dogapi import dog_stats_api
TEST_COOKIE_NAME = "anonUserTest"
def get_random_anon_username():
candidate = get_random_string(64)
while AnonymousUserExpt.objects.filter(username=candidate).exists():
candidate = get_random_string(64)
return candidate
class ExperimentalUserMiddleware(object):
def process_request(self, request):
# Test if our test anonymous cookie is set
if not request.COOKIES.get(TEST_COOKIE_NAME):
with dog_stats_api.timer('unauth_experiment.middleware.add_new_anon_user'):
with transaction.commit_on_success():
anon_username = get_random_anon_username()
anon_user = AnonymousUserExpt(username=anon_username,
user_agent=request.META.get('HTTP_USER_AGENT', ''))
anon_user.save()
# tag request with the username we set, so the response can set the cookie
request._expt_anon_username = anon_username
dog_stats_api.increment("unauth_experiment.middleware.new_anon_user")
return None
def process_response(self, request, response):
name_to_set = getattr(request, '_expt_anon_username', None)
if name_to_set:
# age is 3 months
response.set_cookie(TEST_COOKIE_NAME, name_to_set, max_age=7776000)
return response
# -*- coding: utf-8 -*-
import datetime
from south.db import db
from south.v2 import SchemaMigration
from django.db import models
class Migration(SchemaMigration):
def forwards(self, orm):
# Adding model 'AnonymousUserExpt'
db.create_table('unauth_experiment_anonymoususerexpt', (
('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
('username', self.gf('django.db.models.fields.CharField')(db_index=True, max_length=64, null=True, blank=True)),
('user_agent', self.gf('django.db.models.fields.TextField')(null=True, blank=True)),
))
db.send_create_signal('unauth_experiment', ['AnonymousUserExpt'])
def backwards(self, orm):
# Deleting model 'AnonymousUserExpt'
db.delete_table('unauth_experiment_anonymoususerexpt')
models = {
'unauth_experiment.anonymoususerexpt': {
'Meta': {'object_name': 'AnonymousUserExpt'},
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'user_agent': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}),
'username': ('django.db.models.fields.CharField', [], {'db_index': 'True', 'max_length': '64', 'null': 'True', 'blank': 'True'})
}
}
complete_apps = ['unauth_experiment']
\ No newline at end of file
# -*- coding: utf-8 -*-
import datetime
from south.db import db
from south.v2 import SchemaMigration
from django.db import models
class Migration(SchemaMigration):
def forwards(self, orm):
# Adding field 'AnonymousUserExpt.created_datetime'
db.add_column('unauth_experiment_anonymoususerexpt', 'created_datetime',
self.gf('django.db.models.fields.DateTimeField')(auto_now_add=True, null=True, blank=True),
keep_default=False)
# Adding field 'AnonymousUserExpt.modified_datetime'
db.add_column('unauth_experiment_anonymoususerexpt', 'modified_datetime',
self.gf('django.db.models.fields.DateTimeField')(auto_now=True, null=True, blank=True),
keep_default=False)
def backwards(self, orm):
# Deleting field 'AnonymousUserExpt.created_datetime'
db.delete_column('unauth_experiment_anonymoususerexpt', 'created_datetime')
# Deleting field 'AnonymousUserExpt.modified_datetime'
db.delete_column('unauth_experiment_anonymoususerexpt', 'modified_datetime')
models = {
'unauth_experiment.anonymoususerexpt': {
'Meta': {'object_name': 'AnonymousUserExpt'},
'created_datetime': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'null': 'True', 'blank': 'True'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'modified_datetime': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'null': 'True', 'blank': 'True'}),
'user_agent': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}),
'username': ('django.db.models.fields.CharField', [], {'db_index': 'True', 'max_length': '64', 'null': 'True', 'blank': 'True'})
}
}
complete_apps = ['unauth_experiment']
\ No newline at end of file
from django.db import models
# Create your models here.
class AnonymousUserExpt(models.Model):
username = models.CharField(max_length=64, db_index=True, null=True, blank=True)
user_agent = models.TextField(null=True, blank=True)
created_datetime = models.DateTimeField(auto_now_add=True, null=True)
modified_datetime = models.DateTimeField(auto_now=True, null=True)
...@@ -639,9 +639,6 @@ MIDDLEWARE_CLASSES = ( ...@@ -639,9 +639,6 @@ MIDDLEWARE_CLASSES = (
# For A/B testing # For A/B testing
'waffle.middleware.WaffleMiddleware', 'waffle.middleware.WaffleMiddleware',
# Experimentation with anonymous users,
'unauth_experiment.middleware.ExperimentalUserMiddleware',
) )
############################### Pipeline ####################################### ############################### Pipeline #######################################
...@@ -1006,9 +1003,6 @@ INSTALLED_APPS = ( ...@@ -1006,9 +1003,6 @@ INSTALLED_APPS = (
# CME Registration # CME Registration
'cme_registration', 'cme_registration',
# Experimental
'unauth_experiment',
) )
######################### MARKETING SITE ############################### ######################### MARKETING SITE ###############################
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment