- 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> <!DOCTYPE html>
<html> <html data-bs-theme="light" lang="en">
<head> <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> </head>
<body> <body>
<form id="loginForm"> <div class="container" style="margin-top: 10rem;">
<!-- Your login input fields go here --> <div class="row">
<input type="text" name="email" placeholder="email"> <div class="col-md-10 col-lg-4 mx-auto">
<input type="password" name="password" placeholder="Password"> <form>
<button type="submit">Login</button> <div class="form-outline mb-4">
</form> <input type="email" id="form2Example1" class="form-control" />
<label class="form-label" for="form2Example1">Email address</label>
</div>
<script> <div class="form-outline mb-4">
// Function to handle the form submission <input type="password" id="form2Example2" class="form-control" />
function handleSubmit(event) { <label class="form-label" for="form2Example2">Password</label>
event.preventDefault(); </div>
const form = document.getElementById('loginForm');
const formData = new FormData(form);
fetch('/login', { <button type="button" class="btn btn-primary btn-block mb-4">Sign in</button>
method: 'POST', // Adjust the HTTP method if needed </form>
body: formData, </div>
}) </div>
.then(response => response.json()) </div>
.then(data => {
const accessToken = data.access_token;
console.log(accessToken);
document.cookie = `access_token=${accessToken}`;
})
.catch(error => {
console.error('Login error:', error);
});
}
// Add a submit event listener to the form <script src="static/bootstrap/js/bootstrap.min.js"></script>
const loginForm = document.getElementById('loginForm');
loginForm.addEventListener('submit', handleSubmit);
</script>
</body> </body>
</html> </html>

View File

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

View File

@ -28,7 +28,7 @@ router = APIRouter()
templates = Jinja2Templates(directory=settings.APP_PATH / 'templates') 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( async def login(
request: Request 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( async def login(
db: AsyncSession = Depends(get_async_db), db: AsyncSession = Depends(get_async_db),
form_data: LoginForm = Depends() form_data: LoginForm = Depends()