reg/views.py
changeset 3 182f216da4a8
parent 2 c11afa8623f7
child 4 ededea9ad08b
equal deleted inserted replaced
2:c11afa8623f7 3:182f216da4a8
     1 from django.shortcuts import render_to_response
     1 from django.shortcuts import render_to_response, redirect
     2 
     2 
     3 def homepage(request):
     3 from django.contrib.auth import authenticate, login, logout
     4     """ List all the workshops and their status.
     4 from django.contrib.auth.decorators import login_required
       
     5 
       
     6 from workshop.reg import forms as reg_forms
       
     7 
       
     8 def login(request):
       
     9     """ get the user object from e-mail and then check for password.
     5     """
    10     """
     6 
    11 
     7     events = Event.objects.all()
    12     user = request.user
       
    13     if user.is_authenticated():
       
    14         return redirect('/reg')
       
    15 
       
    16     if request.method == "POST":
       
    17         form = reg_forms.LoginForm(request.POST)
       
    18         if form.is_valid():
       
    19             email = form.cleaned_data['email']
       
    20             password = form.cleaned_data['password']
       
    21             username = User.objects.get(email__iexact=email)
       
    22 
       
    23             user = authenticate(username, password)
       
    24             login(request, user)
       
    25             return redirect('/reg')
       
    26         else:
       
    27             return render_to_response('login.html', {'form':form})
       
    28     else:
       
    29         form = LoginForm()
       
    30         return render_to_response('login.html', {'form':form})