Compare commits

...

3 Commits

Author SHA1 Message Date
Teajey 8a1fef487a
fix: only trim group name 2024-12-29 20:42:59 +13:00
Teajey ffd3890584
fix: check if session exists for see other 2024-12-29 20:41:42 +13:00
Teajey dd952a1f39
fix: check if flash field exists 2024-12-29 20:41:21 +13:00
3 changed files with 13 additions and 7 deletions

View File

@ -80,7 +80,7 @@ func GetAllGroups() ([]Group, error) {
} }
func CreateGroup(name string, reference string) (*Group, error) { func CreateGroup(name string, reference string) (*Group, error) {
name = normalize.Name(name) name = normalize.Trim(name)
stmt := "INSERT INTO [group] (name, reference) VALUES (?, ?)" stmt := "INSERT INTO [group] (name, reference) VALUES (?, ?)"
result, err := database.Exec(stmt, name, reference) result, err := database.Exec(stmt, name, reference)
if err != nil { if err != nil {

View File

@ -29,11 +29,13 @@ func (res *Response) Write(w http.ResponseWriter, r *http.Request) error {
if res.SeeOther != "" { if res.SeeOther != "" {
http.Redirect(w, r, res.SeeOther, http.StatusSeeOther) http.Redirect(w, r, res.SeeOther, http.StatusSeeOther)
flash := res.Session.FlashPeek() if res.Session != nil {
if flash != nil { flash := res.Session.FlashPeek()
err := json.NewEncoder(w).Encode(flash) if flash != nil {
if err != nil { err := json.NewEncoder(w).Encode(flash)
return err if err != nil {
return err
}
} }
} }
return nil return nil

View File

@ -18,7 +18,11 @@ func (s *Session) FlashGet() any {
} }
func (s *Session) FlashPeek() any { func (s *Session) FlashPeek() any {
list, _ := s.inner.Values["_flash"].([]any) flash, ok := s.inner.Values["_flash"]
if !ok {
return nil
}
list := flash.([]any)
if len(list) < 1 { if len(list) < 1 {
return nil return nil
} else { } else {