Konfis manuell hinzufügen eingebaut

This commit is contained in:
konrad 2017-06-17 18:20:03 +02:00 committed by konrad
parent 67ec04cf09
commit e4d8e84f0f
6 changed files with 40 additions and 3 deletions

View File

@ -0,0 +1,34 @@
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."})
}
}

View File

@ -76,11 +76,13 @@ $('.ui.kofiadd.modal')
.modal({
duration: 200,
onApprove : function() {
$('.loader').addClass('active');
$.ajax({
url: '/add',
method: 'POST',
data: 'name=' + $('#name').val() + '&gemeinde=' + $('#gemeinde').val(),
success: function (msg) {
$('.loader').removeClass('active');
console.log(msg);
if (msg.Message == 'success') {

View File

@ -21,7 +21,7 @@ func deleteKonfi(c echo.Context) error {
if logged != nil{
id, _ := strconv.Atoi(c.FormValue("id"))
//Aktuelle Coins holen
//Löschen
_, err := db.Id(id).Delete(&Kofi{})
if err == nil {
return c.JSON(http.StatusOK, Message{"success"})

View File

@ -45,6 +45,7 @@ func main() {
e.POST("/login", login)
e.POST("/update", update)
e.POST("/delete", deleteKonfi)
e.POST("/add", addKonfi)
//Template
t := &Template{

View File

@ -11,7 +11,7 @@
{{if .Loggedin}}
<body>
<div style="width: 98%; margin: 0 auto;">
<h1>Kasino Admin</h1>
<h1>Kasino Admin <div class="ui inline loader"></div></h1>
<p>
<div class="ui right labeled icon addKofi button green">
<i class="right plus icon"></i>

View File

@ -3,7 +3,7 @@ package main
import "log"
type Kofi struct {
ID int `xorm:"pk"`
ID int `xorm:"pk autoincr"`
Name string
Gemeinde string
KCoins int