Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @csrf_protect
- def login_view(request):
- title = "Login"
- email = request.POST.get('email', '')
- password = request.POST.get('password', '')
- user = auth.authenticate(email=email, password=password)
- if request.method == 'POST':
- form = AuthenticationForm(data=request.POST)
- if form.is_valid():
- form.clean()
- login(request, form.Label.choice)
- if form.Label.choices == 'truck':
- return HttpResponseRedirect('/post_load/')
- elif form.Label.choices == 'company':
- return HttpResponseRedirect('/live_deal/')
- else:
- form = AuthenticationForm()
- return render(request, 'registration/login.html', {'form' : form, 'title': title})
- class AuthenticationForm(forms.Form):
- email = forms.EmailField(label=_("Email"),widget=forms.EmailInput)
- password = forms.CharField(label=_("Password"),widget=forms.PasswordInput)
- CHOICES= (('Truck', 'Truck'),('Company', 'Company'),)
- Label = forms.ChoiceField(choices=CHOICES, label='Label', widget=forms.RadioSelect())
- {%extends "registration/header.html"%}
- {% block content %}
- {% if form.errors %}
- <p>Your email and password didn't match. Please try again.</p>
- {% endif %}
- <form class="form-horizontal" method="post" action = "." >{%csrf_token%}
- <div class="panel panel-default login">
- <div class="panel-heading">
- <span class="glyphicon glyphicon-lock"></span> Login</div>
- <div class="panel-body">
- <form class="form-horizontal" role="form">
- <div class="form-group">
- <div class='col-sm-6 col-sm-offset-4'>
- <table border="0">
- <div class="col-sm-4">
- <tr><th><label for="id_user" class="col-sm-4 control-label">Email:</label></th><td>{{ form.email }}</td></tr> </div>
- <div class="col-sm-4">
- <tr><th><label for="id_password" class="col-sm-4 control-label">Password:</label></th><td>{{ form.password }}</td></tr> </div>
- </table> </div>
- </div>
- </div>
- <div class="form-group">
- <div class="col-sm-offset-4 col-sm-8">
- <div class="checkbox">
- <label>
- <input type="checkbox"/>
- Remember me
- </label>
- </div>
- </div>
- </div>
- <div class="form-group last">
- <div class="col-sm-offset-4 col-sm-8">
- <button type="submit" class="btn btn-success btn-sm">
- Sign in</button>
- <input type="hidden" name="next" value="/" />
- <label class="col-sm-offset-3">
- <a href="#">Forget Password? </a>
- </label>
- </div>
- </div>
- </form>
- </div>
- <div class="panel-footer">
- Not Registered? <a href="/register/">Register</a></div>
- </div>
- </form>
- {% endblock %}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement