Skip to content

Commit

Permalink
fix bug 778474 - enable browserid for all locales
Browse files Browse the repository at this point in the history
  • Loading branch information
groovecoder committed Aug 22, 2012
1 parent 857f3fe commit c29c8f7
Show file tree
Hide file tree
Showing 14 changed files with 44 additions and 178 deletions.
11 changes: 1 addition & 10 deletions apps/demos/templates/demos/submit_noauth.html
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
{% extends "demos/base.html" %}

{% set use_browserid = LANG|lower in config.BROWSERID_LOCALES.split(' ') %}

{% set obj = submission %}
{% set submit_url=url('demos_submit') %}
{% set login_url='%s?next=%s' % (url('users.login'), submit_url) %}
{% if use_browserid %}
{% set signup_url=login_url %}
{% else %}
{% set signup_url=url('users.register') | e %}
{% endif %}
{% set signup_url=login_url %}

{% block pageid %}demos-submit{% endblock %}
{% block bodyclass %}section-demos plain{% endblock %}
Expand Down Expand Up @@ -69,9 +63,6 @@ <h3 class="mod-title">{{_('Preparing Your Demo')}}</h3>
{% endtrans %}

<p class="choices">
{% if not use_browserid %}
<a href="{{signup_url}}" class="button positive">{{_('Create an Account')}}</a>
{% endif %}
<a href="{{login_url}}" class="button">{{_('Log In to Account')}}</a>
</p>

Expand Down
2 changes: 0 additions & 2 deletions apps/demos/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,6 @@ def setUp(self):

def test_submit_loggedout(self):
r = self.client.get(reverse('demos_submit'))
# Check for at least the login button. Registration button may or may
# not appear, depending on BrowserID availability.
choices = pq(r.content)('p.choices a[href*="login"]')
eq_(choices.length, 1)

Expand Down
6 changes: 6 additions & 0 deletions apps/devmo/context_processors.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ def i18n(request):
}


def next_url(request):
if 'login' not in request.path and 'register' not in request.path:
return {'next_url': request.path }
return {}


def phpbb_logged_in(request):
"""Detect PHPBB login cookie."""
return {
Expand Down
4 changes: 0 additions & 4 deletions apps/devmo/templates/devmo/profile_edit.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{% extends "base.html" %}
{% set use_browserid = LANG|lower in config.BROWSERID_LOCALES.split(' ') %}

{% block pageid %}{% endblock %}

Expand Down Expand Up @@ -53,9 +52,6 @@ <h1 class="page-title">{{ profile.user.username }}</h1>

<ul>
<li><a href="{{ url('devmo.views.profile_view', username=profile.user.username) }}">{{ _('View profile') }}</a></li>
{% if not use_browserid %}
<li><a href="{{ url('users.pw_change') }}">{{ _('Change password') }}</a></li>
{% endif %}
{# TODO: Implement account deletion #}
{# <li class="delete"><a href="#">{{ _('Delete my account') }}</a></li> #}
</ul>
Expand Down
17 changes: 0 additions & 17 deletions apps/users/templates/users/browserid_header_signin.html

This file was deleted.

22 changes: 0 additions & 22 deletions apps/users/templates/users/change_email.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@
{% from "layout/errorlist.html" import errorlist %}
{% set title = _('Change Email Address') %}
{% set classes = 'change_email' %}
{% set use_browserid = LANG|lower in config.BROWSERID_LOCALES.split(' ') %}

{% block content %}
<section id="content">
<div class="wrap">
<div id="content-main" class="full">
<article id="change-email" class="main">
{% if use_browserid %}
<h1>{{ _('Change email with BrowserID') }}</h1>
<form class="browserid boxed" action="{{url('users.browserid_change_email')}}" method="POST">
<input type="hidden" name="next" value="{{ next_url }}" />
Expand All @@ -36,26 +34,6 @@ <h3>What's this?</h3>
</ul>
{% endif %}
</form>
{% else %}
<h1>{{ title }}</h1>
<p>
{% trans %}
You will need to confirm the newly set email address to complete
the change.
{% endtrans %}
</p>
<form class="boxed" method="post" action="">
{{ csrf() }}
<fieldset>
<ul>
{{ form.as_ul()|safe }}
<li class="submit">
<button type="submit">{{ _('Change my email') }}</button>
</li>
</ul>
</fieldset>
</form>
{% endif %}
</article>
</div>
</div>
Expand Down
14 changes: 4 additions & 10 deletions apps/users/templates/users/login.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
{% extends "users/base.html" %}
{% set title = _('Log In') %}
{% set classes = 'login' %}
{% set use_browserid = LANG|lower in config.BROWSERID_LOCALES.split(' ') %}

{% block content %}
<section id="content">
Expand All @@ -14,16 +13,11 @@
<h3>{{ _('You are already logged in.') }}</h3>
</article>
{% else %}
<article id="login" class="main" data-browserid-signin-html="{{ url('users.browserid_signin_html') }}?next={{ next_url }}">
{% if use_browserid %}
<article id="login" class="main">
{% include "users/browserid_signin.html" %}
{% else %}
<h1>{{ _('Log In') }}</h1>
{% include "users/login_form.html" %}
{% endif %}
</article>
{% endif %}
</article>
{% endif %}
</div>
</div>
</div>
</section>
{% endblock %}
5 changes: 1 addition & 4 deletions apps/users/templates/users/register.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@
{% from "layout/errorlist.html" import errorlist %}
{% set title = _('Register') %}
{% set classes = 'register' %}
{% set use_browserid = LANG|lower in config.BROWSERID_LOCALES.split(' ') %}

{% block content %}
<section id="content">
<div class="wrap">
<div id="content-main" class="full">
<article id="register" class="main" data-browserid-signin-html="{{ url('users.browserid_signin_html') }}">
<article id="register" class="main">
<h1>{{ _('Register') }}</h1>
<p>{% trans %}
You can access everything on the MDN website even without an account, but
Expand All @@ -34,9 +33,7 @@ <h1>{{ _('Register') }}</h1>
{% endblock %}

{% block js %}
{% if use_browserid %}
<script type="text/javascript">
$('article.main').load($('article.main').attr('data-browserid-signin-html'), bindBrowserIDSignin);
</script>
{% endif %}
{% endblock %}
45 changes: 11 additions & 34 deletions apps/users/tests/test_templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
from sumo.tests import post
from users.models import RegistrationProfile
from users.tests import TestCaseBase
from users.views import _clean_next_url
from users.views import _clean_next_url, SESSION_VERIFIED_EMAIL


class LoginTests(TestCaseBase):
Expand Down Expand Up @@ -92,47 +92,24 @@ def test_login_next_parameter(self):
eq_(302, response.status_code)
eq_('http://testserver' + next, response['location'])

def test_login_next_parameter_all_forms(self):
def test_login_next_parameter_in_forms(self):
'''Test with a valid ?next=url parameter.'''
next = '/demos/submit'

# Verify that next parameter is set in form hidden field.
response = self.client.get(urlparams(reverse('users.login'),
next=next))
eq_(200, response.status_code)
doc = pq(response.content)
eq_(next, doc('input[name="next"]')[0].attrib['value'])

# Verify that next parameter is set in form hidden field.
response = self.client.get(urlparams(
reverse('users.browserid_header_signin_html'), next=next))
# header and footer forms
next = '/en-US/demos/submit'
response = self.client.get(urlparams(reverse('demos_submit')))
eq_(200, response.status_code)
doc = pq(response.content)
eq_(next, doc('input[name="next"]')[0].attrib['value'])
eq_(next, doc('#masthead input[name="next"]')[0].attrib['value'])
eq_(next, doc('#site-info input[name="next"]')[0].attrib['value'])

# Verify that next parameter is set in form hidden field.
response = self.client.get(urlparams(
reverse('users.browserid_signin_html'), next=next))
# user login page - someone logged-out clicks edit
next = '/en-US/docs/Testing$edit'
response = self.client.get(urlparams(reverse('users.login'),
next=next))
eq_(200, response.status_code)
doc = pq(response.content)
eq_(next, doc('input[name="next"]')[0].attrib['value'])

@attr('latin1char_next')
def test_latin1_characters_in_next_parameter(self):
'''Some pages have bad chars in the url, which can kill clean_next_url.
Test with a bad character in HTTP_REFERER.'''
constance.config.BROWSERID_LOCALES = 'en-us, fr'
next = '/fr/Firefox_pour_les_d\xc3\xa9veloppeurs'
response = self.client.get(urlparams(
reverse('users.browserid_header_signin_html', locale='fr')),
**{'HTTP_REFERER': next,
'ACCEPT_LANGUAGE': 'fr',
})
eq_(200, response.status_code)
doc = pq(response.content)
eq_(unicode(next.decode('latin1', 'ignore')),
doc('input[name="next"]')[0].attrib['value'])

@mock.patch_object(Site.objects, 'get_current')
def test_clean_url(self, get_current):
'''Verify that protocol and domain get removed.'''
Expand Down
4 changes: 0 additions & 4 deletions apps/users/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@
name='users.browserid_register'),
url(r'^/browserid_change_email$', views.browserid_change_email,
name='users.browserid_change_email'),
url(r'^/browserid_header_signin_html$', views.browserid_header_signin_html,
name='users.browserid_header_signin_html'),
url(r'^/browserid_signin_html$', views.browserid_signin_html,
name='users.browserid_signin_html'),
url(r'^/login$', views.login, name='users.login'),
url(r'^/logout$', views.logout, name='users.logout'),
url(r'^/register$', views.register, name='users.register'),
Expand Down
19 changes: 0 additions & 19 deletions apps/users/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,25 +83,6 @@ def set_browserid_explained(response):
return response


def browserid_header_signin_html(request):
next_url = _clean_next_url(request) or reverse('home')
browserid_locales = constance.config.BROWSERID_LOCALES
if request.locale.lower() not in browserid_locales.lower():
raise Http404
return jingo.render(request, 'users/browserid_header_signin.html',
{'next_url': next_url})


def browserid_signin_html(request):
next_url = _clean_next_url(request) or reverse('home')
browserid_locales = constance.config.BROWSERID_LOCALES
if request.locale.lower() not in browserid_locales.lower():
raise Http404
form = handle_login(request)
return jingo.render(request, 'users/browserid_signin.html',
{'form': form, 'next_url': next_url})


@ssl_required
@login_required
@require_POST
Expand Down
40 changes: 1 addition & 39 deletions media/js/mdn/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,47 +136,9 @@ jQuery.extend({
});
}



(function() {

var $signedOutList = $('ul.signed-out');

if($signedOutList.length) {
// Hide the signed-out block, add and wire up a BrowserID sign in button,
// then show the signed-out block again
$signedOutList.hide();

// Retrieve the login url
var url = $signedOutList.attr('data-browserid-header-signin-html');

// Split the URL, find the next value
var urlSplit = url.split("?"),
rootUrl = urlSplit.shift(),
qstring = urlSplit.join("?");

$.get(rootUrl, {
next: $.parseQuerystring(qstring).next || $.parseQuerystring().next || window.location.pathname
}, function(content) {
$signedOutList.html(content).each(function() {
$('.toggle', $(this)).click(function() {
$(this).siblings(".sub-menu").slideToggle(150).removeAttr("aria-hidden");
return false;
});
});
// Binding the signout link!
bindBrowserIDSignin();
});

$signedOutList.show();
}

})();


// Wire up the statically-drawn browserid-signin element on the change
// email page
$('#change-email').ready(function(){
$('#change-email', '.signed-out').ready(function(){
bindBrowserIDSignin();
});

Expand Down
9 changes: 1 addition & 8 deletions settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ def lazy_language_deki_map():
'sumo.context_processors.for_data',

'devmo.context_processors.i18n',
# 'devmo.context_processors.phpbb_logged_in',
'devmo.context_processors.next_url',

'jingo_minify.helpers.build_ids',

Expand Down Expand Up @@ -954,13 +954,6 @@ def read_only_mode(env):
"Dev derby tags for previous challenges (space-separated tags)"
),

BROWSERID_LOCALES = (
' '.join([
'en-us',
]),
'Space-separated locales for which BrowserID sign-in should be enabled'
),

DEKIWIKI_POST_RETRIES = (
6,
'Number of time to retry dekiwiki/MindTouch post before giving up.'
Expand Down
24 changes: 19 additions & 5 deletions templates/includes/login.html
Original file line number Diff line number Diff line change
@@ -1,13 +1,27 @@
{% set use_browserid = LANG|lower in config.BROWSERID_LOCALES.split(' ') %}
{% if user.is_authenticated() %}
<ul class="user-state">
{% set username = request.user.username %}
<li><a href="{{ url('devmo.views.profile_view', username=username) }}">{{ _('{username}') | f(username=username) }}</a></li>
<li><a href="{{ url('users.logout') }}">{{ _('Sign out') }}</a></li>
<li><a href="{{ url('users.logout') }}?next={{ next_url }}">{{ _('Sign out') }}</a></li>
</ul>
{% else %}
<ul class="user-state signed-out" data-browserid-header-signin-html="{{ url('users.browserid_header_signin_html') }}?next={{ next_url }}">
<li><a href="{{ url('users.register') }}">{{ _('Join MDN') }}</a></li>
<li><a href="{{ url('users.login') }}">{{ _('Log in') }}</a></li>
<ul class="user-state signed-out">
<li class="user-signin menu">
<form class="browserid" action="{{url('users.browserid_verify') }}" method="POST">
<input id="next" name="next" type="hidden" value="{{ next_url }}"/>
{{ browserid_form }}
{% set toggle = 'toggle' %}
{% if request.COOKIES.get('browserid_explained', 0) == '1' %}
{% set toggle = '' %}
{% endif %}
<a href="#" target="_blank" class="browserid-signin {{ toggle }}" aria-haspopup="true" title="{{_('Sign in with BrowserID')}}">{{ _('Sign in') }}</a>
{% if toggle %}
<div class="browserid-info sub-menu" aria-hidden="true">
{% include "users/browserid_explanation.html" %}
<p><a href="#" target="_blank" class="browserid-signin" title="{{_('Sign in with BrowserID')}}">{{ _('Sign in') }}</a></p>
</div>
{% endif %}
</form>
</li>
</ul>
{% endif %}

0 comments on commit c29c8f7

Please sign in to comment.