reg/views.py
author nishanth
Fri, 09 Apr 2010 15:35:40 +0530
changeset 6 057498d12450
parent 5 37e4027fba48
child 8 e2699e042129
permissions -rw-r--r--
users can now register but still there is no concept of activation e-mail .
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4
ededea9ad08b login and logout works .
nishanth
parents: 3
diff changeset
     1
from django.contrib.auth.models import User
3
182f216da4a8 made the login view. have to write templates and check it.
nishanth
parents: 2
diff changeset
     2
from django.contrib.auth import authenticate, login, logout
182f216da4a8 made the login view. have to write templates and check it.
nishanth
parents: 2
diff changeset
     3
from django.contrib.auth.decorators import login_required
2
c11afa8623f7 incorporated gen_key .
nishanth
parents: 0
diff changeset
     4
4
ededea9ad08b login and logout works .
nishanth
parents: 3
diff changeset
     5
from django.shortcuts import render_to_response, redirect
ededea9ad08b login and logout works .
nishanth
parents: 3
diff changeset
     6
6
057498d12450 users can now register but still there is no concept of activation e-mail .
nishanth
parents: 5
diff changeset
     7
from workshop.reg.models import Event
3
182f216da4a8 made the login view. have to write templates and check it.
nishanth
parents: 2
diff changeset
     8
from workshop.reg import forms as reg_forms
6
057498d12450 users can now register but still there is no concept of activation e-mail .
nishanth
parents: 5
diff changeset
     9
from workshop.reg import events as reg_events
3
182f216da4a8 made the login view. have to write templates and check it.
nishanth
parents: 2
diff changeset
    10
4
ededea9ad08b login and logout works .
nishanth
parents: 3
diff changeset
    11
from django.http import HttpResponse
ededea9ad08b login and logout works .
nishanth
parents: 3
diff changeset
    12
ededea9ad08b login and logout works .
nishanth
parents: 3
diff changeset
    13
def homepage(request):
ededea9ad08b login and logout works .
nishanth
parents: 3
diff changeset
    14
    """ see if the user is active.
ededea9ad08b login and logout works .
nishanth
parents: 3
diff changeset
    15
    If not, only show the re send activation email link.
ededea9ad08b login and logout works .
nishanth
parents: 3
diff changeset
    16
    else show all the options in homepage.
ededea9ad08b login and logout works .
nishanth
parents: 3
diff changeset
    17
    """
ededea9ad08b login and logout works .
nishanth
parents: 3
diff changeset
    18
ededea9ad08b login and logout works .
nishanth
parents: 3
diff changeset
    19
    user = request.user
ededea9ad08b login and logout works .
nishanth
parents: 3
diff changeset
    20
6
057498d12450 users can now register but still there is no concept of activation e-mail .
nishanth
parents: 5
diff changeset
    21
    events = Event.objects.all()[:10]
057498d12450 users can now register but still there is no concept of activation e-mail .
nishanth
parents: 5
diff changeset
    22
4
ededea9ad08b login and logout works .
nishanth
parents: 3
diff changeset
    23
ededea9ad08b login and logout works .
nishanth
parents: 3
diff changeset
    24
def user_login(request):
3
182f216da4a8 made the login view. have to write templates and check it.
nishanth
parents: 2
diff changeset
    25
    """ get the user object from e-mail and then check for password.
2
c11afa8623f7 incorporated gen_key .
nishanth
parents: 0
diff changeset
    26
    """
c11afa8623f7 incorporated gen_key .
nishanth
parents: 0
diff changeset
    27
3
182f216da4a8 made the login view. have to write templates and check it.
nishanth
parents: 2
diff changeset
    28
    user = request.user
182f216da4a8 made the login view. have to write templates and check it.
nishanth
parents: 2
diff changeset
    29
    if user.is_authenticated():
182f216da4a8 made the login view. have to write templates and check it.
nishanth
parents: 2
diff changeset
    30
        return redirect('/reg')
182f216da4a8 made the login view. have to write templates and check it.
nishanth
parents: 2
diff changeset
    31
182f216da4a8 made the login view. have to write templates and check it.
nishanth
parents: 2
diff changeset
    32
    if request.method == "POST":
182f216da4a8 made the login view. have to write templates and check it.
nishanth
parents: 2
diff changeset
    33
        form = reg_forms.LoginForm(request.POST)
182f216da4a8 made the login view. have to write templates and check it.
nishanth
parents: 2
diff changeset
    34
        if form.is_valid():
182f216da4a8 made the login view. have to write templates and check it.
nishanth
parents: 2
diff changeset
    35
            email = form.cleaned_data['email']
182f216da4a8 made the login view. have to write templates and check it.
nishanth
parents: 2
diff changeset
    36
            password = form.cleaned_data['password']
4
ededea9ad08b login and logout works .
nishanth
parents: 3
diff changeset
    37
            username = User.objects.get(email__iexact=email).username
3
182f216da4a8 made the login view. have to write templates and check it.
nishanth
parents: 2
diff changeset
    38
4
ededea9ad08b login and logout works .
nishanth
parents: 3
diff changeset
    39
            user = authenticate(username=username, password=password)
3
182f216da4a8 made the login view. have to write templates and check it.
nishanth
parents: 2
diff changeset
    40
            login(request, user)
182f216da4a8 made the login view. have to write templates and check it.
nishanth
parents: 2
diff changeset
    41
            return redirect('/reg')
182f216da4a8 made the login view. have to write templates and check it.
nishanth
parents: 2
diff changeset
    42
        else:
182f216da4a8 made the login view. have to write templates and check it.
nishanth
parents: 2
diff changeset
    43
            return render_to_response('login.html', {'form':form})
182f216da4a8 made the login view. have to write templates and check it.
nishanth
parents: 2
diff changeset
    44
    else:
4
ededea9ad08b login and logout works .
nishanth
parents: 3
diff changeset
    45
        form = reg_forms.LoginForm()
3
182f216da4a8 made the login view. have to write templates and check it.
nishanth
parents: 2
diff changeset
    46
        return render_to_response('login.html', {'form':form})
4
ededea9ad08b login and logout works .
nishanth
parents: 3
diff changeset
    47
ededea9ad08b login and logout works .
nishanth
parents: 3
diff changeset
    48
def user_logout(request):
ededea9ad08b login and logout works .
nishanth
parents: 3
diff changeset
    49
    """ simply logout the user and redirect to homepage.
ededea9ad08b login and logout works .
nishanth
parents: 3
diff changeset
    50
    """
ededea9ad08b login and logout works .
nishanth
parents: 3
diff changeset
    51
ededea9ad08b login and logout works .
nishanth
parents: 3
diff changeset
    52
    logout(request)
ededea9ad08b login and logout works .
nishanth
parents: 3
diff changeset
    53
    return redirect('/reg')
ededea9ad08b login and logout works .
nishanth
parents: 3
diff changeset
    54
6
057498d12450 users can now register but still there is no concept of activation e-mail .
nishanth
parents: 5
diff changeset
    55
def user_register(request):
057498d12450 users can now register but still there is no concept of activation e-mail .
nishanth
parents: 5
diff changeset
    56
    """ take the credentials like name, college and gender here itself.
057498d12450 users can now register but still there is no concept of activation e-mail .
nishanth
parents: 5
diff changeset
    57
    """
4
ededea9ad08b login and logout works .
nishanth
parents: 3
diff changeset
    58
6
057498d12450 users can now register but still there is no concept of activation e-mail .
nishanth
parents: 5
diff changeset
    59
    if request.method == "POST":
057498d12450 users can now register but still there is no concept of activation e-mail .
nishanth
parents: 5
diff changeset
    60
        form = reg_forms.RegisterForm(request.POST)
057498d12450 users can now register but still there is no concept of activation e-mail .
nishanth
parents: 5
diff changeset
    61
        if form.is_valid():
057498d12450 users can now register but still there is no concept of activation e-mail .
nishanth
parents: 5
diff changeset
    62
            data = form.cleaned_data
057498d12450 users can now register but still there is no concept of activation e-mail .
nishanth
parents: 5
diff changeset
    63
            reg_events.create_user(email=data['email'], 
057498d12450 users can now register but still there is no concept of activation e-mail .
nishanth
parents: 5
diff changeset
    64
                                   password=data['password'],
057498d12450 users can now register but still there is no concept of activation e-mail .
nishanth
parents: 5
diff changeset
    65
                                   firstname=data['first_name'],
057498d12450 users can now register but still there is no concept of activation e-mail .
nishanth
parents: 5
diff changeset
    66
                                   lastname=data['last_name'], 
057498d12450 users can now register but still there is no concept of activation e-mail .
nishanth
parents: 5
diff changeset
    67
                                   gender=data['gender'], 
057498d12450 users can now register but still there is no concept of activation e-mail .
nishanth
parents: 5
diff changeset
    68
                                   profession=data['profession'], 
057498d12450 users can now register but still there is no concept of activation e-mail .
nishanth
parents: 5
diff changeset
    69
                                   affiliated_to=data['affiliated_to'], 
057498d12450 users can now register but still there is no concept of activation e-mail .
nishanth
parents: 5
diff changeset
    70
                                   interests=data['interests']
057498d12450 users can now register but still there is no concept of activation e-mail .
nishanth
parents: 5
diff changeset
    71
                                  )
057498d12450 users can now register but still there is no concept of activation e-mail .
nishanth
parents: 5
diff changeset
    72
            return render_to_response('account_created.html')
057498d12450 users can now register but still there is no concept of activation e-mail .
nishanth
parents: 5
diff changeset
    73
        else:
057498d12450 users can now register but still there is no concept of activation e-mail .
nishanth
parents: 5
diff changeset
    74
            return render_to_response('register.html', {'form':form})
057498d12450 users can now register but still there is no concept of activation e-mail .
nishanth
parents: 5
diff changeset
    75
    else:
057498d12450 users can now register but still there is no concept of activation e-mail .
nishanth
parents: 5
diff changeset
    76
        form = reg_forms.RegisterForm()
057498d12450 users can now register but still there is no concept of activation e-mail .
nishanth
parents: 5
diff changeset
    77
        return render_to_response('register.html', {'form':form})