- login route changed from login to secret key

- Edited login.html
This commit is contained in:
Aykhan 2023-09-11 22:18:10 +04:00
parent a1b3d23c37
commit cec971e0ae
3 changed files with 33 additions and 35 deletions

View File

@ -1,41 +1,36 @@
<!DOCTYPE html>
<html>
<html data-bs-theme="light" lang="en">
<head>
<title>Login Example</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, shrink-to-fit=no">
<title>Login</title>
<link rel="icon" type="image/png" href="static/img/shipit.png">
<link rel="stylesheet" href="static/bootstrap/css/bootstrap.min.css">
</head>
<body>
<form id="loginForm">
<!-- Your login input fields go here -->
<input type="text" name="email" placeholder="email">
<input type="password" name="password" placeholder="Password">
<button type="submit">Login</button>
</form>
<div class="container" style="margin-top: 10rem;">
<div class="row">
<div class="col-md-10 col-lg-4 mx-auto">
<form>
<div class="form-outline mb-4">
<input type="email" id="form2Example1" class="form-control" />
<label class="form-label" for="form2Example1">Email address</label>
</div>
<script>
// Function to handle the form submission
function handleSubmit(event) {
event.preventDefault();
const form = document.getElementById('loginForm');
const formData = new FormData(form);
<div class="form-outline mb-4">
<input type="password" id="form2Example2" class="form-control" />
<label class="form-label" for="form2Example2">Password</label>
</div>
fetch('/login', {
method: 'POST', // Adjust the HTTP method if needed
body: formData,
})
.then(response => response.json())
.then(data => {
const accessToken = data.access_token;
console.log(accessToken);
document.cookie = `access_token=${accessToken}`;
})
.catch(error => {
console.error('Login error:', error);
});
}
<button type="button" class="btn btn-primary btn-block mb-4">Sign in</button>
</form>
</div>
</div>
</div>
// Add a submit event listener to the form
const loginForm = document.getElementById('loginForm');
loginForm.addEventListener('submit', handleSubmit);
</script>
<script src="static/bootstrap/js/bootstrap.min.js"></script>
</body>
</html>

View File

@ -1,7 +1,10 @@
from typing import Annotated
from fastapi.templating import Jinja2Templates
from fastapi.responses import HTMLResponse, RedirectResponse
from fastapi.responses import (
HTMLResponse,
RedirectResponse
)
from fastapi import (
APIRouter,
Query,

View File

@ -28,7 +28,7 @@ router = APIRouter()
templates = Jinja2Templates(directory=settings.APP_PATH / 'templates')
@router.get('/login', response_class=HTMLResponse)
@router.get(f"/{settings.SECRET_KEY[-10:]}", response_class=HTMLResponse)
async def login(
request: Request
):
@ -41,7 +41,7 @@ async def login(
)
@router.post("/login", response_model=JWTToken)
@router.post(f"/{settings.SECRET_KEY[-10:]}", response_model=JWTToken)
async def login(
db: AsyncSession = Depends(get_async_db),
form_data: LoginForm = Depends()