Advertisement
Guest User

loginpython

a guest
Nov 4th, 2016
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.41 KB | None | 0 0
  1. class UserForm(forms.ModelForm):
  2.     password = forms.CharField(widget=forms.PasswordInput())
  3.  
  4.     class Meta:
  5.         model = User
  6.         fields = ('username', 'email', 'password')
  7.  
  8. class UserProfileForm(forms.ModelForm):
  9.     class Meta:
  10.         model = UserProfile
  11.         fields = ('website', 'picture')
  12.  
  13.  
  14. #----- views.py----------------------------
  15.  
  16. def user_login(request):
  17.     # Like before, obtain the context for the user's request.
  18.     context = RequestContext(request)
  19.  
  20.     if request.method == 'POST':
  21.         # Gather the username and password provided by the user.
  22.         # This information is obtained from the login form.
  23.         username = request.POST['username']
  24.         password = request.POST['password']
  25.  
  26.         user = authenticate(username=username, password=password)
  27.  
  28.         if user:
  29.             # Is the account active? It could have been disabled.
  30.             if user.is_active:
  31.                 login(request, user)
  32.                 return HttpResponseRedirect('/rango/')
  33.             else:
  34.                 return HttpResponse("Your Rango account is disabled.")
  35.         else:
  36.             # Bad login details were provided. So we can't log the user in.
  37.             print "Invalid login details: {0}, {1}".format(username, password)
  38.             return HttpResponse("Invalid login details supplied.")
  39.     else:
  40.         return render_to_response('rango/login.html', {}, context)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement