Skip to content

Commit

Permalink
Simple example of authentication using popups.
Browse files Browse the repository at this point in the history
  • Loading branch information
krvss committed Dec 30, 2012
1 parent a3764ef commit 40b0615
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 1 deletion.
4 changes: 4 additions & 0 deletions example/app/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,7 @@ def form2(request):
backend = request.session[name]['backend']
return redirect('socialauth_complete', backend=backend)
return render_to_response('form2.html', {}, RequestContext(request))


def close_login_popup(request):
return render_to_response('close_popup.html', {}, RequestContext(request))
23 changes: 23 additions & 0 deletions example/example/templates/close_popup.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{% extends "base.html" %}

{% block heading %}Login popup{% endblock %}

{% block script %}
<script type="text/javascript">

function closeAndUpdate()
{
if (window.opener) {
window.opener.location.reload(true);
window.close();
}
}

closeAndUpdate();

// To handle errors, this template should be integrated into your authentication error message page
// Note that you can call any window.opener function like window.opener.func

</script>

{% endblock %}
26 changes: 26 additions & 0 deletions example/example/templates/home.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,22 @@
{% block script %}
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script>
<script src="https://browserid.org/include.js" type="text/javascript"></script>

<script type="text/javascript">
function openPopup(url) {
var w = 700;
var h = 500;
var left = 100;
var top = 100;

var settings = 'height=' + h + ',width=' + w + ',left=' + left + ',top=' + top + ',resizable=yes,scrollbars=yes,toolbar=no,menubar=no,location=yes,directories=no,status=yes';
url += "?next={% url 'login_popup_close' %}";

window.open(url, name, settings)
}

</script>

{% endblock %}

{% block heading %}Login using any of the following methods{% endblock %}
Expand Down Expand Up @@ -89,6 +105,16 @@ <h3>Login using <a href="https://browserid.org/" title="BrowserID">BrowserID</a>
</form>
</div>

<br/>
<div>
<h3>Login in pop-up window:</h3>
<ul>
{% with social_auth.backends.oauth2|first as first_name %}
<li>Some OAuth2 backend: <a rel="nofollow" href="javascript:openPopup('{% url "socialauth_begin" first_name %}'); return void(0);">{{ first_name|title }}</a></li>
{% endwith %}
</ul>
</div>

<div>
<h3>Login using other authentication systems:</h3>
<ul>
Expand Down
3 changes: 2 additions & 1 deletion example/example/urls.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from django.conf.urls.defaults import patterns, url, include
from django.contrib import admin

from app.views import home, done, logout, error, form, form2
from app.views import home, done, logout, error, form, form2, close_login_popup
from app.facebook import facebook_view
from app.vkontakte import vkontakte_view
from app.odnoklassniki import ok_app, ok_app_info
Expand All @@ -21,5 +21,6 @@
url(r'^vk/', vkontakte_view, name='vk_app'),
url(r'^ok/$', ok_app, name='ok_app'),
url(r'^ok/info/$', ok_app_info, name='ok_app_info'),
url(r'^close_login_popup/$', close_login_popup, name='login_popup_close'),
url(r'', include('social_auth.urls')),
)

0 comments on commit 40b0615

Please sign in to comment.