mirror of
https://github.com/m1k1o/neko.git
synced 2026-11-03 08:21:50 -06:00
fix(api): update profile handling to ensure only the name field is modified.
This commit is contained in:
@@ -84,15 +84,25 @@ func (api *ApiManagerCtx) Whoami(w http.ResponseWriter, r *http.Request) error {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: Remove when legacy mode is removed as all sessions must be synced with their providers.
|
||||||
func (api *ApiManagerCtx) UpdateProfile(w http.ResponseWriter, r *http.Request) error {
|
func (api *ApiManagerCtx) UpdateProfile(w http.ResponseWriter, r *http.Request) error {
|
||||||
session, _ := auth.GetSession(r)
|
session, _ := auth.GetSession(r)
|
||||||
|
|
||||||
data := session.Profile()
|
profile := session.Profile()
|
||||||
if err := utils.HttpJsonRequest(w, r, &data); err != nil {
|
if !profile.IsAdmin {
|
||||||
|
// Name is the only updatable field in the profile for non-admins
|
||||||
|
var payload types.MemberProfile
|
||||||
|
if err := utils.HttpJsonRequest(w, r, &payload); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
profile.Name = payload.Name
|
||||||
|
} else {
|
||||||
|
if err := utils.HttpJsonRequest(w, r, &profile); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
err := api.sessions.Update(session.ID(), data)
|
err := api.sessions.Update(session.ID(), profile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if errors.Is(err, types.ErrSessionNotFound) {
|
if errors.Is(err, types.ErrSessionNotFound) {
|
||||||
return utils.HttpBadRequest("session does not exist")
|
return utils.HttpBadRequest("session does not exist")
|
||||||
|
|||||||
Reference in New Issue
Block a user