WIP
This commit is contained in:
126
cmd/cmd.go
126
cmd/cmd.go
@@ -1,13 +1,8 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"errors"
|
||||
"reichard.io/imagini/routes"
|
||||
"reichard.io/imagini/internal/db"
|
||||
"reichard.io/imagini/internal/auth"
|
||||
"reichard.io/imagini/internal/models"
|
||||
"reichard.io/imagini/internal/config"
|
||||
"reichard.io/imagini/internal/context"
|
||||
|
||||
"github.com/urfave/cli/v2"
|
||||
"net/http"
|
||||
@@ -21,67 +16,72 @@ var CmdServe = cli.Command{
|
||||
Action: serveWeb,
|
||||
}
|
||||
|
||||
var CmdDBTest = cli.Command{
|
||||
Name: "test",
|
||||
Aliases: []string{"t"},
|
||||
Usage: "test db.",
|
||||
Action: testDatabase,
|
||||
}
|
||||
// var CmdDBTest = cli.Command{
|
||||
// Name: "test",
|
||||
// Aliases: []string{"t"},
|
||||
// Usage: "test db.",
|
||||
// Action: testDatabase,
|
||||
// }
|
||||
|
||||
func serveWeb(ctx *cli.Context) error {
|
||||
func serveWeb(cliCtx *cli.Context) error {
|
||||
log.Info("Serving Web")
|
||||
routes.RegisterRoutes()
|
||||
if err := http.ListenAndServe(":8080", nil); err != nil {
|
||||
|
||||
ctx := context.NewImaginiContext()
|
||||
routes.RegisterRoutes(ctx)
|
||||
//listener, _ := net.Listen("tcp", ctx.Config.ListenPort)
|
||||
|
||||
if err := http.ListenAndServe(":" + ctx.Config.ListenPort, nil); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func testDatabase(ctx *cli.Context) error {
|
||||
log.Info("Testing Database")
|
||||
c := config.NewConfig()
|
||||
db.ConnectDB(c)
|
||||
|
||||
err := auth.CreateUser(models.User{
|
||||
Username: "User12346",
|
||||
Email: "user26@evan.pub",
|
||||
FirstName: "User",
|
||||
LastName: "Reichard",
|
||||
AuthType: "Local",
|
||||
}, "myPassword123")
|
||||
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
|
||||
resp := auth.AuthenticateUser("User123", "myPassword123")
|
||||
if resp == true {
|
||||
log.Info("USER SUCCESSFULLY AUTHENTICATED BY USERNAME")
|
||||
}else {
|
||||
log.Info("USER NOT AUTHENTICATED")
|
||||
}
|
||||
|
||||
resp = auth.AuthenticateUser("user@evan.pub", "myPassword123")
|
||||
if resp == true {
|
||||
log.Info("USER SUCCESSFULLY AUTHENTICATED BY EMAIL")
|
||||
}else {
|
||||
log.Info("USER NOT AUTHENTICATED")
|
||||
}
|
||||
|
||||
resp = auth.AuthenticateUser("user@evan.pub", "myPassword12")
|
||||
if resp == true {
|
||||
log.Info("USER SUCCESSFULLY AUTHENTICATED BY EMAIL")
|
||||
}else {
|
||||
log.Info("USER NOT AUTHENTICATED")
|
||||
}
|
||||
|
||||
// foundUser, err := db.GetUser(db.User{Username: "User123"})
|
||||
|
||||
// if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
// log.Warn("RECORD NOT FOUND")
|
||||
// } else {
|
||||
// log.Info("FOUND USER", foundUser)
|
||||
// }
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// func testDatabase(cliCtx *cli.Context) error {
|
||||
// log.Info("Testing Database")
|
||||
// c := config.NewConfig()
|
||||
// db.ConnectDB(c)
|
||||
//
|
||||
// err := auth.CreateUser(models.User{
|
||||
// Username: "User123",
|
||||
// Email: "user26@evan.pub",
|
||||
// FirstName: "User",
|
||||
// LastName: "Reichard",
|
||||
// AuthType: "Local",
|
||||
// }, "myPassword123")
|
||||
//
|
||||
// if err != nil {
|
||||
// fmt.Println(err)
|
||||
// }
|
||||
//
|
||||
// resp := auth.AuthenticateUser(models.APICredentials{User:"User123", Password: "myPassword123"})
|
||||
// if resp == true {
|
||||
// log.Info("USER SUCCESSFULLY AUTHENTICATED BY USERNAME")
|
||||
// }else {
|
||||
// log.Info("USER NOT AUTHENTICATED")
|
||||
// }
|
||||
//
|
||||
// resp = auth.AuthenticateUser(models.APICredentials{User:"user26@evan.pub", Password: "myPassword123"})
|
||||
// if resp == true {
|
||||
// log.Info("USER SUCCESSFULLY AUTHENTICATED BY EMAIL")
|
||||
// }else {
|
||||
// log.Info("USER NOT AUTHENTICATED")
|
||||
// }
|
||||
//
|
||||
// resp = auth.AuthenticateUser(models.APICredentials{User:"user@evan.pub", Password: "myPassword12"})
|
||||
// if resp == true {
|
||||
// log.Info("USER SUCCESSFULLY AUTHENTICATED BY EMAIL")
|
||||
// }else {
|
||||
// log.Info("USER NOT AUTHENTICATED")
|
||||
// }
|
||||
//
|
||||
// // foundUser, err := db.GetUser(db.User{Username: "User123"})
|
||||
//
|
||||
// // if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
// // log.Warn("RECORD NOT FOUND")
|
||||
// // } else {
|
||||
// // log.Info("FOUND USER", foundUser)
|
||||
// // }
|
||||
//
|
||||
// return nil
|
||||
// }
|
||||
|
||||
Reference in New Issue
Block a user