logout as logout_django
from django.contrib.auth.models import User, Group
from django.forms import HiddenInput, ModelForm
+from django import forms
from django.shortcuts import render_to_response, get_object_or_404
from django.template import RequestContext, Context, loader
from eventos.models import Palestrante, Trabalho, TipoTrabalho, Trilha, Evento, Improve
class Meta:
model = Improve
+class SubscribeForm(forms.Form):
+ full_name = forms.CharField(label=u'Nome completo', max_length=255)
+ email = forms.EmailField()
+ username = forms.CharField(max_length=255)
+ password = forms.CharField(label=u'Senha',
+ max_length=255,
+ widget=forms.PasswordInput)
+ confirm_password = forms.CharField(label=u'Confirmar senha',
+ max_length=255,
+ widget=forms.PasswordInput)
+
+ def clean_username(self):
+ data = self.cleaned_data['username']
+ if User.objects.filter(username=data):
+ raise forms.ValidationError(u'O usuário "%s" já existe' % data)
+ return data
+
+ def clean_confirm_password(self):
+ passwd = self.cleaned_data['password']
+ conf_passwd = self.cleaned_data['confirm_password']
+ if passwd != conf_passwd:
+ raise forms.ValidationError(u'A confirmação difere da senha')
+ return conf_passwd
+
def login(request):
"""This is a function that will be used as a front-end to the
django's login system. It receives username and password fields
"""
username = request.POST['username']
password = request.POST['password']
+
user = authenticate(username=username, password=password)
if user is not None:
c = {'talk': talk, 'form': form, 'improve': improve, 'speaker': speaker}
return render_to_response('eventos/talk_improve.html', Context(c),
context_instance=RequestContext(request))
+
+def subscribe(request):
+ """This view shows a form with name, login and password fields and
+ if it receives a post, it will get data from the above fields and
+ create an User (yes, the django User). I think this user will be
+ used as an attendee.
+
+ This function authenticates the new user.
+ """
+ form = SubscribeForm(request.POST or None)
+
+ if request.POST and form.is_valid():
+ new_user = User.objects.create_user(request.POST['username'],
+ request.POST['email'],
+ request.POST['password'])
+ login(request)
+ return HttpResponseRedirect('/')
+
+ context = {'form': form}
+ return render_to_response('eventos/subscribe.html', Context(context),
+ context_instance=RequestContext(request))