Compare commits
2 Commits
3f0ddf7138
...
08fb20d7be
Author | SHA1 | Date | |
---|---|---|---|
08fb20d7be | |||
6547b6ac85 |
1
.gitignore
vendored
1
.gitignore
vendored
@ -6,3 +6,4 @@ cred.txt
|
|||||||
dist/
|
dist/
|
||||||
.air.toml
|
.air.toml
|
||||||
tmp/
|
tmp/
|
||||||
|
invoices/
|
||||||
|
24
Makefile
24
Makefile
@ -5,7 +5,7 @@ API_PORT=4001
|
|||||||
DSN=vinchent:secret@tcp(localhost:3306)/widgets?parseTime=true&tls=false
|
DSN=vinchent:secret@tcp(localhost:3306)/widgets?parseTime=true&tls=false
|
||||||
|
|
||||||
## build: builds all binaries
|
## build: builds all binaries
|
||||||
build: clean build_front build_back
|
build: clean build_front build_back build_invoice
|
||||||
@printf "All binaries built!\n"
|
@printf "All binaries built!\n"
|
||||||
|
|
||||||
## clean: cleans all binaries and runs go clean
|
## clean: cleans all binaries and runs go clean
|
||||||
@ -15,6 +15,12 @@ clean:
|
|||||||
@go clean
|
@go clean
|
||||||
@echo "Cleaned!"
|
@echo "Cleaned!"
|
||||||
|
|
||||||
|
## build_invoice: builds the invoice microservice
|
||||||
|
build_invoice:
|
||||||
|
@echo "Building invoice microservice..."
|
||||||
|
@go build -o dist/invoice ./cmd/micro/invoice
|
||||||
|
@echo "Invoice microservice built!"
|
||||||
|
|
||||||
## build_front: builds the front end
|
## build_front: builds the front end
|
||||||
build_front:
|
build_front:
|
||||||
@echo "Building front end..."
|
@echo "Building front end..."
|
||||||
@ -28,7 +34,13 @@ build_back:
|
|||||||
@echo "Back end built!"
|
@echo "Back end built!"
|
||||||
|
|
||||||
## start: starts front and back end
|
## start: starts front and back end
|
||||||
start: start_front start_back
|
start: start_front start_back start_invoice
|
||||||
|
|
||||||
|
## start_invoice: starts the invoice microservice
|
||||||
|
start_invoice: build_invoice
|
||||||
|
@echo "Starting the invoice microservice..."
|
||||||
|
@./dist/invoice &
|
||||||
|
@echo "invoice microservice running!"
|
||||||
|
|
||||||
## start_front: starts the front end
|
## start_front: starts the front end
|
||||||
start_front: build_front
|
start_front: build_front
|
||||||
@ -43,9 +55,15 @@ start_back: build_back
|
|||||||
@echo "Back end running!"
|
@echo "Back end running!"
|
||||||
|
|
||||||
## stop: stops the front and back end
|
## stop: stops the front and back end
|
||||||
stop: stop_front stop_back
|
stop: stop_front stop_back stop_invoice
|
||||||
@echo "All applications stopped"
|
@echo "All applications stopped"
|
||||||
|
|
||||||
|
## stop_invoice: stops the invoice microservice
|
||||||
|
stop_invoice:
|
||||||
|
@echo "Stopping the invoice microservice..."
|
||||||
|
@-pkill -SIGTERM -f "invoice"
|
||||||
|
@echo "Stopped invoice microservice"
|
||||||
|
|
||||||
## stop_front: stops the front end
|
## stop_front: stops the front end
|
||||||
stop_front:
|
stop_front:
|
||||||
@echo "Stopping the front end..."
|
@echo "Stopping the front end..."
|
||||||
|
@ -33,7 +33,7 @@ type stripePayload struct {
|
|||||||
LastName string `json:"last_name"`
|
LastName string `json:"last_name"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type jsonResponse struct {
|
type JSONResponse struct {
|
||||||
OK bool `json:"ok"`
|
OK bool `json:"ok"`
|
||||||
Message string `json:"message,omitempty"`
|
Message string `json:"message,omitempty"`
|
||||||
Content string `json:"content,omitempty"`
|
Content string `json:"content,omitempty"`
|
||||||
@ -63,7 +63,7 @@ func (app *application) GetPaymentIntent(w http.ResponseWriter, r *http.Request)
|
|||||||
|
|
||||||
pi, msg, err := card.Charge(payload.Currency, amount)
|
pi, msg, err := card.Charge(payload.Currency, amount)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
j := jsonResponse{
|
j := JSONResponse{
|
||||||
OK: false,
|
OK: false,
|
||||||
Message: msg,
|
Message: msg,
|
||||||
Content: "",
|
Content: "",
|
||||||
@ -190,7 +190,7 @@ func (app *application) CreateCustomerAndSubscribeToPlan(w http.ResponseWriter,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
resp := jsonResponse{
|
resp := JSONResponse{
|
||||||
OK: okay,
|
OK: okay,
|
||||||
Message: txnMsg,
|
Message: txnMsg,
|
||||||
}
|
}
|
||||||
@ -340,7 +340,7 @@ func (app *application) CheckAuthentication(w http.ResponseWriter, r *http.Reque
|
|||||||
}
|
}
|
||||||
|
|
||||||
// valid user
|
// valid user
|
||||||
var payload jsonResponse
|
var payload JSONResponse
|
||||||
payload.OK = true
|
payload.OK = true
|
||||||
payload.Message = fmt.Sprintf("authenticated user %s", user.Email)
|
payload.Message = fmt.Sprintf("authenticated user %s", user.Email)
|
||||||
app.writeJSON(w, http.StatusOK, payload)
|
app.writeJSON(w, http.StatusOK, payload)
|
||||||
@ -423,7 +423,7 @@ func (app *application) SendPasswordResetEmail(w http.ResponseWriter, r *http.Re
|
|||||||
// verify that email exists
|
// verify that email exists
|
||||||
_, err = app.DB.GetUserByEmail(payload.Email)
|
_, err = app.DB.GetUserByEmail(payload.Email)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
resp := jsonResponse{
|
resp := JSONResponse{
|
||||||
OK: false,
|
OK: false,
|
||||||
Message: "No matching email found on our system",
|
Message: "No matching email found on our system",
|
||||||
}
|
}
|
||||||
@ -458,7 +458,7 @@ func (app *application) SendPasswordResetEmail(w http.ResponseWriter, r *http.Re
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
resp := jsonResponse{
|
resp := JSONResponse{
|
||||||
OK: true,
|
OK: true,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -509,7 +509,7 @@ func (app *application) ResetPassword(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
resp := jsonResponse{
|
resp := JSONResponse{
|
||||||
OK: true,
|
OK: true,
|
||||||
Message: "Password reset.",
|
Message: "Password reset.",
|
||||||
}
|
}
|
||||||
@ -649,7 +649,7 @@ func (app *application) RefundCharge(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
var resp jsonResponse
|
var resp JSONResponse
|
||||||
resp.OK = true
|
resp.OK = true
|
||||||
resp.Message = "Charge refunded"
|
resp.Message = "Charge refunded"
|
||||||
|
|
||||||
@ -696,7 +696,7 @@ func (app *application) CancelSubscription(w http.ResponseWriter, r *http.Reques
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
var resp jsonResponse
|
var resp JSONResponse
|
||||||
resp.OK = true
|
resp.OK = true
|
||||||
resp.Message = "Subscription canceled"
|
resp.Message = "Subscription canceled"
|
||||||
|
|
||||||
@ -775,7 +775,7 @@ func (app *application) EditUser(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var resp jsonResponse
|
var resp JSONResponse
|
||||||
resp.OK = true
|
resp.OK = true
|
||||||
app.writeJSON(w, http.StatusOK, resp)
|
app.writeJSON(w, http.StatusOK, resp)
|
||||||
}
|
}
|
||||||
@ -789,7 +789,7 @@ func (app *application) DeleteUser(w http.ResponseWriter, r *http.Request) {
|
|||||||
app.badRequest(w, r, err)
|
app.badRequest(w, r, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
var resp jsonResponse
|
var resp JSONResponse
|
||||||
resp.OK = true
|
resp.OK = true
|
||||||
app.writeJSON(w, http.StatusOK, resp)
|
app.writeJSON(w, http.StatusOK, resp)
|
||||||
}
|
}
|
||||||
|
86
cmd/micro/invoice/helpers.go
Normal file
86
cmd/micro/invoice/helpers.go
Normal file
@ -0,0 +1,86 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
|
"io"
|
||||||
|
"net/http"
|
||||||
|
"os"
|
||||||
|
)
|
||||||
|
|
||||||
|
type JSONResponse struct {
|
||||||
|
OK bool `json:"ok"`
|
||||||
|
Message string `json:"message,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (app *application) readJSON(w http.ResponseWriter, r *http.Request, data interface{}) error {
|
||||||
|
maxBytes := 1048576
|
||||||
|
|
||||||
|
r.Body = http.MaxBytesReader(w, r.Body, int64(maxBytes))
|
||||||
|
|
||||||
|
dec := json.NewDecoder(r.Body)
|
||||||
|
err := dec.Decode(data)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Make sure there is only one entry.
|
||||||
|
err = dec.Decode(&struct{}{})
|
||||||
|
if err != io.EOF {
|
||||||
|
return errors.New("body must only have a single JSON value")
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// writeJSON writes arbitrary data out as JSON
|
||||||
|
func (app *application) writeJSON(
|
||||||
|
w http.ResponseWriter,
|
||||||
|
status int, data interface{},
|
||||||
|
headers ...http.Header,
|
||||||
|
) error {
|
||||||
|
out, err := json.MarshalIndent(data, "", "\t")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(headers) > 0 {
|
||||||
|
for k, v := range headers[0] {
|
||||||
|
w.Header()[k] = v
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
w.Header().Set("Content-Type", "application/json")
|
||||||
|
w.WriteHeader(status)
|
||||||
|
w.Write(out)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (app *application) badRequest(w http.ResponseWriter, r *http.Request, err error) error {
|
||||||
|
var payload JSONResponse
|
||||||
|
|
||||||
|
payload.OK = false
|
||||||
|
payload.Message = err.Error()
|
||||||
|
|
||||||
|
out, err := json.MarshalIndent(payload, "", "\t")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
w.Header().Set("Content-Type", "application/json")
|
||||||
|
w.WriteHeader(http.StatusBadGateway)
|
||||||
|
w.Write(out)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (app *application) CreateDirIfNotExist(path string) error {
|
||||||
|
const mode = 0755
|
||||||
|
if _, err := os.Stat(path); os.IsNotExist(err) {
|
||||||
|
err := os.Mkdir(path, mode)
|
||||||
|
if err != nil {
|
||||||
|
app.errorLog.Println(err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
145
cmd/micro/invoice/invoice-handlers.go
Normal file
145
cmd/micro/invoice/invoice-handlers.go
Normal file
@ -0,0 +1,145 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"net/http"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/phpdave11/gofpdf"
|
||||||
|
"github.com/phpdave11/gofpdf/contrib/gofpdi"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Order struct {
|
||||||
|
ID int `json:"id"`
|
||||||
|
Quantity int `json:"quantity"`
|
||||||
|
Amount int `json:"amount"`
|
||||||
|
Product string `json:"product"`
|
||||||
|
FirstName string `json:"first_name"`
|
||||||
|
LastName string `json:"last_name"`
|
||||||
|
Email string `json:"email"`
|
||||||
|
CreatedAt time.Time `json:"-"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (app *application) CreateAndSendInvoice(w http.ResponseWriter, r *http.Request) {
|
||||||
|
// receive json
|
||||||
|
var order Order
|
||||||
|
|
||||||
|
err := app.readJSON(w, r, &order)
|
||||||
|
if err != nil {
|
||||||
|
app.badRequest(w, r, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// generate a pdf invoice
|
||||||
|
|
||||||
|
// create mail
|
||||||
|
|
||||||
|
// send mail with attachment
|
||||||
|
|
||||||
|
// send response
|
||||||
|
var resp JSONResponse
|
||||||
|
resp.OK = true
|
||||||
|
resp.Message = fmt.Sprintf("Invoice %d.pdf created and sent to %s", order.ID, order.Email)
|
||||||
|
app.writeJSON(w, http.StatusCreated, resp)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (app *application) createInvoicePDF(order Order) error {
|
||||||
|
pdf := gofpdf.New("P", "mm", "Letter", "")
|
||||||
|
pdf.SetMargins(10, 13, 10)
|
||||||
|
pdf.SetAutoPageBreak(true, 0)
|
||||||
|
|
||||||
|
importer := gofpdi.NewImporter()
|
||||||
|
|
||||||
|
t := importer.ImportPage(pdf, "./pdf-templates/invoice.pdf", q, "/MediaBox")
|
||||||
|
|
||||||
|
pdf.AddPage()
|
||||||
|
importer.UseImportedTemplate(pdf, t, 0, 0, 215.9, 0)
|
||||||
|
|
||||||
|
pdf.SetY(20)
|
||||||
|
|
||||||
|
// write info
|
||||||
|
pdf.SetY(50)
|
||||||
|
pdf.SetX(10)
|
||||||
|
pdf.SetFont("Times", "", 11)
|
||||||
|
pdf.CellFormat(
|
||||||
|
97,
|
||||||
|
8,
|
||||||
|
fmt.Sprintf("Attention: %s %s", order.FirstName, order.LastName),
|
||||||
|
"",
|
||||||
|
0,
|
||||||
|
"L",
|
||||||
|
false,
|
||||||
|
0,
|
||||||
|
"",
|
||||||
|
)
|
||||||
|
pdf.Ln(5)
|
||||||
|
pdf.CellFormat(
|
||||||
|
97,
|
||||||
|
8,
|
||||||
|
order.Email,
|
||||||
|
"",
|
||||||
|
0,
|
||||||
|
"L",
|
||||||
|
false,
|
||||||
|
0,
|
||||||
|
"",
|
||||||
|
)
|
||||||
|
pdf.Ln(5)
|
||||||
|
pdf.CellFormat(
|
||||||
|
97,
|
||||||
|
8,
|
||||||
|
order.CreatedAt.Format("2005-01-02"),
|
||||||
|
"",
|
||||||
|
0,
|
||||||
|
"L",
|
||||||
|
false,
|
||||||
|
0,
|
||||||
|
"",
|
||||||
|
)
|
||||||
|
|
||||||
|
pdf.SetX(58)
|
||||||
|
pdf.SetY(93)
|
||||||
|
pdf.CellFormat(
|
||||||
|
155,
|
||||||
|
8,
|
||||||
|
order.Product,
|
||||||
|
"",
|
||||||
|
0,
|
||||||
|
"L",
|
||||||
|
false,
|
||||||
|
0,
|
||||||
|
"",
|
||||||
|
)
|
||||||
|
pdf.SetX(166)
|
||||||
|
pdf.CellFormat(
|
||||||
|
20,
|
||||||
|
8,
|
||||||
|
fmt.Sprintf("%d", order.Quantity),
|
||||||
|
"",
|
||||||
|
0,
|
||||||
|
"C",
|
||||||
|
false,
|
||||||
|
0,
|
||||||
|
"",
|
||||||
|
)
|
||||||
|
|
||||||
|
pdf.SetX(185)
|
||||||
|
pdf.CellFormat(
|
||||||
|
155,
|
||||||
|
8,
|
||||||
|
fmt.Sprintf("€%.2f", float32(order.Amount/100.0)),
|
||||||
|
"",
|
||||||
|
0,
|
||||||
|
"R",
|
||||||
|
false,
|
||||||
|
0,
|
||||||
|
"",
|
||||||
|
)
|
||||||
|
|
||||||
|
invoicePath := fmt.Sprintf("./invoices/%d.pdf", order.ID)
|
||||||
|
err := pdf.OutputFileAndClose(invoicePath)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
23
cmd/micro/invoice/invoice-routes.go
Normal file
23
cmd/micro/invoice/invoice-routes.go
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/go-chi/chi/v5"
|
||||||
|
"github.com/go-chi/cors"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (app *application) routes() http.Handler {
|
||||||
|
mux := chi.NewRouter()
|
||||||
|
|
||||||
|
mux.Use(cors.Handler(cors.Options{
|
||||||
|
AllowedOrigins: []string{"https://*", "http://*"},
|
||||||
|
AllowedMethods: []string{"GET", "POST", "PUT", "DELETE", "OPTIONS"},
|
||||||
|
AllowedHeaders: []string{"Accept", "Authorization", "Content-Type", "X-CSRF-Token"},
|
||||||
|
AllowCredentials: false,
|
||||||
|
MaxAge: 300,
|
||||||
|
}))
|
||||||
|
|
||||||
|
mux.Post("/invoice/create-and-send", app.CreateAndSendInvoice)
|
||||||
|
return mux
|
||||||
|
}
|
79
cmd/micro/invoice/invoice.go
Normal file
79
cmd/micro/invoice/invoice.go
Normal file
@ -0,0 +1,79 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"flag"
|
||||||
|
"fmt"
|
||||||
|
"log"
|
||||||
|
"net/http"
|
||||||
|
"os"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
version = "1.0.0"
|
||||||
|
)
|
||||||
|
|
||||||
|
type config struct {
|
||||||
|
port int
|
||||||
|
smtp struct {
|
||||||
|
host string
|
||||||
|
port int
|
||||||
|
username string
|
||||||
|
password string
|
||||||
|
}
|
||||||
|
frontend string
|
||||||
|
}
|
||||||
|
|
||||||
|
type application struct {
|
||||||
|
config config
|
||||||
|
infoLog *log.Logger
|
||||||
|
errorLog *log.Logger
|
||||||
|
version string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (app *application) serve() error {
|
||||||
|
srv := &http.Server{
|
||||||
|
Addr: fmt.Sprintf(":%d", app.config.port),
|
||||||
|
Handler: app.routes(),
|
||||||
|
IdleTimeout: 30 * time.Second,
|
||||||
|
ReadTimeout: 10 * time.Second,
|
||||||
|
ReadHeaderTimeout: 5 * time.Second,
|
||||||
|
WriteTimeout: 5 * time.Second,
|
||||||
|
}
|
||||||
|
|
||||||
|
app.infoLog.Printf(
|
||||||
|
"Starting invoice microservice on port %d",
|
||||||
|
app.config.port,
|
||||||
|
)
|
||||||
|
return srv.ListenAndServe()
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
var cfg config
|
||||||
|
|
||||||
|
flag.IntVar(&cfg.port, "port", 5000, "Server port to listen on")
|
||||||
|
flag.StringVar(&cfg.smtp.host, "smtphost", "0.0.0.0", "smtp host")
|
||||||
|
flag.IntVar(&cfg.smtp.port, "smtpport", 1025, "smtp host")
|
||||||
|
flag.StringVar(&cfg.smtp.username, "smtpuser", "user", "smtp user")
|
||||||
|
flag.StringVar(&cfg.smtp.password, "smtppwd", "password", "smtp password")
|
||||||
|
flag.StringVar(&cfg.frontend, "frontend", "http://localhost:4000", "frontend address")
|
||||||
|
|
||||||
|
flag.Parse()
|
||||||
|
|
||||||
|
infoLog := log.New(os.Stdout, "INFO\t", log.Ldate|log.Ltime)
|
||||||
|
errorLog := log.New(os.Stdout, "ERROR\t", log.Ldate|log.Ltime|log.Lshortfile)
|
||||||
|
|
||||||
|
app := &application{
|
||||||
|
version: version,
|
||||||
|
config: cfg,
|
||||||
|
infoLog: infoLog,
|
||||||
|
errorLog: errorLog,
|
||||||
|
}
|
||||||
|
|
||||||
|
app.CreateDirIfNotExist("./invoices")
|
||||||
|
|
||||||
|
err := app.serve()
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
@ -119,6 +119,8 @@ func main() {
|
|||||||
Session: session,
|
Session: session,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
go app.ListenToWsChannel()
|
||||||
|
|
||||||
app.infoLog.Println("Connected to MariaDB")
|
app.infoLog.Println("Connected to MariaDB")
|
||||||
|
|
||||||
err = app.serve()
|
err = app.serve()
|
||||||
|
@ -12,6 +12,8 @@ func (app *application) routes() http.Handler {
|
|||||||
|
|
||||||
mux.Get("/", app.Home)
|
mux.Get("/", app.Home)
|
||||||
|
|
||||||
|
mux.Get("/ws", app.WsEndPoint)
|
||||||
|
|
||||||
mux.Route("/admin", func(mux chi.Router) {
|
mux.Route("/admin", func(mux chi.Router) {
|
||||||
mux.Use(app.Auth)
|
mux.Use(app.Auth)
|
||||||
mux.Get("/virtual-terminal", app.VirtualTerminal)
|
mux.Get("/virtual-terminal", app.VirtualTerminal)
|
||||||
|
@ -105,7 +105,12 @@
|
|||||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"
|
||||||
integrity="sha384-YvpcrYf0tY3lHB60NNkmXc5s9fDVZLESaAA55NDzOxhy9GkcIdslK1eN7N6jIeHz"
|
integrity="sha384-YvpcrYf0tY3lHB60NNkmXc5s9fDVZLESaAA55NDzOxhy9GkcIdslK1eN7N6jIeHz"
|
||||||
crossorigin="anonymous"></script>
|
crossorigin="anonymous"></script>
|
||||||
<script src="/static/js/base.js"></script>
|
<script type="module">
|
||||||
|
import {wsConn, socket} from "/static/js/base.js"
|
||||||
|
document.addEventListener("DOMContentLoaded", function() {
|
||||||
|
wsConn({{.IsAuthenticated}}, {{.UserID}});
|
||||||
|
});
|
||||||
|
</script>
|
||||||
{{ block "js" . }}
|
{{ block "js" . }}
|
||||||
{{ end }}
|
{{ end }}
|
||||||
</body>
|
</body>
|
||||||
|
109
cmd/web/ws-handlers.go
Normal file
109
cmd/web/ws-handlers.go
Normal file
@ -0,0 +1,109 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/gorilla/websocket"
|
||||||
|
)
|
||||||
|
|
||||||
|
type WebSocketConnection struct {
|
||||||
|
*websocket.Conn
|
||||||
|
}
|
||||||
|
|
||||||
|
type WsPayload struct {
|
||||||
|
Action string `json:"action"`
|
||||||
|
Message string `json:"message"`
|
||||||
|
UserName string `json:"user_name"`
|
||||||
|
MessageType string `json:"message_type"`
|
||||||
|
UserID int `json:"user_id"`
|
||||||
|
Conn WebSocketConnection `json:"-"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type WsJSONResponse struct {
|
||||||
|
Action string `json:"action"`
|
||||||
|
Message string `json:"message"`
|
||||||
|
UserID int `json:"user_id"`
|
||||||
|
}
|
||||||
|
|
||||||
|
var upgradeConnection = websocket.Upgrader{
|
||||||
|
ReadBufferSize: 1024,
|
||||||
|
WriteBufferSize: 1024,
|
||||||
|
// since we don't expect any communication from the client side
|
||||||
|
CheckOrigin: func(r *http.Request) bool { return true },
|
||||||
|
}
|
||||||
|
|
||||||
|
var clients = make(map[WebSocketConnection]string)
|
||||||
|
|
||||||
|
var wsChan = make(chan WsPayload)
|
||||||
|
|
||||||
|
func (app *application) WsEndPoint(w http.ResponseWriter, r *http.Request) {
|
||||||
|
ws, err := upgradeConnection.Upgrade(w, r, nil)
|
||||||
|
if err != nil {
|
||||||
|
app.errorLog.Println(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
app.infoLog.Printf("Client connected from %s\n", r.RemoteAddr)
|
||||||
|
var response WsJSONResponse
|
||||||
|
response.Message = "Connected to server"
|
||||||
|
|
||||||
|
err = ws.WriteJSON(response)
|
||||||
|
if err != nil {
|
||||||
|
app.errorLog.Println(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
conn := WebSocketConnection{Conn: ws}
|
||||||
|
clients[conn] = ""
|
||||||
|
|
||||||
|
go app.ListenForWS(&conn)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (app *application) ListenForWS(conn *WebSocketConnection) {
|
||||||
|
defer func() {
|
||||||
|
if r := recover(); r != nil {
|
||||||
|
app.errorLog.Println("ERROR:", fmt.Sprintf("%v", r))
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
var payload WsPayload
|
||||||
|
|
||||||
|
for {
|
||||||
|
err := conn.ReadJSON(&payload)
|
||||||
|
if err != nil {
|
||||||
|
// do nothing
|
||||||
|
app.errorLog.Println(err)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
payload.Conn = *conn
|
||||||
|
wsChan <- payload
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (app *application) ListenToWsChannel() {
|
||||||
|
var response WsJSONResponse
|
||||||
|
for {
|
||||||
|
e := <-wsChan
|
||||||
|
switch e.Action {
|
||||||
|
case "deleteUser":
|
||||||
|
response.Action = "logout"
|
||||||
|
response.Message = "Your account has ben deleted"
|
||||||
|
response.UserID = e.UserID
|
||||||
|
app.broadcastToAll(response)
|
||||||
|
default:
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (app *application) broadcastToAll(response WsJSONResponse) {
|
||||||
|
for client := range clients {
|
||||||
|
// broadcast to every connected client
|
||||||
|
err := client.WriteJSON(response)
|
||||||
|
if err != nil {
|
||||||
|
app.errorLog.Printf("Websocket err on %s: %s", response.Action, err)
|
||||||
|
_ = client.Close()
|
||||||
|
delete(clients, client)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
4
go.mod
4
go.mod
@ -9,6 +9,8 @@ require (
|
|||||||
github.com/go-chi/chi/v5 v5.1.0
|
github.com/go-chi/chi/v5 v5.1.0
|
||||||
github.com/go-chi/cors v1.2.1
|
github.com/go-chi/cors v1.2.1
|
||||||
github.com/go-sql-driver/mysql v1.8.1
|
github.com/go-sql-driver/mysql v1.8.1
|
||||||
|
github.com/gorilla/websocket v1.5.3
|
||||||
|
github.com/phpdave11/gofpdf v1.4.2
|
||||||
github.com/stripe/stripe-go/v79 v79.6.0
|
github.com/stripe/stripe-go/v79 v79.6.0
|
||||||
github.com/xhit/go-simple-mail/v2 v2.16.0
|
github.com/xhit/go-simple-mail/v2 v2.16.0
|
||||||
golang.org/x/crypto v0.26.0
|
golang.org/x/crypto v0.26.0
|
||||||
@ -17,6 +19,8 @@ require (
|
|||||||
require (
|
require (
|
||||||
filippo.io/edwards25519 v1.1.0 // indirect
|
filippo.io/edwards25519 v1.1.0 // indirect
|
||||||
github.com/go-test/deep v1.1.1 // indirect
|
github.com/go-test/deep v1.1.1 // indirect
|
||||||
|
github.com/phpdave11/gofpdi v1.0.12 // indirect
|
||||||
|
github.com/pkg/errors v0.9.1 // indirect
|
||||||
github.com/toorop/go-dkim v0.0.0-20201103131630-e1cd1a0a5208 // indirect
|
github.com/toorop/go-dkim v0.0.0-20201103131630-e1cd1a0a5208 // indirect
|
||||||
golang.org/x/sys v0.23.0 // indirect
|
golang.org/x/sys v0.23.0 // indirect
|
||||||
)
|
)
|
||||||
|
15
go.sum
15
go.sum
@ -4,6 +4,7 @@ github.com/alexedwards/scs/mysqlstore v0.0.0-20240316134038-7e11d57e8885 h1:C7QA
|
|||||||
github.com/alexedwards/scs/mysqlstore v0.0.0-20240316134038-7e11d57e8885/go.mod h1:p8jK3D80sw1PFrCSdlcJF1O75bp55HqbgDyyCLM0FrE=
|
github.com/alexedwards/scs/mysqlstore v0.0.0-20240316134038-7e11d57e8885/go.mod h1:p8jK3D80sw1PFrCSdlcJF1O75bp55HqbgDyyCLM0FrE=
|
||||||
github.com/alexedwards/scs/v2 v2.8.0 h1:h31yUYoycPuL0zt14c0gd+oqxfRwIj6SOjHdKRZxhEw=
|
github.com/alexedwards/scs/v2 v2.8.0 h1:h31yUYoycPuL0zt14c0gd+oqxfRwIj6SOjHdKRZxhEw=
|
||||||
github.com/alexedwards/scs/v2 v2.8.0/go.mod h1:ToaROZxyKukJKT/xLcVQAChi5k6+Pn1Gvmdl7h3RRj8=
|
github.com/alexedwards/scs/v2 v2.8.0/go.mod h1:ToaROZxyKukJKT/xLcVQAChi5k6+Pn1Gvmdl7h3RRj8=
|
||||||
|
github.com/boombuler/barcode v1.0.0/go.mod h1:paBWMcWSl3LHKBqUq+rly7CNSldXjb2rDl3JlRe0mD8=
|
||||||
github.com/bwmarrin/go-alone v0.0.0-20190806015146-742bb55d1631 h1:Xb5rra6jJt5Z1JsZhIMby+IP5T8aU+Uc2RC9RzSxs9g=
|
github.com/bwmarrin/go-alone v0.0.0-20190806015146-742bb55d1631 h1:Xb5rra6jJt5Z1JsZhIMby+IP5T8aU+Uc2RC9RzSxs9g=
|
||||||
github.com/bwmarrin/go-alone v0.0.0-20190806015146-742bb55d1631/go.mod h1:P86Dksd9km5HGX5UMIocXvX87sEp2xUARle3by+9JZ4=
|
github.com/bwmarrin/go-alone v0.0.0-20190806015146-742bb55d1631/go.mod h1:P86Dksd9km5HGX5UMIocXvX87sEp2xUARle3by+9JZ4=
|
||||||
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
|
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
|
||||||
@ -17,9 +18,21 @@ github.com/go-sql-driver/mysql v1.8.1 h1:LedoTUt/eveggdHS9qUFC1EFSa8bU2+1pZjSRpv
|
|||||||
github.com/go-sql-driver/mysql v1.8.1/go.mod h1:wEBSXgmK//2ZFJyE+qWnIsVGmvmEKlqwuVSjsCm7DZg=
|
github.com/go-sql-driver/mysql v1.8.1/go.mod h1:wEBSXgmK//2ZFJyE+qWnIsVGmvmEKlqwuVSjsCm7DZg=
|
||||||
github.com/go-test/deep v1.1.1 h1:0r/53hagsehfO4bzD2Pgr/+RgHqhmf+k1Bpse2cTu1U=
|
github.com/go-test/deep v1.1.1 h1:0r/53hagsehfO4bzD2Pgr/+RgHqhmf+k1Bpse2cTu1U=
|
||||||
github.com/go-test/deep v1.1.1/go.mod h1:5C2ZWiW0ErCdrYzpqxLbTX7MG14M9iiw8DgHncVwcsE=
|
github.com/go-test/deep v1.1.1/go.mod h1:5C2ZWiW0ErCdrYzpqxLbTX7MG14M9iiw8DgHncVwcsE=
|
||||||
|
github.com/gorilla/websocket v1.5.3 h1:saDtZ6Pbx/0u+bgYQ3q96pZgCzfhKXGPqt7kZ72aNNg=
|
||||||
|
github.com/gorilla/websocket v1.5.3/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
|
||||||
|
github.com/jung-kurt/gofpdf v1.0.0/go.mod h1:7Id9E/uU8ce6rXgefFLlgrJj/GYY22cpxn+r32jIOes=
|
||||||
|
github.com/phpdave11/gofpdf v1.4.2 h1:KPKiIbfwbvC/wOncwhrpRdXVj2CZTCFlw4wnoyjtHfQ=
|
||||||
|
github.com/phpdave11/gofpdf v1.4.2/go.mod h1:zpO6xFn9yxo3YLyMvW8HcKWVdbNqgIfOOp2dXMnm1mY=
|
||||||
|
github.com/phpdave11/gofpdi v1.0.12 h1:RZb9NG62cw/RW0rHAduVRo+98R8o/G1krcg2ns7DakQ=
|
||||||
|
github.com/phpdave11/gofpdi v1.0.12/go.mod h1:vBmVV0Do6hSBHC8uKUQ71JGW+ZGQq74llk/7bXwjDoI=
|
||||||
|
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||||
|
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
|
||||||
|
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||||
|
github.com/ruudk/golang-pdf417 v0.0.0-20181029194003-1af4ab5afa58/go.mod h1:6lfFZQK844Gfx8o5WFuvpxWRwnSoipWe/p622j1v06w=
|
||||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||||
|
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
|
||||||
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
|
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
|
||||||
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||||
github.com/stripe/stripe-go/v79 v79.6.0 h1:qSBV2f2rpLEEZTdTlVLzdmQJZNmfoo2E3hUEkFT8GBc=
|
github.com/stripe/stripe-go/v79 v79.6.0 h1:qSBV2f2rpLEEZTdTlVLzdmQJZNmfoo2E3hUEkFT8GBc=
|
||||||
@ -30,6 +43,7 @@ github.com/xhit/go-simple-mail/v2 v2.16.0 h1:ouGy/Ww4kuaqu2E2UrDw7SvLaziWTB60ICL
|
|||||||
github.com/xhit/go-simple-mail/v2 v2.16.0/go.mod h1:b7P5ygho6SYE+VIqpxA6QkYfv4teeyG4MKqB3utRu98=
|
github.com/xhit/go-simple-mail/v2 v2.16.0/go.mod h1:b7P5ygho6SYE+VIqpxA6QkYfv4teeyG4MKqB3utRu98=
|
||||||
golang.org/x/crypto v0.26.0 h1:RrRspgV4mU+YwB4FYnuBoKsUapNIL5cohGAmSH3azsw=
|
golang.org/x/crypto v0.26.0 h1:RrRspgV4mU+YwB4FYnuBoKsUapNIL5cohGAmSH3azsw=
|
||||||
golang.org/x/crypto v0.26.0/go.mod h1:GY7jblb9wI+FOo5y8/S2oY4zWP07AkOJ4+jxCqdqn54=
|
golang.org/x/crypto v0.26.0/go.mod h1:GY7jblb9wI+FOo5y8/S2oY4zWP07AkOJ4+jxCqdqn54=
|
||||||
|
golang.org/x/image v0.0.0-20190910094157-69e4b8554b2a/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
|
||||||
golang.org/x/net v0.0.0-20210520170846-37e1c6afe023/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
|
golang.org/x/net v0.0.0-20210520170846-37e1c6afe023/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
|
||||||
golang.org/x/net v0.21.0 h1:AQyQV4dYCvJ7vGmJyKki9+PBdyvhkSd8EIx/qb0AYv4=
|
golang.org/x/net v0.21.0 h1:AQyQV4dYCvJ7vGmJyKki9+PBdyvhkSd8EIx/qb0AYv4=
|
||||||
golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44=
|
golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44=
|
||||||
@ -38,6 +52,7 @@ golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7w
|
|||||||
golang.org/x/sys v0.23.0 h1:YfKFowiIMvtgl1UERQoTPPToxltDeZfbj4H7dVUCwmM=
|
golang.org/x/sys v0.23.0 h1:YfKFowiIMvtgl1UERQoTPPToxltDeZfbj4H7dVUCwmM=
|
||||||
golang.org/x/sys v0.23.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
golang.org/x/sys v0.23.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||||
|
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||||
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||||
golang.org/x/text v0.17.0 h1:XtiM5bkSOt+ewxlOE/aE/AKEHibwj/6gvWMl9Rsh0Qc=
|
golang.org/x/text v0.17.0 h1:XtiM5bkSOt+ewxlOE/aE/AKEHibwj/6gvWMl9Rsh0Qc=
|
||||||
golang.org/x/text v0.17.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
|
golang.org/x/text v0.17.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
|
||||||
|
BIN
pdf-templates/invoice.pdf
Normal file
BIN
pdf-templates/invoice.pdf
Normal file
Binary file not shown.
@ -1,3 +1,32 @@
|
|||||||
|
export let socket;
|
||||||
|
|
||||||
|
export function wsConn(is_authenticated, user_id) {
|
||||||
|
if (is_authenticated !== 1) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
socket = new WebSocket("ws://localhost:4000/ws")
|
||||||
|
socket.onopen = () => {
|
||||||
|
console.log("Successfully connected to websockets")
|
||||||
|
}
|
||||||
|
|
||||||
|
socket.onclose = event => {};
|
||||||
|
socket.onerror = error => {};
|
||||||
|
|
||||||
|
socket.onmessage = msg => {
|
||||||
|
let data = JSON.parse(msg.data);
|
||||||
|
|
||||||
|
switch (data.action) {
|
||||||
|
case "logout":
|
||||||
|
if (data.user_id === user_id) {
|
||||||
|
logout()
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// let loginLink = document.getElementById("login-link");
|
// let loginLink = document.getElementById("login-link");
|
||||||
// let vtLink = document.getElementById("vt-link");
|
// let vtLink = document.getElementById("vt-link");
|
||||||
//
|
//
|
||||||
@ -11,9 +40,9 @@
|
|||||||
// loginLink.classList.remove('d-none')
|
// loginLink.classList.remove('d-none')
|
||||||
// });
|
// });
|
||||||
|
|
||||||
// function logout() {
|
function logout() {
|
||||||
// localStorage.removeItem("token");
|
localStorage.removeItem("token");
|
||||||
// localStorage.removeItem("token_expiry");
|
localStorage.removeItem("token_expiry");
|
||||||
// location.href = "/logout";
|
location.href = "/logout";
|
||||||
// }
|
}
|
||||||
|
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
import {socket} from "./base.js"
|
||||||
|
|
||||||
export function showUsers(api) {
|
export function showUsers(api) {
|
||||||
const tbody = document.getElementById("user-table").getElementsByTagName("tbody")[0];
|
const tbody = document.getElementById("user-table").getElementsByTagName("tbody")[0];
|
||||||
const token = localStorage.getItem("token");
|
const token = localStorage.getItem("token");
|
||||||
@ -14,6 +16,7 @@ export function showUsers(api) {
|
|||||||
fetch(api + "/api/admin/all-users", requestOptions)
|
fetch(api + "/api/admin/all-users", requestOptions)
|
||||||
.then(response => response.json())
|
.then(response => response.json())
|
||||||
.then(function (data) {
|
.then(function (data) {
|
||||||
|
console.log(data)
|
||||||
if (data) {
|
if (data) {
|
||||||
data.forEach(i => {
|
data.forEach(i => {
|
||||||
let newRow = tbody.insertRow();
|
let newRow = tbody.insertRow();
|
||||||
@ -63,21 +66,6 @@ export function showUser(api, userID) {
|
|||||||
document.getElementById("last_name").value = data.last_name;
|
document.getElementById("last_name").value = data.last_name;
|
||||||
document.getElementById("email").value = data.email;
|
document.getElementById("email").value = data.email;
|
||||||
});
|
});
|
||||||
|
|
||||||
delBtn.addEventListener("click", function () {
|
|
||||||
Swal.fire({
|
|
||||||
title: "Are you sure?",
|
|
||||||
text: "You won't be able to undo this!",
|
|
||||||
icon: "warning",
|
|
||||||
showCancelButton: true,
|
|
||||||
confirmButtonColor: "#3085d6",
|
|
||||||
cancelButtonColor: "#d33",
|
|
||||||
confirmButtonText: 'Delete User',
|
|
||||||
}).then((result) => {
|
|
||||||
console.log("would delete user id", id);
|
|
||||||
});
|
|
||||||
})
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function saveUser(api, event) {
|
export function saveUser(api, event) {
|
||||||
@ -160,6 +148,11 @@ export function deleteUser(api) {
|
|||||||
if (!data.ok) {
|
if (!data.ok) {
|
||||||
Swal.fire("Error" + data.message)
|
Swal.fire("Error" + data.message)
|
||||||
} else {
|
} else {
|
||||||
|
let jsonData = {
|
||||||
|
action: "deleteUser",
|
||||||
|
user_id: parseInt(id),
|
||||||
|
};
|
||||||
|
socket.send(JSON.stringify(jsonData));
|
||||||
location.href = "/admin/all-users"
|
location.href = "/admin/all-users"
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user