Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions kitsune/questions/templates/questions/mobile/new_question.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{% extends "mobile/base.html" %}
{% from "layout/errorlist.html" import errorlist %}
{% from "questions/includes/aaq_macros.html" import select_product, selected_product, select_category, selected_category, show_results %}
{% from "questions/includes/aaq_macros.html" import select_product, selected_product, select_category, selected_category %}
{% from "questions/includes/aaq_macros.html" import current_articles_and_message, aaq_search_form with context %}
{% set title = _('Ask A Question') %}
{% set headline = title %}
Expand Down Expand Up @@ -47,12 +47,16 @@ <h2>{{ _('Products') }}</h2>
<a class="btn" href="{{ url('questions.aaq_step2', product_key=current_product.key) }}">{{ _('Try another topic') }}</a>

{% if not deadend %}
{% set form_url = url('questions.aaq_step5', product_key=current_product.key, category_key=current_category.key) %}
<form action="{% if settings.SESSION_COOKIE_SECURE %}https://{{ host }}{% endif %}{{ form_url }}" method="get">
<input type="hidden" name="search" value="" />
<input type="hidden" name="step" value="{% if user.is_authenticated() %}aaq-question{% else %}aaq-register{% endif %}" />
<button type="submit" class="btn">{{ _('Post a question') }}</button>
</form>
{% set next_step_url = url('questions.aaq_step5', product_key=current_product.key, category_key=current_category.key) %}
{% if waffle.flag('browserid') %}
<a href="#" class="btn browserid-login" data-next="{{ next_step_url|urlparams(search=request.GET.search, step='aaq-question') }}">{{ _('Post a question') }}</a>
{% else %}
<form action="{% if settings.SESSION_COOKIE_SECURE %}https://{{ host }}{% endif %}{{ next_step_url }}" method="get">
<input type="hidden" name="search" value="{{ request.GET.search }}" />
<input type="hidden" name="step" value="{% if user.is_authenticated() %}aaq-question{% else %}aaq-register{% endif %}" />
<button type="submit" class="btn">{{ _('Post a question') }}</button>
</form>
{% endif %}
{% endif %}
</div>
{% endif %}
Expand Down
15 changes: 10 additions & 5 deletions kitsune/questions/templates/questions/new_question.html
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,16 @@ <h2>{{ _('Do any of these articles answer your question?') }}</h2>
<h2 class="no-results">{{ _('This question has not been asked before.') }}</h2>
{% set button_text = _('Provide more details') %}
{% endif %}
<form action="{{ url('questions.aaq_step5', product_key=current_product.key, category_key=current_category.key) }}" method="get">
<input type="hidden" name="search" value="{{ request.GET.search }}" />
<input type="hidden" name="step" value="{% if user.is_authenticated() %}aaq-question{% else %}aaq-register{% endif %}" />
<button type="submit" data-type="submit" class="btn btn-submit big">{{ button_text }}</button>
</form>

{% if waffle.flag('browserid') %}
<a href="#" class="btn btn-submit big browserid-login" data-next="{{ url('questions.aaq_step5', product_key=current_product.key, category_key=current_category.key)|urlparams(search=request.GET.search, step='aaq-question') }}">{{ button_text }}</a>
{% else %}
<form action="{{ url('questions.aaq_step5', product_key=current_product.key, category_key=current_category.key) }}" method="get">
<input type="hidden" name="search" value="{{ request.GET.search }}" />
<input type="hidden" name="step" value="{% if user.is_authenticated() %}aaq-question{% else %}aaq-register{% endif %}" />
<button type="submit" data-type="submit" class="btn btn-submit big">{{ button_text }}</button>
</form>
{% endif %}
{% endif %}

{% endblock %}
Expand Down
151 changes: 46 additions & 105 deletions kitsune/questions/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from django.contrib import auth
from django.contrib import messages
from django.contrib.auth.forms import AuthenticationForm
from django.contrib.auth.models import User
from django.contrib.contenttypes.models import ContentType
from django.contrib.sites.models import Site
from django.core.cache import cache
Expand All @@ -24,8 +23,6 @@

import jingo
import waffle
from django_browserid import get_audience, verify
from django_browserid.forms import BrowserIDForm
from mobility.decorators import mobile_template
from ratelimit.decorators import ratelimit
from ratelimit.helpers import is_ratelimited
Expand Down Expand Up @@ -65,8 +62,8 @@
from kitsune.tags.utils import add_existing_tag
from kitsune.upload.models import ImageAttachment
from kitsune.upload.views import upload_imageattachment
from kitsune.users.forms import RegisterForm, BrowserIDSignupForm
from kitsune.users.models import Setting, Profile
from kitsune.users.forms import RegisterForm
from kitsune.users.models import Setting
from kitsune.users.utils import handle_login, handle_register
from kitsune.wiki.facets import documents_for, topics_for
from kitsune.wiki.models import Document, DocumentMappingType
Expand Down Expand Up @@ -445,19 +442,13 @@ def aaq(request, product_key=None, category_key=None, showform=False,
if not request.user.is_authenticated():
# User is on the login or register Step
statsd.incr('questions.aaq.login-or-register')
if waffle.flag_is_active(request, 'browserid'):
register_form = BrowserIDSignupForm()
return render(request, login_t, {
'product': product, 'category': category,
'title': search, 'register_form': register_form})
else:
login_form = AuthenticationForm()
register_form = RegisterForm()
return render(request, login_t, {
'product': product, 'category': category,
'title': search,
'register_form': register_form,
'login_form': login_form})
login_form = AuthenticationForm()
register_form = RegisterForm()
return render(request, login_t, {
'product': product, 'category': category,
'title': search,
'register_form': register_form,
'login_form': login_form})
form = NewQuestionForm(product=product,
category=category,
initial={'title': search})
Expand All @@ -484,97 +475,47 @@ def aaq(request, product_key=None, category_key=None, showform=False,

# Handle the form post.
if not request.user.is_authenticated():
if waffle.flag_is_active(request, 'browserid'):
register_form = BrowserIDSignupForm()
next_url = urlparams(request.get_full_path(), step='aaq-question')

if request.POST.get('assertion'):
# Attempted login
login_form = BrowserIDForm(data=request.POST)

if login_form.is_valid():
result = verify(login_form.cleaned_data['assertion'],
get_audience(request))
if result:
# Verified so log in
email = result['email']
user = User.objects.filter(email=email)

if len(user) == 0:
request.session['browserid-email'] = email
else:
user = user[0]
user.backend = ('django_browserid.auth'
'.BrowserIDBackend')
auth.login(request, user)
return redirect(next_url)
else:
# Attempted registration
email = request.session.get('browserid-email', None)

if email:
register_form = BrowserIDSignupForm(request.REQUEST)

if register_form.is_valid():
user = User.objects.create_user(
register_form.cleaned_data['username'], email)
user.save()

# Create a new profile for the user
Profile.objects.create(user=user,
locale=request.LANGUAGE_CODE)

# Log the user in
user.backend = 'django_browserid.auth.BrowserIDBackend'
auth.login(request, user)
return redirect(next_url)
if request.POST.get('login'):
login_form = handle_login(request, only_active=False)
statsd.incr('questions.user.login')
register_form = RegisterForm()

if login_form.is_valid():
statsd.incr('questions.user.login.success')
else:
statsd.incr('questions.user.login.fail')

elif request.POST.get('register'):
login_form = AuthenticationForm()
register_form = handle_register(
request=request,
text_template='questions/email/confirm_question.ltxt',
html_template='questions/email/confirm_question.html',
subject=_('Please confirm your Firefox Help question'),
email_data=request.GET.get('search'))

if register_form.is_valid(): # Now try to log in.
user = auth.authenticate(username=request.POST.get('username'),
password=request.POST.get('password'))
auth.login(request, user)
statsd.incr('questions.user.register')
else:
# L10n: This shouldn't happen unless people tamper with POST data.
message = _lazy('Request type not recognized.')
return render(request, 'handlers/400.html', {
'message': message}, status=400)
if request.user.is_authenticated():
# Redirect to GET the current URL replacing the step parameter.
# This is also required for the csrf middleware to set the auth'd
# tokens appropriately.
url = urlparams(request.get_full_path(), step='aaq-question')
return HttpResponseRedirect(url)
else:
return render(request, login_t, {
'product': product, 'category': category,
'title': request.POST.get('title'),
'register_form': register_form})
else:
if request.POST.get('login'):
login_form = handle_login(request, only_active=False)
statsd.incr('questions.user.login')
register_form = RegisterForm()

if login_form.is_valid():
statsd.incr('questions.user.login.success')
else:
statsd.incr('questions.user.login.fail')

elif request.POST.get('register'):
login_form = AuthenticationForm()
register_form = handle_register(
request=request,
text_template='questions/email/confirm_question.ltxt',
html_template='questions/email/confirm_question.html',
subject=_('Please confirm your Firefox Help question'),
email_data=request.GET.get('search'))

if register_form.is_valid(): # Now try to log in.
user = auth.authenticate(username=request.POST.get('username'),
password=request.POST.get('password'))
auth.login(request, user)
statsd.incr('questions.user.register')
else:
# L10n: This shouldn't happen unless people tamper with POST data.
message = _lazy('Request type not recognized.')
return render(request, 'handlers/400.html', {
'message': message}, status=400)
if request.user.is_authenticated():
# Redirect to GET the current URL replacing the step parameter.
# This is also required for the csrf middleware to set the auth'd
# tokens appropriately.
url = urlparams(request.get_full_path(), step='aaq-question')
return HttpResponseRedirect(url)
else:
return render(request, login_t, {
'product': product, 'category': category,
'title': request.POST.get('title'),
'register_form': register_form,
'login_form': login_form})
'register_form': register_form,
'login_form': login_form})

form = NewQuestionForm(product=product, category=category,
data=request.POST)
Expand Down