fix: request current password when deleting users
This commit is contained in:
parent
94ec786d34
commit
3aa5d91463
@ -4,6 +4,10 @@ export function get() {
|
|||||||
return fetchJSON<ISettings>(`/api/settings`, {});
|
return fetchJSON<ISettings>(`/api/settings`, {});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getAuthMethod() {
|
||||||
|
return fetchJSON<{ authMethod: string }>(`/api/settings/auth-method`, {});
|
||||||
|
}
|
||||||
|
|
||||||
export async function update(settings: ISettings) {
|
export async function update(settings: ISettings) {
|
||||||
await fetchURL(`/api/settings`, {
|
await fetchURL(`/api/settings`, {
|
||||||
method: "PUT",
|
method: "PUT",
|
||||||
|
|||||||
@ -42,8 +42,15 @@ export async function update(
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function remove(id: number) {
|
export async function remove(
|
||||||
|
id: number,
|
||||||
|
currentPassword: string | null = null
|
||||||
|
) {
|
||||||
await fetchURL(`/api/users/${id}`, {
|
await fetchURL(`/api/users/${id}`, {
|
||||||
method: "DELETE",
|
method: "DELETE",
|
||||||
|
body: JSON.stringify({
|
||||||
|
what: "user",
|
||||||
|
...(currentPassword != null ? { current_password: currentPassword } : {}),
|
||||||
|
}),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@ -142,7 +142,7 @@ onMounted(async () => {
|
|||||||
dateFormat.value = authStore.user.dateFormat;
|
dateFormat.value = authStore.user.dateFormat;
|
||||||
aceEditorTheme.value = authStore.user.aceEditorTheme;
|
aceEditorTheme.value = authStore.user.aceEditorTheme;
|
||||||
layoutStore.loading = false;
|
layoutStore.loading = false;
|
||||||
const { authMethod } = await settings.get();
|
const { authMethod } = await settings.getAuthMethod();
|
||||||
isCurrentPasswordRequired.value = authMethod == "json";
|
isCurrentPasswordRequired.value = authMethod == "json";
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@ -146,7 +146,7 @@ const deleteUser = async (e: Event) => {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
await api.remove(user.value.id);
|
await api.remove(user.value.id, currentPassword.value);
|
||||||
router.push({ path: "/settings/users" });
|
router.push({ path: "/settings/users" });
|
||||||
$showSuccess(t("settings.userDeleted"));
|
$showSuccess(t("settings.userDeleted"));
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
|||||||
@ -80,6 +80,7 @@ func NewHandler(
|
|||||||
api.PathPrefix("/share").Handler(monkey(shareDeleteHandler, "/api/share")).Methods("DELETE")
|
api.PathPrefix("/share").Handler(monkey(shareDeleteHandler, "/api/share")).Methods("DELETE")
|
||||||
|
|
||||||
api.Handle("/settings", monkey(settingsGetHandler, "")).Methods("GET")
|
api.Handle("/settings", monkey(settingsGetHandler, "")).Methods("GET")
|
||||||
|
api.Handle("/settings/auth-method", monkey(authMethodGetHandler, "")).Methods("GET")
|
||||||
api.Handle("/settings", monkey(settingsPutHandler, "")).Methods("PUT")
|
api.Handle("/settings", monkey(settingsPutHandler, "")).Methods("PUT")
|
||||||
|
|
||||||
api.PathPrefix("/raw").Handler(monkey(rawHandler, "/api/raw")).Methods("GET")
|
api.PathPrefix("/raw").Handler(monkey(rawHandler, "/api/raw")).Methods("GET")
|
||||||
|
|||||||
@ -42,6 +42,14 @@ var settingsGetHandler = withAdmin(func(w http.ResponseWriter, r *http.Request,
|
|||||||
return renderJSON(w, r, data)
|
return renderJSON(w, r, data)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
var authMethodGetHandler = func(w http.ResponseWriter, r *http.Request, d *data) (int, error) {
|
||||||
|
data := &settingsData{
|
||||||
|
AuthMethod: d.settings.AuthMethod,
|
||||||
|
}
|
||||||
|
|
||||||
|
return renderJSON(w, r, data)
|
||||||
|
}
|
||||||
|
|
||||||
var settingsPutHandler = withAdmin(func(_ http.ResponseWriter, r *http.Request, d *data) (int, error) {
|
var settingsPutHandler = withAdmin(func(_ http.ResponseWriter, r *http.Request, d *data) (int, error) {
|
||||||
req := &settingsData{}
|
req := &settingsData{}
|
||||||
err := json.NewDecoder(r.Body).Decode(req)
|
err := json.NewDecoder(r.Body).Decode(req)
|
||||||
|
|||||||
@ -103,8 +103,19 @@ var userGetHandler = withSelfOrAdmin(func(w http.ResponseWriter, r *http.Request
|
|||||||
return renderJSON(w, r, u)
|
return renderJSON(w, r, u)
|
||||||
})
|
})
|
||||||
|
|
||||||
var userDeleteHandler = withSelfOrAdmin(func(_ http.ResponseWriter, _ *http.Request, d *data) (int, error) {
|
var userDeleteHandler = withSelfOrAdmin(func(w http.ResponseWriter, r *http.Request, d *data) (int, error) {
|
||||||
err := d.store.Users.Delete(d.raw.(uint))
|
req, err := getUser(w, r)
|
||||||
|
if err != nil {
|
||||||
|
return http.StatusBadRequest, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if d.settings.AuthMethod == auth.MethodJSONAuth {
|
||||||
|
if !users.CheckPwd(req.CurrentPassword, d.user.Password) {
|
||||||
|
return http.StatusBadRequest, fberrors.ErrCurrentPasswordIncorrect
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
err = d.store.Users.Delete(d.raw.(uint))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errToStatus(err), err
|
return errToStatus(err), err
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user