Login fix
This commit is contained in:
parent
0f52b54a2e
commit
1a34329937
@ -1,120 +1,21 @@
|
|||||||
<html>
|
{% extends "authBase.html" %}
|
||||||
|
|
||||||
<head>
|
{% block title %}Login{% endblock %}
|
||||||
<title>Login</title>
|
|
||||||
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
|
|
||||||
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
|
|
||||||
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.6.1/css/all.css" integrity="sha384-gfdkjb5BdAXd+lj+gudLWI+BXq4IuLW5IT+brZEZsLFm++aCMlF1V92rMkPaX4PP" crossorigin="anonymous">
|
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<h2>Log In</h2>
|
||||||
|
<form method="post"> {% csrf_token %}
|
||||||
|
|
||||||
<style>
|
{% for field in login_form %}
|
||||||
body,
|
<p>
|
||||||
html {
|
{{field.label_tag}}
|
||||||
margin: 0;
|
{{field}}
|
||||||
padding: 0;
|
{% for error in field.errors %}
|
||||||
height: 100%;
|
<p style="color: red;">{{error}}</p>
|
||||||
background: #7abecc !important;
|
{% endfor %}
|
||||||
}
|
</p>
|
||||||
.user_card {
|
{% endfor %}
|
||||||
width: 350px;
|
<input type="submit" value="Login">
|
||||||
margin-top: auto;
|
|
||||||
margin-bottom: auto;
|
|
||||||
background: #74cfbf;
|
|
||||||
position: relative;
|
|
||||||
display: flex;
|
|
||||||
justify-content: center;
|
|
||||||
flex-direction: column;
|
|
||||||
padding: 10px;
|
|
||||||
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
|
|
||||||
-webkit-box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
|
|
||||||
-moz-box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
|
|
||||||
border-radius: 5px;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
.form_container {
|
|
||||||
margin-top: 20px;
|
|
||||||
}
|
|
||||||
|
|
||||||
#form-title{
|
|
||||||
color: #fff;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
.login_btn {
|
|
||||||
width: 100%;
|
|
||||||
background: #33ccff !important;
|
|
||||||
color: white !important;
|
|
||||||
}
|
|
||||||
.login_btn:focus {
|
|
||||||
box-shadow: none !important;
|
|
||||||
outline: 0px !important;
|
|
||||||
}
|
|
||||||
.login_container {
|
|
||||||
padding: 0 2rem;
|
|
||||||
}
|
|
||||||
.input-group-text {
|
|
||||||
background: #f7ba5b !important;
|
|
||||||
color: white !important;
|
|
||||||
border: 0 !important;
|
|
||||||
border-radius: 0.25rem 0 0 0.25rem !important;
|
|
||||||
}
|
|
||||||
.input_user,
|
|
||||||
.input_pass:focus {
|
|
||||||
box-shadow: none !important;
|
|
||||||
outline: 0px !important;
|
|
||||||
}
|
|
||||||
|
|
||||||
#messages{
|
|
||||||
background-color: grey;
|
|
||||||
color: #fff;
|
|
||||||
padding: 10px;
|
|
||||||
margin-top: 10px;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<div class="container h-100">
|
|
||||||
<div class="d-flex justify-content-center h-100">
|
|
||||||
<div class="user_card">
|
|
||||||
<div class="d-flex justify-content-center">
|
|
||||||
|
|
||||||
|
|
||||||
<h3 id="form-title">LOGIN</h3>
|
|
||||||
</div>
|
|
||||||
<div class="d-flex justify-content-center form_container">
|
|
||||||
<form method="POST" action="">
|
|
||||||
{% csrf_token %}
|
|
||||||
<div class="input-group mb-3">
|
|
||||||
<div class="input-group-append">
|
|
||||||
<span class="input-group-text"><i class="fas fa-user"></i></span>
|
|
||||||
</div>
|
|
||||||
<input type="text" name="username" placeholder="Username..." class="form-control">
|
|
||||||
</div>
|
|
||||||
<div class="input-group mb-2">
|
|
||||||
<div class="input-group-append">
|
|
||||||
<span class="input-group-text"><i class="fas fa-key"></i></span>
|
|
||||||
</div>
|
|
||||||
<input type="password" name="password" placeholder="Password..." class="form-control" >
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="d-flex justify-content-center mt-3 login_container">
|
|
||||||
<input class="btn login_btn" type="submit" value="Login">
|
|
||||||
</div>
|
|
||||||
</form>
|
</form>
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="mt-4">
|
|
||||||
<div class="d-flex justify-content-center links">
|
|
||||||
Don't have an account? <a href="{% url 'register' %}" class="ml-2">Sign Up</a>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</body>
|
|
||||||
|
|
||||||
</html>
|
|
@ -1,21 +0,0 @@
|
|||||||
{% extends "authBase.html" %}
|
|
||||||
|
|
||||||
{% block title %}Login{% endblock %}
|
|
||||||
|
|
||||||
{% block content %}
|
|
||||||
<h2>Log In</h2>
|
|
||||||
<form method="post"> {% csrf_token %}
|
|
||||||
|
|
||||||
{% for field in login_form %}
|
|
||||||
<p>
|
|
||||||
{{field.label_tag}}
|
|
||||||
{{field}}
|
|
||||||
{% for error in field.errors %}
|
|
||||||
<p style="color: red;">{{error}}</p>
|
|
||||||
{% endfor %}
|
|
||||||
</p>
|
|
||||||
{% endfor %}
|
|
||||||
<input type="submit" value="Login">
|
|
||||||
</form>
|
|
||||||
{% endblock %}
|
|
||||||
|
|
120
templates/login_old.html
Normal file
120
templates/login_old.html
Normal file
@ -0,0 +1,120 @@
|
|||||||
|
<html>
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<title>Login</title>
|
||||||
|
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
|
||||||
|
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
|
||||||
|
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.6.1/css/all.css" integrity="sha384-gfdkjb5BdAXd+lj+gudLWI+BXq4IuLW5IT+brZEZsLFm++aCMlF1V92rMkPaX4PP" crossorigin="anonymous">
|
||||||
|
|
||||||
|
|
||||||
|
<style>
|
||||||
|
body,
|
||||||
|
html {
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
height: 100%;
|
||||||
|
background: #7abecc !important;
|
||||||
|
}
|
||||||
|
.user_card {
|
||||||
|
width: 350px;
|
||||||
|
margin-top: auto;
|
||||||
|
margin-bottom: auto;
|
||||||
|
background: #74cfbf;
|
||||||
|
position: relative;
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
flex-direction: column;
|
||||||
|
padding: 10px;
|
||||||
|
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
|
||||||
|
-webkit-box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
|
||||||
|
-moz-box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
|
||||||
|
border-radius: 5px;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
.form_container {
|
||||||
|
margin-top: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
#form-title{
|
||||||
|
color: #fff;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
.login_btn {
|
||||||
|
width: 100%;
|
||||||
|
background: #33ccff !important;
|
||||||
|
color: white !important;
|
||||||
|
}
|
||||||
|
.login_btn:focus {
|
||||||
|
box-shadow: none !important;
|
||||||
|
outline: 0px !important;
|
||||||
|
}
|
||||||
|
.login_container {
|
||||||
|
padding: 0 2rem;
|
||||||
|
}
|
||||||
|
.input-group-text {
|
||||||
|
background: #f7ba5b !important;
|
||||||
|
color: white !important;
|
||||||
|
border: 0 !important;
|
||||||
|
border-radius: 0.25rem 0 0 0.25rem !important;
|
||||||
|
}
|
||||||
|
.input_user,
|
||||||
|
.input_pass:focus {
|
||||||
|
box-shadow: none !important;
|
||||||
|
outline: 0px !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
#messages{
|
||||||
|
background-color: grey;
|
||||||
|
color: #fff;
|
||||||
|
padding: 10px;
|
||||||
|
margin-top: 10px;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div class="container h-100">
|
||||||
|
<div class="d-flex justify-content-center h-100">
|
||||||
|
<div class="user_card">
|
||||||
|
<div class="d-flex justify-content-center">
|
||||||
|
|
||||||
|
|
||||||
|
<h3 id="form-title">LOGIN</h3>
|
||||||
|
</div>
|
||||||
|
<div class="d-flex justify-content-center form_container">
|
||||||
|
<form method="POST" action="">
|
||||||
|
{% csrf_token %}
|
||||||
|
<div class="input-group mb-3">
|
||||||
|
<div class="input-group-append">
|
||||||
|
<span class="input-group-text"><i class="fas fa-user"></i></span>
|
||||||
|
</div>
|
||||||
|
<input type="text" name="username" placeholder="Username..." class="form-control">
|
||||||
|
</div>
|
||||||
|
<div class="input-group mb-2">
|
||||||
|
<div class="input-group-append">
|
||||||
|
<span class="input-group-text"><i class="fas fa-key"></i></span>
|
||||||
|
</div>
|
||||||
|
<input type="password" name="password" placeholder="Password..." class="form-control" >
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="d-flex justify-content-center mt-3 login_container">
|
||||||
|
<input class="btn login_btn" type="submit" value="Login">
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="mt-4">
|
||||||
|
<div class="d-flex justify-content-center links">
|
||||||
|
Don't have an account? <a href="{% url 'register' %}" class="ml-2">Sign Up</a>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
|
||||||
|
</html>
|
@ -12,12 +12,3 @@ class RegistrationForm(UserCreationForm):
|
|||||||
class Meta:
|
class Meta:
|
||||||
model = User
|
model = User
|
||||||
fields = ("email", "first_name", "last_name", "password1", "password2")
|
fields = ("email", "first_name", "last_name", "password1", "password2")
|
||||||
|
|
||||||
|
|
||||||
class LoginForm(AuthenticationForm):
|
|
||||||
#email = forms.EmailField(max_length=60, widget=forms.EmailInput(attrs={'placeholder': 'Enter Email'}))
|
|
||||||
password = forms.CharField(widget=forms.PasswordInput(attrs={'placeholder': 'Enter Password'}))
|
|
||||||
|
|
||||||
class Meta:
|
|
||||||
model = User
|
|
||||||
fields = ("email", "password")
|
|
||||||
|
@ -4,7 +4,7 @@ from django.urls import path
|
|||||||
from users.views import UserModelViewSet
|
from users.views import UserModelViewSet
|
||||||
from rest_framework_simplejwt.views import TokenObtainPairView
|
from rest_framework_simplejwt.views import TokenObtainPairView
|
||||||
from rest_framework_simplejwt.views import TokenRefreshView
|
from rest_framework_simplejwt.views import TokenRefreshView
|
||||||
from .views import PasswordReset, UserPasswordResetConfirmView, RegisterViewSet, login, logout, register, register_success, login2
|
from .views import PasswordReset, UserPasswordResetConfirmView, RegisterViewSet, login, logout, register, register_success
|
||||||
|
|
||||||
|
|
||||||
router = DefaultRouter(trailing_slash=False)
|
router = DefaultRouter(trailing_slash=False)
|
||||||
|
@ -10,7 +10,7 @@ from .serializers import UserPasswordResetSerializer, UserPasswordResetConfirmSe
|
|||||||
from rest_framework.response import Response
|
from rest_framework.response import Response
|
||||||
from django.shortcuts import render, redirect
|
from django.shortcuts import render, redirect
|
||||||
from django.template import loader
|
from django.template import loader
|
||||||
from .forms import RegistrationForm, LoginForm
|
from .forms import RegistrationForm
|
||||||
from django.contrib.auth.forms import AuthenticationForm
|
from django.contrib.auth.forms import AuthenticationForm
|
||||||
from django.contrib.auth import login as auth_login
|
from django.contrib.auth import login as auth_login
|
||||||
from config.authh import SettingsBackend
|
from config.authh import SettingsBackend
|
||||||
@ -103,30 +103,10 @@ def login_success(request):
|
|||||||
return render(request, 'great.html')
|
return render(request, 'great.html')
|
||||||
|
|
||||||
|
|
||||||
def login2(request):
|
|
||||||
context = {}
|
|
||||||
if request.POST:
|
|
||||||
form = LoginForm(request.POST)
|
|
||||||
if form.is_valid():
|
|
||||||
email = form.cleaned_data["email"],
|
|
||||||
password = form.cleaned_data["password1"]
|
|
||||||
# username = request.POST.get("email")
|
|
||||||
# password = request.POST.get("password")
|
|
||||||
user = SettingsBackend().authenticate(request, email=email, password=password)
|
|
||||||
if user is not None:
|
|
||||||
auth_login(request, user)
|
|
||||||
return redirect('home')
|
|
||||||
else:
|
|
||||||
context['login_form'] = form
|
|
||||||
else:
|
|
||||||
form = LoginForm()
|
|
||||||
context['login_form'] = form
|
|
||||||
return render(request, 'login2.html', context)
|
|
||||||
|
|
||||||
|
|
||||||
def login(request):
|
def login(request):
|
||||||
context = {}
|
context = {}
|
||||||
if request.POST:
|
if request.POST:
|
||||||
|
form = AuthenticationForm(request.POST)
|
||||||
username = request.POST.get("username")
|
username = request.POST.get("username")
|
||||||
password = request.POST.get("password")
|
password = request.POST.get("password")
|
||||||
|
|
||||||
@ -134,4 +114,8 @@ def login(request):
|
|||||||
if user is not None:
|
if user is not None:
|
||||||
auth_login(request, user)
|
auth_login(request, user)
|
||||||
return redirect('home')
|
return redirect('home')
|
||||||
|
context['login_form'] = form
|
||||||
|
else:
|
||||||
|
form = AuthenticationForm()
|
||||||
|
context['login_form'] = form
|
||||||
return render(request, 'login.html', context)
|
return render(request, 'login.html', context)
|
||||||
|
Loading…
Reference in New Issue
Block a user