diff options
-rw-r--r-- | hyperkitty/static/css/hyperkitty.css | 20 | ||||
-rw-r--r-- | hyperkitty/static/img/login/persona-large.png | bin | 0 -> 3684 bytes | |||
-rw-r--r-- | hyperkitty/templates/base.html | 4 | ||||
-rw-r--r-- | hyperkitty/templates/login.html | 41 | ||||
-rw-r--r-- | hyperkitty/templates/register.html | 20 | ||||
-rw-r--r-- | hyperkitty/views/accounts.py | 27 | ||||
-rw-r--r-- | hyperkitty/views/forms.py | 34 |
7 files changed, 88 insertions, 58 deletions
diff --git a/hyperkitty/static/css/hyperkitty.css b/hyperkitty/static/css/hyperkitty.css index f08baaa..bc57a32 100644 --- a/hyperkitty/static/css/hyperkitty.css +++ b/hyperkitty/static/css/hyperkitty.css @@ -78,24 +78,26 @@ h1.lists { /* Login form */ -#loginform { +#login, +#register { text-align: left; width: 40em; margin: 0 auto; } -#loginform h2 { - margin-bottom: 1.5em; +#login h2, +#register h2 { + margin: 4em 0 1em 0; text-align: center; + font-size: 160%; } -.socialLogin { - list-style: none; - margin: 0px; +#login .social-login { + text-align: center; } -.socialLogin li { - float: left; - padding: 5px; +#login .social-login li { + margin: 0 20px; } + /* from Bootstrap's alert class */ .errorlist { list-style-type: none; diff --git a/hyperkitty/static/img/login/persona-large.png b/hyperkitty/static/img/login/persona-large.png Binary files differnew file mode 100644 index 0000000..ab88a71 --- /dev/null +++ b/hyperkitty/static/img/login/persona-large.png diff --git a/hyperkitty/templates/base.html b/hyperkitty/templates/base.html index d645dbe..85b044e 100644 --- a/hyperkitty/templates/base.html +++ b/hyperkitty/templates/base.html @@ -26,8 +26,8 @@ <li><a class="mm_logout" href="{% url user_logout %}">Logout</a></li> <li><a href="{% url user_profile %}">{{ user.username }}</a></li> {% else %} - <li><a class="mm_user" href="{% url user_login %}?next={{next|default:request.path}}">Login</a></li> - <li><a href="{% url user_registration %}?next={{next|default:request.path}}"> Sign Up </a></li> + <li><a class="mm_user" href="{% url user_login %}?next={{next|default:request.path|urlencode}}">Login</a></li> + <li><a href="{% url user_registration %}?next={{next|default:request.path|urlencode}}"> Sign Up </a></li> {% endif %} </ul> diff --git a/hyperkitty/templates/login.html b/hyperkitty/templates/login.html index 9bce6ee..17d8d4b 100644 --- a/hyperkitty/templates/login.html +++ b/hyperkitty/templates/login.html @@ -1,5 +1,6 @@ {% extends "base.html" %} {% load i18n %} +{% load crispy_forms_tags %} {% block title %} @@ -8,37 +9,37 @@ {% block content %} -<div id="loginform"> +<div id="login"> -<h2>Login with username and password</h2> - - -<form action="{{ request.path }}?next={{ next }}" method="post" class="login mm_clear"> - {% csrf_token %} - {{ form.as_p }} - <div class="field"> - <button class="btn btn-primary" type="submit"> - {% trans "Login" %} - </button> - </div> -</form> - - -<ul class="socialLogin"> - <li><a title="Google" class="socialaccount_provider google" href="{% url socialauth_begin backend='google' %}"><img src="{{ STATIC_URL }}img/login/google.png" alt="Google"></a></li> - - <li><a title="Yahoo" class="socialaccount_provider yahoo" href="{% url socialauth_begin backend='yahoo' %}"><img src="{{ STATIC_URL }}img/login/yahoo.png" alt="Yahoo"></a></li> +<h2>Login with your email</h2> +<ul class="social-login inline"> <li> <form method="post" action="{% url socialauth_complete "browserid" %}?next={{ next }}"> {% csrf_token %} <input type="hidden" name="assertion" value="" /> - <a rel="nofollow" id="browserid" href="#"><img src="{{ STATIC_URL }}img/login/browserid.png" alt="Login using BrowserID" /></a> + <a rel="nofollow" id="browserid" href="#"><img src="{{ STATIC_URL }}img/login/persona-large.png" alt="Login using Persona" /></a> </form> </li> + <li><a title="Google" class="socialaccount_provider google" href="{% url socialauth_begin backend='google' %}"><img src="{{ STATIC_URL }}img/login/google.png" alt="Google"></a></li> + <li><a title="Yahoo" class="socialaccount_provider yahoo" href="{% url socialauth_begin backend='yahoo' %}"><img src="{{ STATIC_URL }}img/login/yahoo.png" alt="Yahoo"></a></li> </ul> + +<h2>Login with username and password</h2> + +<form action="{{ request.path }}?next={{ next|urlencode }}" method="post" class="form-horizontal"> + {% csrf_token %} + {{ form|crispy }} + <div class="control-group"> + <div class="controls"> + <button type="submit" class="btn btn-primary">{% trans "Login" %}</button> + </div> + </div> +</form> + + </div> {% endblock %} diff --git a/hyperkitty/templates/register.html b/hyperkitty/templates/register.html index 7d665ab..71d4d6a 100644 --- a/hyperkitty/templates/register.html +++ b/hyperkitty/templates/register.html @@ -1,5 +1,6 @@ {% extends "base.html" %} {% load i18n %} +{% load crispy_forms_tags %} {% block title %} @@ -8,17 +9,22 @@ {% block content %} -<form action="" method="post" class="login mm_clear"> +<div id="register"> + +<h2>Register</h2> + +<form action="{{ request.path }}?next={{ next|urlencode }}" method="post" class="form-horizontal"> {% csrf_token %} - {{ form.as_p }} - <input type="hidden" name="next" value="{{ next }}"> - <div class="field"> - <button class="btn btn-primary" type="submit"> - {% trans "Register" %} - </button> + {{ form|crispy }} + <div class="control-group"> + <div class="controls"> + <button type="submit" class="btn btn-primary">{% trans "Register" %}</button> + </div> </div> </form> +</div> + {% endblock %} {# vim: set noet: #} diff --git a/hyperkitty/views/accounts.py b/hyperkitty/views/accounts.py index 21f0fad..645166e 100644 --- a/hyperkitty/views/accounts.py +++ b/hyperkitty/views/accounts.py @@ -26,16 +26,17 @@ from urllib2 import HTTPError from urlparse import urlparse from django.conf import settings +from django.core.urlresolvers import reverse from django.contrib import messages from django.contrib.auth import logout, authenticate, login from django.contrib.auth.decorators import (login_required, permission_required, user_passes_test) -from django.contrib.auth.forms import AuthenticationForm from django.contrib.auth.models import User from django.http import HttpResponse, HttpResponseRedirect from django.shortcuts import render_to_response, redirect from django.template import Context, loader, RequestContext +from django.utils.http import is_safe_url from django.utils.translation import gettext as _ from hyperkitty.models import UserProfile, Rating, Favorite @@ -46,6 +47,7 @@ from hyperkitty.lib import get_store logger = logging.getLogger(__name__) + @login_required def user_profile(request, user_email=None): if not request.user.is_authenticated(): @@ -100,15 +102,23 @@ def user_profile(request, user_email=None): def user_registration(request): + redirect_to = request.REQUEST.get("next", reverse("root")) + if not is_safe_url(url=redirect_to, host=request.get_host()): + redirect_to = settings.LOGIN_REDIRECT_URL + + if request.user.is_authenticated(): # Already registered, redirect back to index page - return redirect('index') + return HttpResponseRedirect(redirect_to) if request.POST: form = RegistrationForm(request.POST) if form.is_valid(): - # Save the user data. - form.save(form.cleaned_data) + u = User.objects.create_user(form.cleaned_data['username'], + form.cleaned_data['email'], + form.cleaned_data['password1']) + u.is_active = True + u.save() user = authenticate(username=form.cleaned_data['username'], password=form.cleaned_data['password1']) @@ -116,9 +126,14 @@ def user_registration(request): logger.debug(user) if user.is_active: login(request, user) - return redirect('index') + return HttpResponseRedirect(redirect_to) else: form = RegistrationForm() - return render_to_response('register.html', {'form': form}, context_instance=RequestContext(request)) + context = { + 'form': form, + 'next': redirect_to, + } + return render_to_response('register.html', context, + context_instance=RequestContext(request)) diff --git a/hyperkitty/views/forms.py b/hyperkitty/views/forms.py index 3fe6e7e..c19ace4 100644 --- a/hyperkitty/views/forms.py +++ b/hyperkitty/views/forms.py @@ -25,6 +25,7 @@ from django.contrib.auth.models import User from django.utils.safestring import mark_safe + def isValidUsername(username): try: User.objects.get(username=username) @@ -33,27 +34,28 @@ def isValidUsername(username): raise validators.ValidationError('The username "%s" is already taken.' % username) + class RegistrationForm(forms.Form): - username = forms.CharField(label='username', help_text=None, - widget=forms.TextInput( - attrs={'placeholder': 'username...'} - ), required = True, validators=[isValidUsername] - ) + username = forms.CharField(widget=forms.TextInput, required=True, + validators=[isValidUsername]) email = forms.EmailField(required=True) - password1 = forms.CharField(widget=forms.PasswordInput) + password1 = forms.CharField(widget=forms.PasswordInput, + required=True, label="Password") + + password2 = forms.CharField(widget=forms.PasswordInput, + required=True, label="Confirm password") - password2 = forms.CharField(widget=forms.PasswordInput) + def clean(self): + cleaned_data = super(RegistrationForm, self).clean() + if cleaned_data.get("password1") != cleaned_data.get("password2"): + self._errors["password2"] = self.error_class(["Passwords do not match."]) + del cleaned_data["password1"] + del cleaned_data["password2"] + return cleaned_data - def save(self, new_user_data): - u = User.objects.create_user(new_user_data['username'], - new_user_data['email'], - new_user_data['password1']) - u.is_active = True - u.save() - return u class TextInputWithButton(forms.TextInput): @@ -74,6 +76,7 @@ class TextInputWithButton(forms.TextInput): initial_rendering, button, u'</span>']) + class AddTagForm(forms.Form): tag = forms.CharField(label='', help_text=None, widget=TextInputWithButton( @@ -84,6 +87,8 @@ class AddTagForm(forms.Form): ) from_url = forms.CharField(widget=forms.HiddenInput, required=False) + + class SearchForm(forms.Form): target = forms.CharField(label='', help_text=None, widget=forms.Select( @@ -101,6 +106,7 @@ class SearchForm(forms.Form): ) + class ReplyForm(forms.Form): message = forms.CharField(widget=forms.Textarea, label="") |