reg/views.py
changeset 50 fd37bbece439
parent 49 4c1d3fe9fef1
child 51 08da9bd64fca
equal deleted inserted replaced
49:4c1d3fe9fef1 50:fd37bbece439
    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             user = authenticate(username=username, password=password)
    47             new_user = authenticate(username=username, password=password)
    48             if user.is_active:
    48             login(request, new_user)
    49                 login(request, user)
    49             return redirect('/reg')
    50                 return redirect('/reg')
       
    51             else:
       
    52                 return render_to_response('account_inactive.html', {'email':email})
       
    53         else:
    50         else:
    54             return render_to_response('login.html', {'user':user, 'form':form})
    51             return render_to_response('login.html', {'user':user, 'form':form})
    55     else:
    52     else:
    56         form = reg_forms.LoginForm()
    53         form = reg_forms.LoginForm()
    57         return render_to_response('login.html', {'user':user, 'form':form})
    54         return render_to_response('login.html', {'user':user, 'form':form})
   132 def resend_activation(request):
   129 def resend_activation(request):
   133     """ resend only if user is registered and is inactive.
   130     """ resend only if user is registered and is inactive.
   134     """
   131     """
   135 
   132 
   136     user = request.user
   133     user = request.user
       
   134     if not user.is_authenticated():
       
   135         raise Http404
       
   136 
   137     try:
   137     try:
   138         email = request.GET['email']
   138         email = request.GET['email']
   139     except MultiValueDictKeyError:
   139     except MultiValueDictKeyError:
   140         raise Http404
   140         raise Http404
   141 
   141 
   359     """ check if user is logged in.
   359     """ check if user is logged in.
   360     then show the profile.
   360     then show the profile.
   361     """
   361     """
   362 
   362 
   363     user = request.user
   363     user = request.user
   364     if not user.is_authenticated():
   364     if not ( user.is_authenticated() and user.is_active ):
   365         return redirect('/reg')
   365         return redirect('/reg')
   366 
   366 
   367     user_profile = user.get_profile()
   367     user_profile = user.get_profile()
   368     return render_to_response('view_profile.html', {'user':user, 'user_profile':user_profile})
   368     return render_to_response('view_profile.html', {'user':user, 'user_profile':user_profile})
   369 
   369