mirror of
https://github.com/gabehf/Koito.git
synced 2026-03-13 09:30:27 -07:00
fix: use correct form body for login and user update
This commit is contained in:
parent
b1bac4feb5
commit
ef064cd9bd
2 changed files with 35 additions and 8 deletions
|
|
@ -85,8 +85,13 @@ function mergeArtists(from: number, to: number, replaceImage: boolean): Promise<
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
function login(username: string, password: string, remember: boolean): Promise<Response> {
|
function login(username: string, password: string, remember: boolean): Promise<Response> {
|
||||||
return fetch(`/apis/web/v1/login?username=${username}&password=${password}&remember_me=${remember}`, {
|
const form = new URLSearchParams
|
||||||
|
form.append('username', username)
|
||||||
|
form.append('password', password)
|
||||||
|
form.append('remember_me', String(remember))
|
||||||
|
return fetch(`/apis/web/v1/login`, {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
|
body: form,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
function logout(): Promise<Response> {
|
function logout(): Promise<Response> {
|
||||||
|
|
@ -99,8 +104,11 @@ function getApiKeys(): Promise<ApiKey[]> {
|
||||||
return fetch(`/apis/web/v1/user/apikeys`).then((r) => r.json() as Promise<ApiKey[]>)
|
return fetch(`/apis/web/v1/user/apikeys`).then((r) => r.json() as Promise<ApiKey[]>)
|
||||||
}
|
}
|
||||||
const createApiKey = async (label: string): Promise<ApiKey> => {
|
const createApiKey = async (label: string): Promise<ApiKey> => {
|
||||||
const r = await fetch(`/apis/web/v1/user/apikeys?label=${label}`, {
|
const form = new URLSearchParams
|
||||||
method: "POST"
|
form.append('label', label)
|
||||||
|
const r = await fetch(`/apis/web/v1/user/apikeys`, {
|
||||||
|
method: "POST",
|
||||||
|
body: form,
|
||||||
});
|
});
|
||||||
if (!r.ok) {
|
if (!r.ok) {
|
||||||
let errorMessage = `error: ${r.status}`;
|
let errorMessage = `error: ${r.status}`;
|
||||||
|
|
@ -134,8 +142,12 @@ function deleteItem(itemType: string, id: number): Promise<Response> {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
function updateUser(username: string, password: string) {
|
function updateUser(username: string, password: string) {
|
||||||
return fetch(`/apis/web/v1/user?username=${username}&password=${password}`, {
|
const form = new URLSearchParams
|
||||||
method: "PATCH"
|
form.append('username', username)
|
||||||
|
form.append('password', password)
|
||||||
|
return fetch(`/apis/web/v1/user`, {
|
||||||
|
method: "PATCH",
|
||||||
|
body: form,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
function getAliases(type: string, id: number): Promise<Alias[]> {
|
function getAliases(type: string, id: number): Promise<Alias[]> {
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,12 @@ func LoginHandler(store db.DB) http.HandlerFunc {
|
||||||
|
|
||||||
l.Debug().Msg("LoginHandler: Received login request")
|
l.Debug().Msg("LoginHandler: Received login request")
|
||||||
|
|
||||||
r.ParseForm()
|
err := r.ParseForm()
|
||||||
|
if err != nil {
|
||||||
|
l.Debug().Msg("LoginHandler: Failed to parse request form")
|
||||||
|
utils.WriteError(w, "failed to parse request", http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
username := r.FormValue("username")
|
username := r.FormValue("username")
|
||||||
password := r.FormValue("password")
|
password := r.FormValue("password")
|
||||||
if username == "" || password == "" {
|
if username == "" || password == "" {
|
||||||
|
|
@ -149,12 +154,22 @@ func UpdateUserHandler(store db.DB) http.HandlerFunc {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
r.ParseForm()
|
err := r.ParseForm()
|
||||||
|
if err != nil {
|
||||||
|
l.Err(err).Msg("UpdateUserHandler: Failed to parse request form")
|
||||||
|
utils.WriteError(w, "failed to parse request", http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
username := r.FormValue("username")
|
username := r.FormValue("username")
|
||||||
password := r.FormValue("password")
|
password := r.FormValue("password")
|
||||||
|
|
||||||
|
if username == "" && password == "" {
|
||||||
|
l.Debug().Msg("UpdateUserHandler: No parameters were recieved")
|
||||||
|
utils.WriteError(w, "all parameters missing", http.StatusBadRequest)
|
||||||
|
return
|
||||||
|
}
|
||||||
l.Debug().Msgf("UpdateUserHandler: Updating user with ID %d", u.ID)
|
l.Debug().Msgf("UpdateUserHandler: Updating user with ID %d", u.ID)
|
||||||
err := store.UpdateUser(ctx, db.UpdateUserOpts{
|
err = store.UpdateUser(ctx, db.UpdateUserOpts{
|
||||||
ID: u.ID,
|
ID: u.ID,
|
||||||
Username: username,
|
Username: username,
|
||||||
Password: password,
|
Password: password,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue