user information
This commit is contained in:
@@ -125,9 +125,9 @@ async def reset_user(row:pydentic.UserReset):
|
||||
password.send_password(new_row)
|
||||
user = await db.reset_user(new_row)
|
||||
return user
|
||||
@api.get("/admin/{email}")
|
||||
async def admin_stuff(
|
||||
email: str,
|
||||
user = Depends(permissions.check_permission("can_delete"))
|
||||
):
|
||||
return {"msg": f"Добро пожаловать, {user.email}"}
|
||||
@api.get("/me", response_model=pydentic.UserOut)
|
||||
async def read_current_user(current_user=Depends(JWT.current_user)):
|
||||
user = await db.get_user_by_email(current_user)
|
||||
if not user:
|
||||
raise HTTPException(status_code=404, detail="User not found")
|
||||
return user
|
||||
@@ -12,12 +12,16 @@
|
||||
<form id="logoutForm">
|
||||
<button type="submit">Logout</button>
|
||||
</form>
|
||||
<h2>data</h2>
|
||||
<form action="#" method="POST">
|
||||
<p>Data</p>
|
||||
<h2 id ="Account_Email">data</h2>
|
||||
<form>
|
||||
<p id = "Account_Description">Data</p>
|
||||
<p id = "Account_Activated">Data</p>
|
||||
<p id = "Account_Created">Data</p>
|
||||
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
<script src="js.js"></script>
|
||||
<script type="module" src="profile.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
45
server/front/main/profile.js
Normal file
45
server/front/main/profile.js
Normal file
@@ -0,0 +1,45 @@
|
||||
async function loadUser() {
|
||||
try {
|
||||
const token = getToken();
|
||||
const response = await fetch("http://localhost:8000/me", {
|
||||
method: "GET",
|
||||
headers: {
|
||||
"Authorization": `Bearer ${token}`
|
||||
}
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error("Unauthorized");
|
||||
}
|
||||
|
||||
const data = await response.json();
|
||||
console.log("User info:", data);
|
||||
show_data(data)
|
||||
} catch (err) {
|
||||
showError(["Connection error"]);
|
||||
}
|
||||
|
||||
}
|
||||
loadUser();
|
||||
function show_data(data) {
|
||||
const emailElem = document.getElementById('Account_Email');
|
||||
if (emailElem) {
|
||||
emailElem.textContent = data.email;
|
||||
}
|
||||
|
||||
const descElem = document.getElementById('Account_Description');
|
||||
if (descElem) {
|
||||
descElem.textContent = data.description || "—";
|
||||
}
|
||||
|
||||
const activatedElem = document.getElementById('Account_Activated');
|
||||
if (activatedElem) {
|
||||
activatedElem.textContent = `Active: ${data.activated ? "Yes" : "No"}`;
|
||||
}
|
||||
|
||||
const createdElem = document.getElementById('Account_Created');
|
||||
if (createdElem) {
|
||||
// красиво обрезать дату
|
||||
createdElem.textContent = new Date(data.created_at).toLocaleString();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user