mirror of
https://github.com/hpware/news-analyze.git
synced 2025-06-23 13:04:23 +00:00
Update sendUserChanges to make the settings system work.
This commit is contained in:
parent
ad0f13a1a2
commit
85c3332c76
3 changed files with 23 additions and 16 deletions
|
@ -100,23 +100,24 @@ const checkValidApiKey = () => {
|
||||||
const showDeleteDialog = ref(false);
|
const showDeleteDialog = ref(false);
|
||||||
const showLogoutDialog = ref(false);
|
const showLogoutDialog = ref(false);
|
||||||
const confirmDelete = async () => {
|
const confirmDelete = async () => {
|
||||||
|
showDeleteDialog.value = false;
|
||||||
await deleteAccount();
|
await deleteAccount();
|
||||||
await validateUserInfo();
|
await validateUserInfo();
|
||||||
showDeleteDialog.value = false;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const deleteAccount = async () => {
|
const deleteAccount = async () => {
|
||||||
const req = await fetch("/api/user/sendUserChanges", {
|
const req = await fetch("/api/user/sendUserChanges", {
|
||||||
method: "DELETE",
|
method: "DELETE",
|
||||||
});
|
});
|
||||||
const res = await res.json();
|
const res = await req.json();
|
||||||
console.log(res);
|
console.log(res);
|
||||||
};
|
};
|
||||||
|
|
||||||
const submitChangeAction = async (action: string) => {
|
const submitChangeAction = async (action: string) => {
|
||||||
|
//const allowedColumns = ["firstname", "email"];
|
||||||
const actions = [
|
const actions = [
|
||||||
{ name: "NAME", sendValue: enterFirstName.value },
|
{ name: "NAME", SQLSystem: "firstname", sendValue: enterFirstName.value },
|
||||||
{ name: "USER_EMAIL", sendValue: enteruseremail.value },
|
{ name: "USER_EMAIL", SQLSystem: "email", sendValue: enteruseremail.value },
|
||||||
];
|
];
|
||||||
|
|
||||||
const actionMatch = actions.find((a) => a.name === action);
|
const actionMatch = actions.find((a) => a.name === action);
|
||||||
|
@ -131,7 +132,7 @@ const submitChangeAction = async (action: string) => {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
},
|
},
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
action: actionMatch.name,
|
action: actionMatch.SQLSystem,
|
||||||
value: actionMatch.sendValue,
|
value: actionMatch.sendValue,
|
||||||
jsonValue: "",
|
jsonValue: "",
|
||||||
}),
|
}),
|
||||||
|
|
|
@ -81,6 +81,9 @@ export default defineEventHandler(async (event) => {
|
||||||
VALUES (${fetchUserInfoAgain[0].username}, ${newToken})
|
VALUES (${fetchUserInfoAgain[0].username}, ${newToken})
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
const getUserFirstName = await sql`
|
||||||
|
select * from user_other_data`;
|
||||||
|
|
||||||
setCookie(event, "token", newToken);
|
setCookie(event, "token", newToken);
|
||||||
return {
|
return {
|
||||||
user: fetchUserInfoAgain,
|
user: fetchUserInfoAgain,
|
||||||
|
|
|
@ -12,23 +12,26 @@ export default defineEventHandler(async (event) => {
|
||||||
const body = await readBody(event);
|
const body = await readBody(event);
|
||||||
if (body.jsonValue.length === 0) {
|
if (body.jsonValue.length === 0) {
|
||||||
const clearBadDataRegex = /[@-_.+a-zA-Z0-9]{2,}/;
|
const clearBadDataRegex = /[@-_.+a-zA-Z0-9]{2,}/;
|
||||||
let allowed = true;
|
|
||||||
if (body.value.match()) {
|
|
||||||
allowed = false;
|
|
||||||
}
|
|
||||||
// Use Static values for now.
|
// Use Static values for now.
|
||||||
const requestChange = "groq_api_key";
|
const requestChange = body.name;
|
||||||
const apiKeyqq = body.value.match(clearBadDataRegex);
|
const apiKeyqq = body.value.match(clearBadDataRegex);
|
||||||
const allowedColumns = ["groq_api_key", "another_column_name"];
|
const allowedColumns = ["firstname", "email"];
|
||||||
|
|
||||||
if (!allowedColumns.includes(requestChange)) {
|
if (!allowedColumns.includes(requestChange)) {
|
||||||
throw new Error("Invalid column name provided");
|
return {
|
||||||
|
error: "ERR_NOT_ALLOWED",
|
||||||
|
};
|
||||||
|
} else if (requestChange === "name") {
|
||||||
|
const sqlC = await sql`
|
||||||
|
UPDATE users SET firstname = ${apiKeyqq[0]}
|
||||||
|
WHERE username = ${token.user}`;
|
||||||
|
return {
|
||||||
|
sqlC: sqlC,
|
||||||
|
success: true,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
const sqlC = await sql.unsafe(
|
const sqlC = await sql.unsafe(
|
||||||
`
|
`UPDATE user_other_data SET ${requestChange} = $1 WHERE username = $2`,
|
||||||
UPDATE user_other_data SET ${requestChange} = $1
|
|
||||||
WHERE username = $2`,
|
|
||||||
[apiKeyqq[0], token.user],
|
[apiKeyqq[0], token.user],
|
||||||
);
|
);
|
||||||
return {
|
return {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue