Added ability for user to change their bio

This commit is contained in:
2025-02-16 10:44:04 +11:00
parent 42ea74fd63
commit 07453b0f02
6 changed files with 170 additions and 8 deletions

View File

@@ -49,7 +49,8 @@ func HandleChangeUsername(
return
}
if !unique {
account.ChangeUsername("Usename is taken", newUsername).Render(r.Context(), w)
account.ChangeUsername("Username is taken", newUsername).
Render(r.Context(), w)
return
}
user := contexts.GetUser(r.Context())
@@ -59,7 +60,34 @@ func HandleChangeUsername(
w.WriteHeader(http.StatusInternalServerError)
return
}
w.Header().Set("HX-Redirect", "/account")
w.Header().Set("HX-Refresh", "true")
},
)
}
// Handles a request to change the users bio
func HandleChangeBio(
logger *zerolog.Logger,
conn *sql.DB,
) http.Handler {
return http.HandlerFunc(
func(w http.ResponseWriter, r *http.Request) {
r.ParseForm()
newBio := r.FormValue("bio")
leng := len([]rune(newBio))
if leng > 128 {
account.ChangeBio("Bio limited to 128 characters", newBio).
Render(r.Context(), w)
return
}
user := contexts.GetUser(r.Context())
err := user.ChangeBio(conn, newBio)
if err != nil {
logger.Error().Err(err).Msg("Error updating bio")
w.WriteHeader(http.StatusInternalServerError)
return
}
w.Header().Set("HX-Refresh", "true")
},
)
}