<div id="form">
<div class="container">
<div class="col-lg-6 col-lg-offset-3 col-md-6 col-md-offset-3 col-md-8 col-md-offset-2">
<div id="userform">
<ul class="nav nav-tabs nav-justified" role="tablist">
<li class="active"><a href="#signup" role="tab" data-toggle="tab">Регистрация</a></li>
<li><a href="#login" role="tab" data-toggle="tab">Войти</a></li>
</ul>
<div class="tab-content">
<div class="tab-pane fade active in" id="signup">
<h2 class="text-uppercase text-center"> Зарегистрироваться бесплатно</h2>
<form id="signup">
<div class="row">
<div class="col-xs-12 col-sm-6">
<div class="form-group">
<label>Имя<span class="req">*</span> </label>
<input type="text" name="first_name" class="form-control" id="first_name" required data-validation-required-message="Please enter your name." autocomplete="off">
<p class="help-block text-danger"></p>
</div>
</div>
<div class="col-xs-12 col-sm-6">
<div class="form-group">
<label> Фамилия <span class="req">*</span> </label>
<input type="text" name="last_name" class="form-control" id="last_name" required data-validation-required-message="Please enter your name." autocomplete="off">
<p class="help-block text-danger"></p>
</div>
</div>
</div>
<div class="form-group">
<label> Email<span class="req">*</span> </label>
<input type="email" name="email" class="form-control" id="email" required data-validation-required-message="Please enter your email address." autocomplete="off">
<p class="help-block text-danger"></p>
</div>
<div class="form-group">
<label> Номер телефона<span class="req">*</span> </label>
<input type="tel" name="phone" class="form-control" id="phone" required data-validation-required-message="Please enter your phone number." autocomplete="off">
<p class="help-block text-danger"></p>
</div>
<div class="form-group">
<label> Пароль<span class="req">*</span> </label>
<input type="password" name="password" class="form-control" id="password" required data-validation-required-message="Please enter your password" autocomplete="off">
<p class="help-block text-danger"></p>
</div>
<div class="mrgn-30-top">
{% csrf_token %}
<button type="submit" name="submit" value="signup" formmethod="post" method="post" class="btn btn-larger btn-block"/>
Зарегистрироваться
</button>
</div>
</form>
</div>
<div class="tab-pane fade in" id="login">
<h2 class="text-uppercase text-center"> Войти</h2>
<form id="login">
<div class="form-group">
<label> Email<span class="req">*</span> </label>
<input type="email" name="email" class="form-control" id="email" required data-validation-required-message="Please enter your email address." autocomplete="off">
<p class="help-block text-danger"></p>
</div>
<div class="form-group">
<label> Пароль<span class="req">*</span> </label>
<input type="password" name="password" class="form-control" id="password" required data-validation-required-message="Please enter your password" autocomplete="off">
<p class="help-block text-danger"></p>
</div>
<div class="mrgn-30-top">
{% csrf_token %}
<button type="submit" name="submit" value="login" formmethod="post" method="post" class="btn btn-larger btn-block"/>
Войти
</button>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
<!-- /.container -->
</div>
def user_login(request):
if request.user.is_authenticated:
return redirect('home')
else:
if request.method == 'POST':
if request.POST.get('submit') == 'login':
email = request.POST.get('email')
password = request.POST.get('password')
user = authenticate(request, username=email, password=password)
if user is not None:
login(request, user)
return redirect('home')
else:
return redirect('login')
elif request.POST.get('submit') == 'signup':
first_name = request.POST.get('first_name')
last_name = request.POST.get('last_name')
email = request.POST.get('email')
phone = request.POST.get('phone')
password = request.POST.get('password')
data = User(first_name=first_name, last_name=last_name, email=email, phone=phone, password=password)
data.save()
return redirect('home')
elif request.method == 'GET':
return render(request, 'pizza/sign_up.html')