reg/views.py
changeset 76 b0f5c8666edf
parent 62 b7e47cc39342
child 77 121a7aa78469
equal deleted inserted replaced
75:bda9ee536063 76:b0f5c8666edf
    33     """ get the user object from e-mail and then check for password.
    33     """ get the user object from e-mail and then check for password.
    34     """
    34     """
    35 
    35 
    36     user = request.user
    36     user = request.user
    37     if user.is_authenticated():
    37     if user.is_authenticated():
    38         return redirect('/reg')
    38         return redirect("/workshop/registration")
    39 
    39 
    40     if request.method == "POST":
    40     if request.method == "POST":
    41         form = reg_forms.LoginForm(request.POST)
    41         form = reg_forms.LoginForm(request.POST)
    42         if form.is_valid():
    42         if form.is_valid():
    43             email = form.cleaned_data['email']
    43             email = form.cleaned_data['email']
    44             password = form.cleaned_data['password']
    44             password = form.cleaned_data['password']
    45             username = User.objects.get(email__iexact=email).username
    45             username = User.objects.get(email__iexact=email).username
    46 
    46 
    47             new_user = authenticate(username=username, password=password)
    47             new_user = authenticate(username=username, password=password)
    48             login(request, new_user)
    48             login(request, new_user)
    49             return redirect('/reg')
    49             return redirect("/workshop/registration")
    50         else:
    50         else:
    51             return render_to_response('login.html', {'user':user, 'form':form})
    51             return render_to_response('login.html', {'user':user, 'form':form})
    52     else:
    52     else:
    53         form = reg_forms.LoginForm()
    53         form = reg_forms.LoginForm()
    54         return render_to_response('login.html', {'user':user, 'form':form})
    54         return render_to_response('login.html', {'user':user, 'form':form})
    56 def user_logout(request):
    56 def user_logout(request):
    57     """ simply logout the user and redirect to homepage.
    57     """ simply logout the user and redirect to homepage.
    58     """
    58     """
    59 
    59 
    60     logout(request)
    60     logout(request)
    61     return redirect('/reg')
    61     return redirect("/workshop/registration")
    62 
    62 
    63 def user_register(request, event_key):
    63 def user_register(request, event_key):
    64     """ take the credentials like name, college and gender here itself.
    64     """ take the credentials like name, college and gender here itself.
    65     """
    65     """
    66 
    66 
   112     see if the corresponding user is inactive.
   112     see if the corresponding user is inactive.
   113     """
   113     """
   114 
   114 
   115     user = request.user
   115     user = request.user
   116     if user.is_authenticated() and user.is_active:
   116     if user.is_authenticated() and user.is_active:
   117         return redirect('/reg')
   117         return redirect("/workshop/registration")
   118 
   118 
   119     try:
   119     try:
   120         profile = Profile.objects.get(activation_key__iexact=activation_key)
   120         profile = Profile.objects.get(activation_key__iexact=activation_key)
   121     except Profile.DoesNotExist:
   121     except Profile.DoesNotExist:
   122         raise Http404
   122         raise Http404
   142         new_user = User.objects.get(email__iexact=email)
   142         new_user = User.objects.get(email__iexact=email)
   143     except User.DoesNotExist:
   143     except User.DoesNotExist:
   144         raise Http404
   144         raise Http404
   145 
   145 
   146     if new_user.is_active:
   146     if new_user.is_active:
   147         return redirect('/reg')
   147         return redirect("/workshop/registration")
   148     
   148     
   149     profile = new_user.get_profile()
   149     profile = new_user.get_profile()
   150     activation_key = profile.activation_key
   150     activation_key = profile.activation_key
   151     reg_events.send_activation(new_user)
   151     reg_events.send_activation(new_user)
   152     
   152     
   214     Then call the event.
   214     Then call the event.
   215     """
   215     """
   216 
   216 
   217     user = request.user
   217     user = request.user
   218     if user.is_authenticated():
   218     if user.is_authenticated():
   219         return redirect('/reg')
   219         return redirect("/workshop/registration")
   220 
   220 
   221     if request.method == "POST":
   221     if request.method == "POST":
   222         form = reg_forms.PasswordResetForm(request.POST)
   222         form = reg_forms.PasswordResetForm(request.POST)
   223         if form.is_valid():
   223         if form.is_valid():
   224             email = form.cleaned_data['email']
   224             email = form.cleaned_data['email']
   357     then show the profile.
   357     then show the profile.
   358     """
   358     """
   359 
   359 
   360     user = request.user
   360     user = request.user
   361     if not ( user.is_authenticated() and user.is_active ):
   361     if not ( user.is_authenticated() and user.is_active ):
   362         return redirect('/reg')
   362         return redirect("/workshop/registration")
   363 
   363 
   364     user_profile = user.get_profile()
   364     user_profile = user.get_profile()
   365     return render_to_response('view_profile.html', {'user':user, 'user_profile':user_profile})
   365     return render_to_response('view_profile.html', {'user':user, 'user_profile':user_profile})
   366 
   366 
   367 def edit_profile(request):
   367 def edit_profile(request):
   368     """ check if user is logged in.
   368     """ check if user is logged in.
   369     """
   369     """
   370 
   370 
   371     user = request.user
   371     user = request.user
   372     if not ( user.is_authenticated() and user.is_active ):
   372     if not ( user.is_authenticated() and user.is_active ):
   373         return redirect('/reg')
   373         return redirect("/workshop/registration")
   374 
   374 
   375     user_profile = user.get_profile()
   375     user_profile = user.get_profile()
   376 
   376 
   377     if request.method == "POST":
   377     if request.method == "POST":
   378         form = reg_forms.EditProfileForm(request.POST)
   378         form = reg_forms.EditProfileForm(request.POST)
   414 
   414 
   415     user = request.user
   415     user = request.user
   416     try:
   416     try:
   417         event = Event.objects.get(key__iexact=event_key)
   417         event = Event.objects.get(key__iexact=event_key)
   418     except Event.DoesNotExist:
   418     except Event.DoesNotExist:
   419         return redirect('/reg')
   419         return redirect("/workshop/registration")
   420 
   420 
   421     if not user in event.organizers.all() and user.is_active:
   421     if not user in event.organizers.all() and user.is_active:
   422         return redirect('/reg')
   422         return redirect("/workshop/registration")
   423     
   423     
   424     profile = user.get_profile()
   424     profile = user.get_profile()
   425     return render_to_response('list_attendees.html', {'user':user, 'event':event, 'attendees':event.attendees.all()})
   425     return render_to_response('list_attendees.html', {'user':user, 'event':event, 'attendees':event.attendees.all()})