Advertisement
Guest User

Untitled

a guest
Jul 4th, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. class Login(TemplateView):
  2.  
  3.  
  4. # def get(self,request,**kqargs):
  5.  
  6. # if request.user.is_authenticated:
  7.  
  8. # return render(request,'account/dashboard.html')
  9.  
  10. template_name = 'account/login.html'
  11.  
  12. def post(self, request, *args, **kwargs):
  13.  
  14. context = self.get_context_data()
  15.  
  16. if context["form"].is_valid():
  17.  
  18. username = context['form'].data['username']
  19.  
  20. password = context['form'].data['password']
  21.  
  22. user = authenticate(username=username,password=password)
  23.  
  24. if user:
  25.  
  26. login(request,user)
  27.  
  28. return redirect('social:dashboard')
  29.  
  30. else:
  31.  
  32. return redirect('login-again')
  33.  
  34. def get_context_data(self,**kwargs):
  35.  
  36. context = super(Login,self).get_context_data(**kwargs)
  37.  
  38. context['form'] = LoginForm(self.request.POST or None)
  39.  
  40. return context
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement