# HG changeset patch # User dellsystem # Date 1347409431 14400 # Node ID 2bca07be6e51dae811b0c0d67d7a6678837d8095 # Parent 17bc502c65a4286dfbf5455fa5e5d47b03e21463 Add login popup box So you can log in and immediately be redirected to the same page. Sort of like what reddit has. If Javascript is disabled, the user is simply taken to the standard login page. diff -r 17bc502c65a4 -r 2bca07be6e51 static/css/agora.less --- a/static/css/agora.less Tue Sep 11 18:06:01 2012 -0400 +++ b/static/css/agora.less Tue Sep 11 20:23:51 2012 -0400 @@ -265,3 +265,62 @@ border-bottom: 1px solid @lightGrey; } } + +ul { + padding: 5px 0; + margin-left: 20px; +} + +#login-popup { + position: fixed; + top: 0; + left: 0; + right: 0; + bottom: 0; + background: rgba(0, 0, 0, 0.3); + z-index: 200; +} + +#login-form { + @width: 600px; + @height: 300px; + @verticalPadding: 20px; + + .box-shadow(0 0 5px 1px rgba(0, 0, 0, 0.3)); + width: @width; + height: @height - (@verticalPadding * 2); + position: absolute; + top: 50%; + left: 50%; + margin-left: -@width / 2; + margin-top: -@height / 2; + background: @white; + .border-radius(5px); + padding: @verticalPadding 30px; +} + +.errors { + padding-top: 5px; + padding-left: 5px; + background: @lightOrange; + margin-bottom: 10px; + border: 1px solid @orange; + .border-radius(5px); +} + +form { + .form-line { + label { + float: left; + text-align: right; + } + } + + .form-input { + margin-left: 180px; + } + + .errors { + clear: both; + } +} diff -r 17bc502c65a4 -r 2bca07be6e51 static/css/variables.less --- a/static/css/variables.less Tue Sep 11 18:06:01 2012 -0400 +++ b/static/css/variables.less Tue Sep 11 20:23:51 2012 -0400 @@ -9,8 +9,9 @@ @offWhite: #FBFBFB; @white: #FFF; +@darkOrange: #D45500; @orange: #FF7F2A; -@darkOrange: #D45500; +@lightOrange: lighten(@orange, 25%); @darkBlue: #1B749D; @mediumBlue: #22A2CA; diff -r 17bc502c65a4 -r 2bca07be6e51 static/js/agora.js --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/static/js/agora.js Tue Sep 11 20:23:51 2012 -0400 @@ -0,0 +1,25 @@ +(function ($) { + // Handle showing the login popup + var handleLoginLink = function () { + var loginLink = $('.login-link'); + + if (loginLink.length) { + loginLink.click(function () { + $('#login-popup').show(); + + return false; + }); + + $('#login-popup').click(function (event) { + // Only catch events in the outer, overlay div + if (event.target === this) { + $(this).hide(); + } + }); + } + }; + + $(document).ready(function () { + handleLoginLink(); + }); +})(jQuery); diff -r 17bc502c65a4 -r 2bca07be6e51 templates/base.djhtml --- a/templates/base.djhtml Tue Sep 11 18:06:01 2012 -0400 +++ b/templates/base.djhtml Tue Sep 11 20:23:51 2012 -0400 @@ -54,6 +54,7 @@ {% block navbar %} +{% if not user.is_authenticated %}

Explore - - Register an account +

You can sign up, if you want, won't share your email, not required, etc

+{% endif %} {% endblock %} diff -r 17bc502c65a4 -r 2bca07be6e51 templates/login.djhtml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/templates/login.djhtml Tue Sep 11 20:23:51 2012 -0400 @@ -0,0 +1,15 @@ +{% extends "base.djhtml" %} + +{% block content %} +{% include "login_form.djhtml" %} +{% endblock %} + +{% block login_form %} +{% endblock %} + +{% block login_breadcrumbs %} +{% endblock %} + +{% block breadcrumbs %} +« Back to home +{% endblock %} diff -r 17bc502c65a4 -r 2bca07be6e51 templates/login_form.djhtml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/templates/login_form.djhtml Tue Sep 11 20:23:51 2012 -0400 @@ -0,0 +1,85 @@ +

Login or register

+ +{% if user.is_authenticated %} +

+ You are already logged in. + Logout » +

+{% else %} +
+ {% csrf_token %} + +

Already have an account? Enter your username and password below.

+ +
+ +
+ +
+
+ + {% if form.username.errors %} +
+ {{ form.username.errors }} +
+ {% endif %} + +
+ +
+ +
+
+ + {% if form.password1.errors %} +
+ {{ form.password1.errors }} +
+ {% endif %} + +
+ +

+ If you don't have an account yet, you can create one by filling out + the following fields as well: +

+ +
+ +
+ +
+
+ + {% if form.password2.errors %} +
+ {{ form.password2.errors }} +
+ {% endif %} + +
+ +
+ +
+
+ + {% if form.email.errors %} +
+ {{ form.email.errors }} +
+ {% endif %} + +
+ +
+ + +
+
+{% endif %} diff -r 17bc502c65a4 -r 2bca07be6e51 urls.py --- a/urls.py Tue Sep 11 18:06:01 2012 -0400 +++ b/urls.py Tue Sep 11 20:23:51 2012 -0400 @@ -25,10 +25,14 @@ url(r'^code$', 'views.code', name='code'), + url(r'^login', + 'views.login_register', + name='login'), url(r'^admin/doc/', include('django.contrib.admindocs.urls')), url(r'^admin/', include(admin.site.urls)), url(r'^accounts/logout/', 'django.contrib.auth.views.logout', - {'template_name' : 'index.djhtml', 'next_page' : '/'}), + {'template_name' : 'index.djhtml', 'next_page' : '/'} + ), url(r'^accounts/', include('registration.urls')), url(r'^licenses/', include('agora.apps.free_license.urls')), url(r'^users/', include('agora.apps.profile.urls')), diff -r 17bc502c65a4 -r 2bca07be6e51 views.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/views.py Tue Sep 11 20:23:51 2012 -0400 @@ -0,0 +1,59 @@ +from django.contrib.auth import login, authenticate +from django.contrib.auth.forms import AuthenticationForm +from django.shortcuts import render, redirect +from django.core.urlresolvers import reverse +from registration.forms import RegistrationForm + +from agora.apps.snippet.models import Snippet + + +def code(request): + context = { + 'snippets': Snippet.objects.all()[:5], + 'modules': None, # temp + 'forge': None, # temp + } + + return render(request, 'code.djhtml', context) + + +def login_register(request): + form = None + next_url = None + + if request.method == 'POST': + action = request.POST.get('action') + next_url = request.GET.get('next') or reverse('login') + + if action == 'login': + username = request.POST.get('username', '') + password = request.POST.get('password1', '') + + if username and password: + user = authenticate(username=username, password=password) + login(request, user) + + return redirect(next_url) + else: + form = { + 'password1': { + 'errors': 'Please enter a username and password.', + }, + } + elif action == 'register': + form = RegistrationForm(request.POST) + + if form.is_valid(): + user = form.save() + login(request, user) + return redirect(next_url) + else: + # The action is not set. Malicious submission? + pass + + context = { + 'next_url': next_url, + 'form': form, + } + + return render(request, 'login.djhtml', context)