35 lines
674 B
Go
35 lines
674 B
Go
package main
|
|
|
|
import (
|
|
"github.com/labstack/echo"
|
|
"net/http"
|
|
)
|
|
|
|
func addKonfi(c echo.Context) error {
|
|
//Datenbankverbindung aufbauen
|
|
db := DBinit()
|
|
|
|
rw := c.Response()
|
|
r := c.Request()
|
|
|
|
//Session init
|
|
sess := GlobalSessions.SessionStart(rw, r)
|
|
logged := sess.Get("login")
|
|
|
|
//Wenn das password stimmt
|
|
if logged != nil{
|
|
kofi := new(Kofi)
|
|
kofi.Name = c.FormValue("name")
|
|
kofi.Gemeinde = c.FormValue("gemeinde")
|
|
|
|
//Aktuelle Coins holen
|
|
_, err := db.Insert(kofi)
|
|
if err == nil {
|
|
return c.JSON(http.StatusOK, Message{"success"})
|
|
}
|
|
return c.JSON(http.StatusOK, Message{"Error."})
|
|
} else {
|
|
return c.JSON(http.StatusOK, Message{"Login first."})
|
|
}
|
|
}
|