mirror of
https://github.com/m1k1o/neko.git
synced 2025-08-03 08:50:13 +02:00
update profile on join.
This commit is contained in:
parent
0f1f218694
commit
679157ef6d
5 changed files with 73 additions and 8 deletions
|
@ -46,6 +46,7 @@ func (api *ApiManagerCtx) Route(r types.Router) {
|
|||
|
||||
r.Post("/logout", api.Logout)
|
||||
r.Get("/whoami", api.Whoami)
|
||||
r.Post("/profile", api.UpdateProfile)
|
||||
|
||||
sessionsHandler := sessions.New(api.sessions)
|
||||
r.Route("/sessions", sessionsHandler.Route)
|
||||
|
|
|
@ -83,3 +83,23 @@ func (api *ApiManagerCtx) Whoami(w http.ResponseWriter, r *http.Request) error {
|
|||
State: session.State(),
|
||||
})
|
||||
}
|
||||
|
||||
func (api *ApiManagerCtx) UpdateProfile(w http.ResponseWriter, r *http.Request) error {
|
||||
session, _ := auth.GetSession(r)
|
||||
|
||||
data := &types.MemberProfile{}
|
||||
if err := utils.HttpJsonRequest(w, r, data); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err := api.sessions.Update(session.ID(), *data)
|
||||
if err != nil {
|
||||
if errors.Is(err, types.ErrSessionNotFound) {
|
||||
return utils.HttpBadRequest("session does not exist")
|
||||
} else {
|
||||
return utils.HttpInternalServerError().WithInternalErr(err)
|
||||
}
|
||||
}
|
||||
|
||||
return utils.HttpSuccess(w, true)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue