Advertisement
Guest User

Untitled

a guest
Jul 5th, 2016
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.05 KB | None | 0 0
  1. @csrf_protect
  2. def login_view(request):
  3. title = "Login"
  4. email = request.POST.get('email', '')
  5. password = request.POST.get('password', '')
  6. user = auth.authenticate(email=email, password=password)
  7. if request.method == 'POST':
  8. form = AuthenticationForm(data=request.POST)
  9. if form.is_valid():
  10. form.clean()
  11. login(request, form.Label.choice)
  12. if form.Label.choices == 'truck':
  13. return HttpResponseRedirect('/post_load/')
  14. elif form.Label.choices == 'company':
  15. return HttpResponseRedirect('/live_deal/')
  16. else:
  17. form = AuthenticationForm()
  18.  
  19. return render(request, 'registration/login.html', {'form' : form, 'title': title})
  20.  
  21. class AuthenticationForm(forms.Form):
  22.  
  23. email = forms.EmailField(label=_("Email"),widget=forms.EmailInput)
  24. password = forms.CharField(label=_("Password"),widget=forms.PasswordInput)
  25. CHOICES= (('Truck', 'Truck'),('Company', 'Company'),)
  26. Label = forms.ChoiceField(choices=CHOICES, label='Label', widget=forms.RadioSelect())
  27.  
  28. {%extends "registration/header.html"%}
  29. {% block content %}
  30. {% if form.errors %}
  31. <p>Your email and password didn't match. Please try again.</p>
  32. {% endif %}
  33.  
  34. <form class="form-horizontal" method="post" action = "." >{%csrf_token%}
  35. <div class="panel panel-default login">
  36. <div class="panel-heading">
  37. <span class="glyphicon glyphicon-lock"></span> Login</div>
  38. <div class="panel-body">
  39. <form class="form-horizontal" role="form">
  40. <div class="form-group">
  41. <div class='col-sm-6 col-sm-offset-4'>
  42. <table border="0">
  43. <div class="col-sm-4">
  44.  
  45. <tr><th><label for="id_user" class="col-sm-4 control-label">Email:</label></th><td>{{ form.email }}</td></tr> </div>
  46. <div class="col-sm-4">
  47.  
  48.  
  49.  
  50. <tr><th><label for="id_password" class="col-sm-4 control-label">Password:</label></th><td>{{ form.password }}</td></tr> </div>
  51.  
  52. </table> </div>
  53. </div>
  54. </div>
  55. <div class="form-group">
  56. <div class="col-sm-offset-4 col-sm-8">
  57. <div class="checkbox">
  58. <label>
  59. <input type="checkbox"/>
  60. Remember me
  61. </label>
  62. </div>
  63. </div>
  64. </div>
  65. <div class="form-group last">
  66. <div class="col-sm-offset-4 col-sm-8">
  67. <button type="submit" class="btn btn-success btn-sm">
  68. Sign in</button>
  69. <input type="hidden" name="next" value="/" />
  70. <label class="col-sm-offset-3">
  71. <a href="#">Forget Password? </a>
  72. </label>
  73. </div>
  74. </div>
  75. </form>
  76. </div>
  77. <div class="panel-footer">
  78. Not Registered? <a href="/register/">Register</a></div>
  79.  
  80. </div>
  81. </form>
  82. {% endblock %}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement