diff options
-rw-r--r-- | askbot/deps/django_authopenid/urls.py | 7 | ||||
-rw-r--r-- | askbot/deps/django_authopenid/views.py | 92 | ||||
-rw-r--r-- | askbot/skins/default/templates/authopenid/widget_signin.html | 231 | ||||
-rw-r--r-- | askbot/skins/default/templates/widget_base.html | 3 | ||||
-rw-r--r-- | askbot/tests/__init__.py.orig | 19 | ||||
-rw-r--r-- | askbot/tests/widget_tests.py | 9 | ||||
-rw-r--r-- | askbot/views/widgets.py | 17 |
7 files changed, 323 insertions, 55 deletions
diff --git a/askbot/deps/django_authopenid/urls.py b/askbot/deps/django_authopenid/urls.py index f51939ab..249e709e 100644 --- a/askbot/deps/django_authopenid/urls.py +++ b/askbot/deps/django_authopenid/urls.py @@ -7,13 +7,16 @@ urlpatterns = patterns('askbot.deps.django_authopenid.views', url(r'^yadis.xrdf$', 'xrdf', name='yadis_xrdf'), # manage account registration url(r'^%s$' % _('signin/'), 'signin', name='user_signin'), + url(r'^%s$' % _('widget/signin/'), 'signin', + {'template_name': 'authopenid/widget_signin.html'}, + name='widget_signin'), url(r'^%s$' % _('signout/'), 'signout', name='user_signout'), #this view is "complete-openid" signin - url(r'^%s%s$' % (_('signin/'), _('complete/')), 'complete_signin', + url(r'^%s%s$' % (_('signin/'), _('complete/')), 'complete_signin', name='user_complete_signin'), url( r'^%s%s$' % (_('signin/'), _('complete-oauth/')), - 'complete_oauth_signin', + 'complete_oauth_signin', name='user_complete_oauth_signin' ), url(r'^%s$' % _('register/'), 'register', name='user_register'), diff --git a/askbot/deps/django_authopenid/views.py b/askbot/deps/django_authopenid/views.py index a3ecbbab..468e494d 100644 --- a/askbot/deps/django_authopenid/views.py +++ b/askbot/deps/django_authopenid/views.py @@ -1,13 +1,13 @@ # -*- coding: utf-8 -*- # Copyright (c) 2007, 2008, BenoĆ®t Chesneau # Copyright (c) 2007 Simon Willison, original work on django-openid -# +# # All rights reserved. -# +# # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are # met: -# +# # * Redistributions of source code must retain the above copyright # * notice, this list of conditions and the following disclaimer. # * Redistributions in binary form must reproduce the above copyright @@ -17,7 +17,7 @@ # * of its contributors may be used to endorse or promote products # * derived from this software without specific prior written # * permission. -# +# # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS # IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, # THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR @@ -132,7 +132,7 @@ def ask_openid( ): """ basic function to ask openid and return response """ on_failure = on_failure or signin_failure - + trust_root = getattr( settings, 'OPENID_TRUST_ROOT', get_url_host(request) + '/' ) @@ -162,9 +162,9 @@ def complete(request, on_success=None, on_failure=None, return_to=None): """ complete openid signin """ assert(on_success is not None) assert(on_failure is not None) - + logging.debug('in askbot.deps.django_authopenid.complete') - + consumer = Consumer(request.session, util.DjangoOpenIDStore()) # make sure params are encoded in utf8 params = dict((k,smart_unicode(v)) for k, v in request.GET.items()) @@ -174,7 +174,7 @@ def complete(request, on_success=None, on_failure=None, return_to=None): logging.debug(u'returned openid parameters were: %s' % unicode(params)) except Exception, e: logging.critical(u'fix logging statement above ' + unicode(e)) - + if openid_response.status == SUCCESS: logging.debug('openid response status is SUCCESS') return on_success( @@ -267,13 +267,13 @@ def complete_oauth_signin(request): #@not_authenticated @csrf.csrf_protect -def signin(request): +def signin(request, template_name='authopenid/signin.html'): """ - signin page. It manages the legacy authentification (user/password) + signin page. It manages the legacy authentification (user/password) and openid authentification - + url: /signin/ - + template : authopenid/signin.htm """ logging.debug('in signin view') @@ -367,11 +367,11 @@ def signin(request): sreg_req = sreg.SRegRequest(optional=['nickname', 'email']) redirect_to = "%s%s?%s" % ( get_url_host(request), - reverse('user_complete_signin'), + reverse('user_complete_signin'), urllib.urlencode({'next':next_url}) ) return ask_openid( - request, + request, login_form.cleaned_data['openid_url'], redirect_to, on_failure=signin_failure, @@ -442,7 +442,7 @@ def signin(request): user = authenticate( method = 'wordpress_site', wordpress_url = wp.url, - wp_user_id = wp_user.user_id + wp_user_id = wp_user.user_id ) return finalize_generic_signin( request = request, @@ -471,8 +471,9 @@ def signin(request): return show_signin_view( request, login_form = login_form, - view_subtype = view_subtype - ) + view_subtype = view_subtype, + template_name=template_name + ) @csrf.csrf_protect def show_signin_view( @@ -481,7 +482,8 @@ def show_signin_view( account_recovery_form = None, account_recovery_message = None, sticky = False, - view_subtype = 'default' + view_subtype = 'default', + template_name='authopenid/signin.html' ): """url-less utility function that populates context of template 'authopenid/signin.html' @@ -489,12 +491,12 @@ def show_signin_view( """ allowed_subtypes = ( - 'default', 'add_openid', + 'default', 'add_openid', 'email_sent', 'change_openid', 'bad_key' ) - assert(view_subtype in allowed_subtypes) + assert(view_subtype in allowed_subtypes) if sticky: next_url = reverse('user_signin') @@ -608,7 +610,7 @@ def show_signin_view( data['existing_login_methods'] = existing_login_methods active_provider_names = [ item.provider_name for item in existing_login_methods - ] + ] util.set_login_provider_tooltips( major_login_providers, @@ -622,7 +624,7 @@ def show_signin_view( data['major_login_providers'] = major_login_providers.values() data['minor_login_providers'] = minor_login_providers.values() - return render_into_skin('authopenid/signin.html', data, request) + return render_into_skin(template_name, data, request) @login_required def delete_login_method(request): @@ -654,8 +656,8 @@ def complete_signin(request): """ in case of complete signin with openid """ logging.debug('')#blank log just for the trace return complete( - request, - on_success = signin_success, + request, + on_success = signin_success, on_failure = signin_failure, return_to = get_url_host(request) + reverse('user_complete_signin') ) @@ -697,7 +699,7 @@ def signin_success(request, identity_url, openid_response): ) def finalize_generic_signin( - request = None, + request = None, user = None, login_provider_name = None, user_identifier = None, @@ -767,10 +769,10 @@ def register(request, login_provider_name=None, user_identifier=None): and login_provider_name and user_identifier arguments must not be None this function may need to be refactored to simplify the usage pattern - + template : authopenid/complete.html """ - + logging.debug('') next_url = get_next_url(request) @@ -824,7 +826,7 @@ def register(request, login_provider_name=None, user_identifier=None): user = User.objects.create_user(username, email) user_registered.send(None, user = user) - + logging.debug('creating new openid user association for %s') UserAssociation( @@ -836,7 +838,7 @@ def register(request, login_provider_name=None, user_identifier=None): del request.session['user_identifier'] del request.session['login_provider_name'] - + logging.debug('logging the user in') user = authenticate(method = 'force', user_id = user.id) @@ -854,7 +856,7 @@ def register(request, login_provider_name=None, user_identifier=None): #check if we need to post a question that was added anonymously #this needs to be a function call becase this is also done #if user just logged in and did not need to create the new account - + if user != None: if askbot_settings.EMAIL_VALIDATION == True: logging.debug('sending email validation') @@ -868,7 +870,7 @@ def register(request, login_provider_name=None, user_identifier=None): else: logging.debug('have really strange error') raise Exception('openid login failed')#should not ever get here - + providers = { 'yahoo':'<font color="purple">Yahoo!</font>', 'flickr':'<font color="#0063dc">flick</font><font color="#ff0084">r</font>™', @@ -881,7 +883,7 @@ def register(request, login_provider_name=None, user_identifier=None): logging.error('openid provider named "%s" has no pretty customized logo' % login_provider_name) else: provider_logo = providers[login_provider_name] - + logging.debug('printing authopenid/complete.html output') data = { 'openid_register_form': register_form, @@ -909,7 +911,7 @@ def signup_with_password(request): """Create a password-protected account template: authopenid/signup_with_password.html """ - + logging.debug(get_request_info(request)) next = get_next_url(request) login_form = forms.LoginForm(initial = {'next': next}) @@ -925,7 +927,7 @@ def signup_with_password(request): if request.method == 'POST': form = RegisterForm(request.POST) email_feeds_form = askbot_forms.SimpleEmailSubscribeForm(request.POST) - + #validation outside if to remember form values logging.debug('validating classic register form') form1_is_valid = form.is_valid() @@ -945,7 +947,7 @@ def signup_with_password(request): password = form.cleaned_data['password1'] email = form.cleaned_data['email'] provider_name = form.cleaned_data['login_provider'] - + new_user = User.objects.create_user(username, email, password) user_registered.send(None, user = new_user) @@ -964,19 +966,19 @@ def signup_with_password(request): logging.debug('new user logged in') email_feeds_form.save(user) logging.debug('email feeds form saved') - + # send email #subject = _("Welcome email subject line") #message_template = get_emplate( # 'authopenid/confirm_email.txt' #) - #message_context = Context({ + #message_context = Context({ # 'signup_url': askbot_settings.APP_URL + reverse('user_signin'), # 'username': username, # 'password': password, #}) #message = message_template.render(message_context) - #send_mail(subject, message, settings.DEFAULT_FROM_EMAIL, + #send_mail(subject, message, settings.DEFAULT_FROM_EMAIL, # [user.email]) #logging.debug('new password acct created, confirmation email sent!') return HttpResponseRedirect(next) @@ -999,7 +1001,7 @@ def signup_with_password(request): minor_login_providers = util.get_enabled_minor_login_providers() context_data = { - 'form': form, + 'form': form, 'page_class': 'openid-signin', 'email_feeds_form': email_feeds_form, 'major_login_providers': major_login_providers.values(), @@ -1043,7 +1045,7 @@ XRDF_TEMPLATE = """<?xml version='1.0' encoding='UTF-8'?> </Service> </XRD> </xrds:XRDS>""" - + def xrdf(request): url_host = get_url_host(request) return_to = "%s%s" % (url_host, reverse('user_complete_signin')) @@ -1094,7 +1096,7 @@ def _send_email_key(user): def send_new_email_key(user,nomessage=False): import random random.seed() - user.email_key = '%032x' % random.getrandbits(128) + user.email_key = '%032x' % random.getrandbits(128) user.save() _send_email_key(user) if nomessage==False: @@ -1110,14 +1112,14 @@ def send_email_key(request): email sending is called internally raises 404 if email validation is off - if current email is valid shows 'key_not_sent' view of + if current email is valid shows 'key_not_sent' view of authopenid/changeemail.html template """ if askbot_settings.EMAIL_VALIDATION == True: if request.user.email_isvalid: data = { - 'email': request.user.email, - 'action_type': 'key_not_sent', + 'email': request.user.email, + 'action_type': 'key_not_sent', 'change_link': reverse('user_changeemail') } return render_into_skin( @@ -1181,7 +1183,7 @@ def account_recover(request, key = None): ) else: return show_signin_view(request, view_subtype = 'bad_key') - + #internal server view used as return value by other views def validation_email_sent(request): diff --git a/askbot/skins/default/templates/authopenid/widget_signin.html b/askbot/skins/default/templates/authopenid/widget_signin.html new file mode 100644 index 00000000..c3dbcfde --- /dev/null +++ b/askbot/skins/default/templates/authopenid/widget_signin.html @@ -0,0 +1,231 @@ +{% extends "widget_base.html" %}
+{% import "authopenid/authopenid_macros.html" as login_macros %}
+{% from "macros.html" import timeago %}
+<!-- signin.html -->
+{% block title %}{% spaceless %}{% trans %}User login{% endtrans %}{% endspaceless %}{% endblock %}
+{% block forestyle %}
+ <link rel="stylesheet" type="text/css" media="screen" href="{{"/jquery-openid/openid.css"|media}}"/>
+{% endblock %}
+{% block forejs %}
+ {% include "meta/bottom_scripts.html" %}
+ {% include "meta/html_head_javascript.html" %}
+{% endblock %}
+{% block content %}
+{% if have_buttons or view_subtype == 'email_sent' %}
+ <h1 class="section-title">{{page_title}}</h1>
+{% endif %}
+ {% if answer %}
+ <div class="message">
+ {% trans title=answer.question.title|escape, summary=answer.summary|escape %}
+ Your answer to {{title}} {{summary}} will be posted once you log in
+ {% endtrans %}
+ </div>
+ {% endif %}
+ {% if question %}
+ <div class="message">
+ {% trans title=question.title|escape, summary=question.summary|escape %}Your question
+ {{title}} {{summary}} will be posted once you log in
+ {% endtrans %}
+ </div>
+ {% endif %}
+ <p id='login-intro'>
+ {% if view_subtype == 'default' and have_buttons %}
+ {% trans %}Choose your favorite service below to sign in using secure OpenID or similar technology. Your external service password always stays confidential and you don't have to rememeber or create another one.{% endtrans %}
+ {% elif view_subtype == 'add_openid' and have_buttons %}
+ {% if existing_login_methods %}
+ {% trans %}It's a good idea to make sure that your existing login methods still work, or add a new one. Please click any of the icons below to check/change or add new login methods.{% endtrans %}
+ {% else %}
+ {% trans %}Please add a more permanent login method by clicking one of the icons below, to avoid logging in via email each time.{% endtrans %}
+ {% endif %}
+ {% elif view_subtype == 'change_openid' and have_buttons %}
+ {% if existing_login_methods %}
+ {% trans %}Click on one of the icons below to add a new login method or re-validate an existing one.{% endtrans %}
+ {% else %}
+ {% trans %}You don't have a method to log in right now, please add one or more by clicking any of the icons below.{% endtrans %}
+ {% endif %}
+ {% elif view_subtype == 'email_sent' %}
+ {% trans %}Please check your email and visit the enclosed link to re-connect to your account{% endtrans %}
+ {% endif %}
+ </p>
+ {% if openid_error_message %}
+ <p class="warning">{{ openid_error_message }}</p>
+ {% endif %}
+ {% if view_subtype != 'email_sent' and view_subtype != 'bad_key' %}
+ <form id="signin-form" method="post" action="{% url widget_signin %}">{% csrf_token %}
+ {# in this branch - the real signin view we display the login icons
+ here we hide the local login button only if admin
+ wants to always show the password login form - then
+ the button is useless.
+ #}
+ {{ login_form.login_provider_name }}
+ {{ login_form.next }}
+ {{
+ login_macros.provider_buttons(
+ login_form = login_form,
+ major_login_providers = major_login_providers,
+ minor_login_providers = minor_login_providers,
+ hide_local_login = settings.SIGNIN_ALWAYS_SHOW_LOCAL_LOGIN,
+ settings = settings,
+ logged_in = user.is_authenticated(),
+ show_buttons = have_buttons
+ )
+ }}
+ {% if use_password_login == True %}
+ <fieldset
+ id="password-fs"
+ {% if user.is_anonymous() %}
+ {% if not login_form.username.errors and not login_form.password_login_failed %}
+ {% if not settings.SIGNIN_ALWAYS_SHOW_LOCAL_LOGIN %}
+ style="display:none;"
+ {%endif%}
+ {% endif %}
+ {% else %}
+ {% if not login_form.new_password.errors and not login_form.new_password_retyped.errors %}
+ {% if not settings.SIGNIN_ALWAYS_SHOW_LOCAL_LOGIN %}
+ style="display:none;"
+ {% endif%}
+ {% endif %}
+ {% endif %}
+ >
+ {{login_form.password_action}}
+ {% if user.is_anonymous() %}
+ {% if have_buttons %}
+ <h2 id="password-heading">
+ {% trans %}or enter your <span>user name and password</span>, then sign in{% endtrans %}
+ </h2>
+ {% else %}
+ <h1 class="section-title">
+ {% trans %}Please, sign in{% endtrans %}
+ </h1>
+ {% endif %}
+ {% if have_buttons %}
+ <p class="hint">{% trans %}(or select another login method above){% endtrans %}</p>
+ {% endif %}
+ {% if login_form.password_login_failed %}
+ <p class="error">{% trans %}Login failed, please try again{% endtrans %}</p>
+ {% endif %}
+ <table class="login">
+ <tr>
+ <td><label for="id_username">{% trans %}Login or email{% endtrans %}</label></td>
+ <td>{{login_form.username}}</td>
+ </tr>
+ <tr>
+ <td><label for="id_password">{% trans %}Password{% endtrans %}</label></td>
+ <td>{{login_form.password}}</td>
+ </tr>
+ </table>
+ <p id="local_login_buttons">
+ <input class="submit-b" name="login_with_password" type="submit" value="{% trans %}Sign in{% endtrans %}" />
+ {% if settings.USE_LDAP_FOR_PASSWORD_LOGIN == False %}
+ <a class="create-password-account" style="vertical-align:middle" href="{% url user_signup_with_password %}?login_provider=local">{% trans %}Create a password-protected account{% endtrans %}</a>
+ {% endif %}
+ </p>
+ {% elif settings.USE_LDAP_FOR_PASSWORD_LOGIN == False %}
+ <h2 id="password-heading">
+ {% trans %}To change your password - please enter the new one twice, then submit{% endtrans %}
+ </h2>
+ <table class="login">
+ <tr>
+ <td><label for="id_new_password">{% trans %}New password{% endtrans %}</label></td>
+ <td>
+ {{login_form.new_password}}
+ </td>
+ <td>
+ <span class="error">{{login_form.new_password.errors[0]}}</span>
+ </td>
+ </tr>
+ <tr>
+ <td><label for="id_new_password_retyped">{% trans %}Please, retype{% endtrans %}</label></td>
+ <td>
+ {{login_form.new_password_retyped}}
+ </td>
+ <td>
+ <span class="error">{{login_form.new_password_retyped.errors[0]}}</span>
+ </td>
+ </tr>
+ </table>
+ <p id="local_login_buttons">
+ <input class="submit-b" name="change_password" type="submit" value="{% trans %}Change password{% endtrans %}" />
+ </p>
+ {% endif %}
+ </fieldset>
+ {% endif %}
+ </form>
+ {% if user.is_authenticated() and existing_login_methods and settings.ALLOW_ADD_REMOVE_LOGIN_METHODS %}
+ <div
+ id='existing-login-methods'
+ {% if login_form.password_change_failed %}
+ style="display:none";
+ {% endif %}
+ >
+ <h2 id='ab-show-login-methods'>
+ {% trans %}Here are your current login methods{% endtrans %}
+ </h2>
+ <table id='ab-existing-login-methods'>
+ <tr>
+ <th>{% trans %}provider{% endtrans %}</th>
+ <th>{% trans %}last used{% endtrans %}</th>
+ <th>{% trans %}delete, if you like{% endtrans %}</th>
+ </tr>
+ {% for login_method in existing_login_methods %}
+ <tr class="ab-provider-row">
+ <td class="ab-provider-name">
+ {{login_method.provider_name}}
+ </td>
+ <td>
+ {% if login_method.last_used_timestamp %}
+ {{ timeago(login_method.last_used_timestamp) }}
+ {% endif %}
+ </td>
+ <td>
+ {% if login_method.is_deletable %}
+ <button>{% trans %}delete{% endtrans %}</button>
+ {% else %}
+ {% trans %}cannot be deleted{% endtrans %}
+ {% endif %}
+ </td>
+ </tr>
+ {% endfor %}
+ </table>
+ </div>
+ {% endif %}
+ {% endif %}
+ {% if view_subtype != 'email_sent' or view_subtype == 'bad_key' %}
+ {% if user.is_anonymous() and settings.ALLOW_ACCOUNT_RECOVERY_BY_EMAIL %}
+ <form id="account-recovery-form" action="{% url user_account_recover %}" method="post">{% csrf_token %}
+ {% if view_subtype != 'bad_key' %}
+ <h2 id='account-recovery-heading'>{% trans %}Still have trouble signing in?{% endtrans %}</h2>
+ {% endif %}
+ <p class="hint">
+ <span class="text">
+ {% if view_subtype == 'bad_key' %}
+ {% trans %}Please, enter your email address below and obtain a new key{% endtrans %}
+ {% else %}
+ {% trans %}Please, enter your email address below to recover your account{% endtrans %}
+ {% endif %}
+ </span>
+ <span style="display:none" class="link"> - <a href="#">{% trans %}recover your account via email{% endtrans %}</a></span>
+ </p>
+ <fieldset id='email-input-fs'>
+ {% if account_recovery_form.email.errors %}
+ <p class="error">{{account_recovery_form.email.errors[0]}}</p>
+ {% endif %}
+ {{ account_recovery_form.email }}
+ <input
+ class="submit-b"
+ type="submit"
+ {% if view_subtype == 'bad_key' %}
+ value="{% trans %}Send a new recovery key{% endtrans %}"
+ {% else %}
+ value="{% trans %}Recover your account via email{% endtrans %}"
+ {% endif %}
+ />
+ </fieldset>
+ </form>
+ {% endif %}
+ {% endif %}
+{% endblock %}
+{% block endjs %}
+{% include "authopenid/providers_javascript.html" %}
+{% endblock %}
+<!-- end signin.html -->
diff --git a/askbot/skins/default/templates/widget_base.html b/askbot/skins/default/templates/widget_base.html index 8156095d..fd5e739e 100644 --- a/askbot/skins/default/templates/widget_base.html +++ b/askbot/skins/default/templates/widget_base.html @@ -3,6 +3,7 @@ <html xmlns="http://www.w3.org/1999/xhtml"> {% spaceless %} <head> + {% include "meta/bottom_scripts.html" %} {% block before_css %}{% endblock %} {% block forestyle %}{% endblock %} {% block forejs %}{% endblock %} @@ -11,6 +12,8 @@ <body class="lang-{{settings.LANGUAGE_CODE}}"> {% block body%} {% endblock %} + {% block content%} + {% endblock %} {% block endjs %} {% endblock %} </body> diff --git a/askbot/tests/__init__.py.orig b/askbot/tests/__init__.py.orig new file mode 100644 index 00000000..905c90df --- /dev/null +++ b/askbot/tests/__init__.py.orig @@ -0,0 +1,19 @@ +from askbot.tests.cache_tests import * +from askbot.tests.email_alert_tests import * +from askbot.tests.on_screen_notification_tests import * +from askbot.tests.page_load_tests import * +from askbot.tests.permission_assertion_tests import * +from askbot.tests.db_api_tests import * +from askbot.tests.skin_tests import * +from askbot.tests.badge_tests import * +from askbot.tests.management_command_tests import * +from askbot.tests.search_state_tests import * +from askbot.tests.form_tests import * +from askbot.tests.follow_tests import * +from askbot.tests.templatefilter_tests import * +from askbot.tests.markup_test import * +from askbot.tests.post_model_tests import * +from askbot.tests.thread_model_tests import * +from askbot.tests.reply_by_email_tests import * +from askbot.tests.category_tree_tests import CategoryTreeTests +from askbot.tests.user_model_tests import UserModelTests diff --git a/askbot/tests/widget_tests.py b/askbot/tests/widget_tests.py index e33f88b9..40c63e0e 100644 --- a/askbot/tests/widget_tests.py +++ b/askbot/tests/widget_tests.py @@ -50,3 +50,12 @@ class WidgetViewsTests(AskbotTestCase): self.assertFalse('widget_question' in self.client.session) self.assertEquals(response.status_code, 302) #verify posting question + +class WidgetLoginViewTest(AskbotTestCase): + + def test_correct_template_loading(self): + client = Client() + response = client.get(reverse('widget_signin')) + template_name = 'authopenid/widget_signin.html' + templates = [template.name for template in response.templates] + self.assertTrue(template_name in templates) diff --git a/askbot/views/widgets.py b/askbot/views/widgets.py index ea093916..77eb7eb5 100644 --- a/askbot/views/widgets.py +++ b/askbot/views/widgets.py @@ -1,10 +1,11 @@ from datetime import datetime -from django.views.decorators import csrf -from django.shortcuts import redirect +from django.core import exceptions from django.utils import simplejson +from django.shortcuts import redirect +from django.views.decorators import csrf from django.contrib.auth.models import User -from django.core import exceptions +from django.core.urlresolvers import reverse from django.contrib.auth.decorators import login_required @@ -41,10 +42,10 @@ def ask_widget(request): return redirect('ask_by_widget_complete') else: request.session['widget_question'] = data_dict - #return redirect('widgets_login') - return redirect('user_signin') + next_url = '%s?next=%s' % (reverse('widget_signin'), reverse('ask_by_widget')) + return redirect(next_url) else: - if 'widget_question' in request.session or \ + if 'widget_question' in request.session and \ request.GET.get('action', 'post-after-login'): if request.user.is_authenticated(): data_dict = request.session['widget_question'] @@ -54,8 +55,8 @@ def ask_widget(request): return redirect('ask_by_widget_complete') else: #FIXME: this redirect is temporal need to create the correct view - #return redirect('widgets_login') - return redirect('user_signin') + next_url = '%s?next=%s' % (reverse('widget_signin'), reverse('ask_by_widget')) + return redirect(next_url) form = forms.AskWidgetForm() data = {'form': form} |