Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files
XDATA-439 implementing EmailUser from module custom_user which satisf…
…ies the "username length" problem, but also properly implements using email as the "username" instead of having a separate user name field.
  • Loading branch information
arf1855 committed Dec 3, 2015
1 parent 05324ef commit bc1c9b219627271b1b135ea7bc890d7d74389d96
Show file tree
Hide file tree
Showing 21 changed files with 63 additions and 68 deletions.
@@ -2,11 +2,11 @@

{% block content %}

<h1>Please enter your new User information:</h1>
<h1>Please enter your new user information:</h1>
<form method="POST" action="{% url 'exp_portal:new_user' %}">
<div class="form-group">
<label for="id_username">Userame</label>
<input class="form-control" name="username" id="id_username" placeholder='Enter the userame' size="60" required/>
<label for="id_email">Email</label>
<input class="form-control" name="email" id="id_email" placeholder='Enter the email' size="255" required/>
</div>
<div class="form-group">
<label for="id_password_1">Password</label>
@@ -3,7 +3,7 @@
{% block content %}

<h1>Add Tasks for Participant:</h1>
<h3>{{ userprofile.user.username }} has {{userprofile.tasklistitem_set.count}} tasks</h3>
<h3>{{ userprofile.user.email }} has {{userprofile.tasklistitem_set.count}} tasks</h3>

<div class="col-md-15">
<table class="table table-hover">
@@ -19,7 +19,7 @@ <h1>Completed Tasks</h1>
{% for task in completed_tasks %}
<tr>
<td>{{ forloop.counter }}</td>
<td>{{ task.userprofile.user.username }}</td>
<td>{{ task.userprofile.user.email }}</td>
<td>{{ task.op_task.name }}</td>
<td>{{ task.date_complete }}</td>
<td>{{ task.activity_count }}</td>
@@ -18,7 +18,7 @@ <h1>Incomplete Tasks</h1>
{% for task in incomplete_tasks %}
<tr>
<td>{{ forloop.counter }}</td>
<td>{{ task.userprofile.user.username }}</td>
<td>{{ task.userprofile.user.email }}</td>
<td>{{ task.op_task.name }}</td>
<td>{{ task.userprofile.user.date_joined }}</td>
{% endfor %}
@@ -140,7 +140,7 @@ <h1 id="expStatusHeader">Experiment Status</h1>
<div class="expTrayBody">
<div id="users" class="expTraySection active">
<ul id="usersHeader" class="trayTableHeader">
<li class="username">Username</li>
<li class="email">Email</li>
<li class="progressBar">Progress</li>
<li class="lastLogin">Last Login</li>
</ul>
@@ -149,7 +149,7 @@ <h1 id="expStatusHeader">Experiment Status</h1>
{% if 'users' in expObjKey %}
{% for user in expObjVal %}
<li>
<div class="username">
<div class="email">
<a href="{% url 'exp_portal:view_user_tasks' profile=user.user_hash %}">
{{ user }}
</a>
@@ -277,7 +277,7 @@ <h1 id="expStatusHeader">Experiment Status</h1>
{% for completedTask in expObjVal %}
<li>
<div class="taskCompletedUser">
{{ completedTask.userprofile.user.username }}
{{ completedTask.userprofile.user.email }}
</div>
<div class="taskCompletedName">
{{ completedTask.op_task.name }}
@@ -306,7 +306,7 @@ <h1 id="expStatusHeader">Experiment Status</h1>
{% for incompleteTask in expObjVal %}
<li>
<div class="taskIncompleteUser">
{{ incompleteTask.userprofile.user.username }}
{{ incompleteTask.userprofile.user.email }}
</div>
<div class="taskIncompleteName">
{{ incompleteTask.op_task.name }}
@@ -3,7 +3,7 @@
{% block content %}

<h1>Participant Info</h1>
<h3>Username: {{ userprofile.user.username }}</h3>
<h3>Email: {{ userprofile.user.email }}</h3>

<h3> Experiment </h3>
<form method="POST" action="{% url 'exp_portal:edit_user' userprofilepk=userprofile.pk %}">
@@ -14,7 +14,7 @@ <h1>Registered Participants</h1>
<thead>
<tr>
<th>Item</th>
<th>Username</th>
<th>Email</th>
<th>Experiment</th>
<th>Progress</th>
<th>Last Login</th>
@@ -27,7 +27,7 @@ <h1>Registered Participants</h1>
<td>{{ forloop.counter }}</td>
<td>
<a href="{% url 'exp_portal:view_user_tasks' profile=userprofile.user_hash %}">
{{ userprofile.user.username }}
{{ userprofile.user.email }}
</a>
</td>
<td>{{ userprofile.experiment }}</td>
@@ -32,7 +32,7 @@ def test_can_count_completed_tasks(self):
task = OpTask(dataset=dataset, name='test_task', survey_url='test_url')
task.save()

user = User(username='john', password=make_password('paul'))
user = User(email='john@test.com', password=make_password('paul'))
user.save()

userprofile = UserProfile(user=user)
@@ -1,7 +1,8 @@
from django.shortcuts import render, redirect
from op_tasks.models import UserProfile, Product, Dataset, OpTask, TaskListItem, Experiment
from django.contrib.auth.decorators import login_required
from django.contrib.auth.models import User
from django.contrib.auth import get_user_model

from django.http import JsonResponse

@login_required(login_url='/tasking/login')
@@ -50,9 +51,8 @@ def delete_user(request, userprofilepk):

@login_required(login_url='/tasking/login')
def new_user(request):
user = User(username=request.POST['username'])
user = get_user_model()(email=request.POST['email'])
user.set_password(request.POST['password_1'])
user.email = user.username
user.save()

userprofile = UserProfile()
@@ -83,7 +83,7 @@ def test_can_register_a_user_with_tasks(self):
self.browser.find_element_by_id("intro-complete").submit()

# register a new user
inputemail = self.browser.find_element_by_name("username")
inputemail = self.browser.find_element_by_name("email")
inputemail.send_keys("new@test.com")

inputpassword = self.browser.find_element_by_name("password")
@@ -98,7 +98,7 @@ def test_can_register_a_user_with_tasks(self):
# check successful registration
saved_users = User.objects.all()
self.assertEqual(saved_users.count(), 1)
self.assertEqual(saved_users[0].username, 'new@test.com')
self.assertEqual(saved_users[0].email, 'new@test.com')

saved_products = Product.objects.all()
self.assertEqual(saved_products.count(), 1)
@@ -109,8 +109,8 @@ def test_can_register_a_user_with_tasks(self):
first_task = saved_task_list_items[0]
second_task = saved_task_list_items[1]
self.assertEqual(first_task.userprofile, second_task.userprofile)
self.assertEqual(first_task.userprofile.user.username, 'new@test.com')
self.assertEqual(second_task.userprofile.user.username, 'new@test.com')
self.assertEqual(first_task.userprofile.user.email, 'new@test.com')
self.assertEqual(second_task.userprofile.user.email, 'new@test.com')

# def test_can_show_STOUT_and_ALE_integration(self):
# experiment admin page load showing experiment setup
@@ -1,6 +1,7 @@
from django.core.management.base import BaseCommand
from django.contrib.auth.hashers import make_password
from django.contrib.auth.models import User
#from django.contrib.auth.models import User
from django.contrib.auth import get_user_model
from django.conf import settings
from django.conf.urls.static import static

@@ -27,9 +28,9 @@ class Command(BaseCommand):
help = 'our help string comes here'

def _create_admin_profile(self):
staff_users = User.objects.filter(is_staff=True)
staff_users = get_user_model().objects.filter(is_staff=True)
admin = staff_users[0]
print admin.username
print admin.email

userprofile = UserProfile(user=admin)
userprofile.save()
@@ -38,8 +39,7 @@ def _create_user(self):
# fix this later; need a logical method for experiment assignment
saved_experiments = Experiment.objects.all()

user = User(username='test@test.com', password=make_password('test'))
user.email = user.username
user = get_user_model()(email='test@test.com', password=make_password('test'))
user.save()

userprofile = UserProfile(user=user)
@@ -1,5 +1,6 @@
from django.db import models
from django.contrib.auth.models import User
#from django.contrib.auth.models import User
from django.conf import settings
import hashlib
import time, datetime

@@ -70,7 +71,7 @@ def __unicode__(self):


class UserProfile(models.Model):
user = models.OneToOneField(User)
user = models.OneToOneField(settings.AUTH_USER_MODEL)
user_hash = models.CharField(max_length=30, default=_createHash, unique=True, editable=False)
progress = models.IntegerField(default=0)

@@ -87,7 +88,7 @@ class UserProfile(models.Model):


def __unicode__(self):
return self.user.username
return self.user.email

def read_instructions(self):
return self.exp_inst_complete and self.portal_inst_complete and self.task_inst_complete
@@ -118,7 +119,7 @@ def _both_complete(self):
both_complete = property(_both_complete)

def __unicode__(self): # Python 3: def __str__(self):
return '%s, %s, %s' % (self.userprofile.user.username, self.op_task, self.index)
return '%s, %s, %s' % (self.userprofile.user.email, self.op_task, self.index)

class Meta:
ordering = ('userprofile', 'index')
@@ -138,4 +139,4 @@ class UserAchievement(models.Model):
achievement = models.ForeignKey(Achievement)

def __unicode__(self):
return '%s - %s' % (self.userprofile.user.username, self.achievement.name)
return '%s - %s' % (self.userprofile.user.email, self.achievement.name)
@@ -45,7 +45,7 @@ <h3>AFFILIATED SITE

<br>You will first be asked to complete questionnaires which gather information about your demographic information, education, personality, and analytic experience. This is estimated to take approximately 30-60 minutes of your time. Prior to completing these measures, you will be asked whether or not you agree and assent to the terms mentioned in this consent form. If you agree with and assent to these terms, you will proceed to the questionnaires, all of which can be answered online via a secure web-survey that is hosted through SurveyMonkey.com, a reputable company that hosts web-based surveys and allows for complete confidentiality through the use of sophisticated data-encryption techniques (all data submitted through SurveyMonkey.com is encrypted through secure socket encryption (SSL)). SurveyMonkey.com's data security and privacy statement will be made available to you upon request.

<p>If you are recruited for an online experiment, the online consent form and online intake survey will be made available to you via a web-based portal that will give you directions as to which tasks (see below) we are asking you to complete and the sequence with which we wish you to complete them. A link to this portal will accompany recruitment materials and will guide you through a brief registration that will provide you with a username and password for repeated access to the portal.
<p>If you are recruited for an online experiment, the online consent form and online intake survey will be made available to you via a web-based portal that will give you directions as to which tasks (see below) we are asking you to complete and the sequence with which we wish you to complete them. A link to this portal will accompany recruitment materials and will guide you through a brief registration that will provide you with a username (a valid email address) and password for repeated access to the portal.

<p>If you are recruited for a laboratory experiment, the online consent form and online intake survey will be distributed to you as a link embedded in an email sent to you via study personnel.

@@ -6,7 +6,7 @@ <h1 align="center"><b>Login to XDATA Online</b></h1>
<form class="form-signin" id="login_form" method="post" action="{% url 'op_tasks:login' %}">
{% csrf_token %}
<h4 class="form-signin-heading">Please sign in</h4>
<input class="form-control" name="username" value="" placeholder="Username" required autofocus/>
<input class="form-control" name="email" value="" placeholder="Email" required autofocus/>
<input class="form-control" type="password" name="password" value="" placeholder="Password" required/>
<button class="btn btn-lg btn-primary btn-block" type="submit" value="submit">Sign in</button>
</form>
@@ -13,8 +13,8 @@ <h2 class="form-signin-heading">Create an account</h2>

<div class="form-group">
<p class="required">
<label for="id_email">Username: (please use a valid email address)</label>
<input class="form-control" id="id_email" name="username" type="email" placeholder="Enter email"/>
<label for="id_email">Email: (please use a valid email address)</label>
<input class="form-control" id="id_email" name="email" type="email" placeholder="Enter email"/>
</p>
</div>
<div class="form-group">
@@ -5,7 +5,7 @@
{% block reset_link %}
{{ protocol }}://{{ domain }}{% url 'op_tasks:reset_confirm' uidb64=uid token=token %}
{% endblock %}
Your username, in case you've forgotten: {{ user.get_username }}
Your username, in case you've forgotten: {{ user.email }}

Thanks for using our site!

@@ -30,8 +30,7 @@ def test_user_can_be_assigned_an_experiment(self):
saved_experiments = Experiment.objects.all()
self.assertEqual(saved_experiments.count(), 1)

user = User(username='Bob', password=make_password('Bob') )
user.email = user.username
user = User(email='Bob@test.com', password=make_password('Bob') )
user.save()

saved_users = User.objects.all()
@@ -75,12 +74,7 @@ def test_saving_and_retrieving_product(self):
self.assertEqual(first_product.instructions, 'http://www.si.com')

def test_saving_and_retrieving_user(self):
# either of the methods below works...
user = User(username='Bob', password=make_password('Bob') )
# user = User()
# user.username = 'Bob'
# user.set_password('Bob')
user.email = user.username
user = User(email='Bob@test.com', password=make_password('Bob') )
user.save()

saved_users = User.objects.all()
@@ -94,12 +88,10 @@ def test_saving_and_retrieving_user(self):
self.assertEqual(saved_profiles.count(), 1)

first_profile = saved_profiles[0]
self.assertEqual(first_profile.user.username, 'Bob')
self.assertEqual(first_profile.user.username, first_profile.user.email)
self.assertEqual(first_profile.user.email, 'Bob@test.com')

def test_can_get_profile_from_user(self):
user = User(username='George', password=make_password('George'))
user.email = user.username
user = User(email='George@test.com', password=make_password('George'))
user.save()

userprofile = UserProfile(exp_inst_complete=True, portal_inst_complete=True)
@@ -175,17 +167,17 @@ def test_can_match_product_and_task_by_dataset(self):

def test_can_find_users_tasks(self):
# create a bunch of users
user1 = User(username='John', password=make_password('John'))
user1 = User(email='John@test.com', password=make_password('John'))
user1.save()
userprofile1 = UserProfile(user=user1)
userprofile1.save()

user2 = User(username='Paul', password=make_password('Paul'))
user2 = User(email='Paul@test.com', password=make_password('Paul'))
user2.save()
userprofile2 = UserProfile(user=user2)
userprofile2.save()

user3 = User(username='Ringo', password=make_password('Ringo'))
user3 = User(email='Ringo@test.com', password=make_password('Ringo'))
user3.save()
userprofile3 = UserProfile(user=user3)
userprofile3.save()
@@ -220,19 +212,19 @@ def test_can_find_users_tasks(self):
saved_userprofiles = UserProfile.objects.all()
for userprofile in saved_userprofiles:
matched_task_items = userprofile.tasklistitem_set.all()
if userprofile.user.username == 'John':
if userprofile.user.email == 'John@test.com':
self.assertEqual(matched_task_items.count(),2)
else:
self.assertEqual(matched_task_items.count(),0)

def test_can_assign_user_achievements(self):
# create a bunch of users
user = User(username='John', password=make_password('John'))
user = User(email='John@test.com', password=make_password('John'))
user.save()
userprofile = UserProfile(user=user)
userprofile.save()

userTwo = User(username='Paul', password=make_password('Paul'))
userTwo = User(email='Paul@test.com', password=make_password('Paul'))
userTwo.save()
userprofileTwo = UserProfile(user=userTwo)
userprofileTwo.save()
@@ -260,7 +252,7 @@ def test_can_assign_user_achievements(self):
self.assertEqual(saved_userachievements.count(), 2)

for saved_userachievement in saved_userachievements:
if saved_userachievement.userprofile.user.username == 'Paul':
if saved_userachievement.userprofile.user.email == 'Paul@test.com':
self.assertEqual(saved_userachievement.achievement.name, 'One')

try:
@@ -273,7 +265,7 @@ def test_can_assign_user_achievements(self):


def test_can_check_achievement_conditions(self):
user = User(username='John', password=make_password('John'))
user = User(email='John@test.com', password=make_password('John'))
user.save()
userprofile = UserProfile(user=user)
userprofile.referrals = 3

0 comments on commit bc1c9b2

Please sign in to comment.