This repository has been archived by the owner on Jan 31, 2018. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[bug 935632] Add intermediary account creation
This creates a UserProfile model which doesn't do a whole lot yet other than let us denote new users. This updates all the places where the user's name shows up to use get_display_name(). This adds a FjordVerify class which sends new users to the creation page. Right now this is sort of a stub and allows us to create a UserProfile. At some point p, this will be important and will have a profile creation form and also tell the new user what he/she can do on Input.
- Loading branch information
Showing
18 changed files
with
299 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import urlparse | ||
|
||
from django.http import HttpResponseRedirect | ||
|
||
from django_browserid.views import Verify | ||
from funfactory.urlresolvers import reverse | ||
|
||
from fjord.base.models import Profile | ||
|
||
|
||
class FjordVerify(Verify): | ||
def login_success(self): | ||
"""Send to new-user-view if new user, otherwise send on their way""" | ||
response = super(FjordVerify, self).login_success() | ||
# If this user has never logged in before, send them to our | ||
# super secret "Welcome!" page. | ||
try: | ||
self.user.profile | ||
return response | ||
|
||
except Profile.DoesNotExist: | ||
url = reverse('new-user-view') | ||
|
||
redirect_to = self.request.REQUEST.get('next') | ||
|
||
# Do not accept redirect URLs pointing to a different host. | ||
if redirect_to: | ||
netloc = urlparse.urlparse(redirect_to).netloc | ||
if netloc and netloc != self.request.get_host(): | ||
redirect_to = None | ||
|
||
if redirect_to: | ||
url = url + '?next=' + redirect_to | ||
|
||
return HttpResponseRedirect(url) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
# -*- 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 'Profile' | ||
db.create_table('base_profile', ( | ||
('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)), | ||
('user', self.gf('django.db.models.fields.related.OneToOneField')(to=orm['auth.User'], unique=True)), | ||
)) | ||
db.send_create_signal('base', ['Profile']) | ||
|
||
|
||
def backwards(self, orm): | ||
# Deleting model 'Profile' | ||
db.delete_table('base_profile') | ||
|
||
|
||
models = { | ||
'auth.group': { | ||
'Meta': {'object_name': 'Group'}, | ||
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), | ||
'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '80'}), | ||
'permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}) | ||
}, | ||
'auth.permission': { | ||
'Meta': {'ordering': "('content_type__app_label', 'content_type__model', 'codename')", 'unique_together': "(('content_type', 'codename'),)", 'object_name': 'Permission'}, | ||
'codename': ('django.db.models.fields.CharField', [], {'max_length': '100'}), | ||
'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']"}), | ||
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), | ||
'name': ('django.db.models.fields.CharField', [], {'max_length': '50'}) | ||
}, | ||
'auth.user': { | ||
'Meta': {'object_name': 'User'}, | ||
'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}), | ||
'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}), | ||
'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}), | ||
'groups': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Group']", 'symmetrical': 'False', 'blank': 'True'}), | ||
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), | ||
'is_active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}), | ||
'is_staff': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), | ||
'is_superuser': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), | ||
'last_login': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}), | ||
'last_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}), | ||
'password': ('django.db.models.fields.CharField', [], {'max_length': '128'}), | ||
'user_permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}), | ||
'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'}) | ||
}, | ||
'base.profile': { | ||
'Meta': {'object_name': 'Profile'}, | ||
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), | ||
'user': ('django.db.models.fields.related.OneToOneField', [], {'to': "orm['auth.User']", 'unique': 'True'}) | ||
}, | ||
'contenttypes.contenttype': { | ||
'Meta': {'ordering': "('name',)", 'unique_together': "(('app_label', 'model'),)", 'object_name': 'ContentType', 'db_table': "'django_content_type'"}, | ||
'app_label': ('django.db.models.fields.CharField', [], {'max_length': '100'}), | ||
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), | ||
'model': ('django.db.models.fields.CharField', [], {'max_length': '100'}), | ||
'name': ('django.db.models.fields.CharField', [], {'max_length': '100'}) | ||
} | ||
} | ||
|
||
complete_apps = ['base'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<h2>{{ _('Welcome!') }}</h2> | ||
<p> | ||
{% trans %} | ||
The identity you just logged into Persona with ties you to your | ||
account on Input. Please remember which identity you used. | ||
{% endtrans %} | ||
</p> | ||
<p> | ||
<a href="{{ next_url }}">{{ _('Onwards to your destination.') }}</a> | ||
</p> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{% extends "mobile/base.html" %} | ||
|
||
{% block page_title %}{{ _('Welcome to Input!') }}{% endblock %} | ||
|
||
{% block content %} | ||
<article> | ||
<section> | ||
{% include "includes/new_user_text.html" %} | ||
</section> | ||
</article> | ||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{% extends "base.html" %} | ||
|
||
{% block page_title %}{{ _('Welcome to Input!') }}{% endblock %} | ||
|
||
{% block content %} | ||
<div class="col"></div> | ||
<div class="col wide"> | ||
<div class="block"> | ||
{% include "includes/new_user_text.html" %} | ||
</div> | ||
</div> | ||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
from django.test.client import RequestFactory | ||
|
||
from nose.tools import eq_ | ||
|
||
from fjord.base.browserid import FjordVerify | ||
from fjord.base.tests import BaseTestCase, profile, reverse, user | ||
|
||
|
||
class TestAuth(BaseTestCase): | ||
def test_new_user(self): | ||
"""Tests that new users get redirected to new_user page""" | ||
# Create a user that has no profile--this is the sign that the | ||
# user is new! | ||
new_user = user(save=True) | ||
self.client_login_user(new_user) | ||
|
||
# Now do some ridiculous setup so we can call login_success() | ||
# on the Verify and see if it did what it should be doing. | ||
|
||
# FIXME - this can go away post django-browserid 0.9 | ||
new_user.backend = 'django_browserid.auth.BrowserIDBackend' | ||
|
||
get_request = RequestFactory().get(reverse('dashboard')) | ||
get_request.user = new_user | ||
get_request.session = self.client.session | ||
|
||
fv = FjordVerify() | ||
fv.user = new_user | ||
fv.request = get_request | ||
|
||
resp = fv.login_success() | ||
eq_(302, resp.status_code) | ||
eq_(resp.get('location'), reverse('new-user-view')) | ||
|
||
def test_existing_user(self): | ||
"""Tests that existing users get redirected to right place""" | ||
# Create a user that has no profile--this is the sign that the | ||
# user is new! | ||
new_user = user(save=True) | ||
profile(user=new_user, save=True) | ||
self.client_login_user(new_user) | ||
|
||
# Now do some ridiculous setup so we can call login_success() | ||
# on the Verify and see if it did what it should be doing. | ||
|
||
# FIXME - this can go away post django-browserid 0.9 | ||
new_user.backend = 'django_browserid.auth.BrowserIDBackend' | ||
|
||
# First, do it RAW! | ||
get_request = RequestFactory().get(reverse('dashboard')) | ||
get_request.user = new_user | ||
get_request.session = self.client.session | ||
|
||
fv = FjordVerify() | ||
fv.user = new_user | ||
fv.request = get_request | ||
|
||
resp = fv.login_success() | ||
eq_(302, resp.status_code) | ||
eq_(resp.get('location'), '/') | ||
|
||
# Now do it with next! | ||
get_request = RequestFactory().get(reverse('dashboard') + '?next=/foo') | ||
get_request.user = new_user | ||
get_request.session = self.client.session | ||
|
||
fv = FjordVerify() | ||
fv.user = new_user | ||
fv.request = get_request | ||
|
||
resp = fv.login_success() | ||
eq_(302, resp.status_code) | ||
eq_(resp.get('location'), '/foo') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.