2021-01-03 03:21:11 +00:00
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
2021-01-12 22:06:27 +00:00
|
|
|
"net/http"
|
|
|
|
|
2021-01-10 00:44:02 +00:00
|
|
|
"reichard.io/imagini/routes"
|
2021-01-12 04:48:32 +00:00
|
|
|
"reichard.io/imagini/internal/context"
|
2021-01-04 05:16:58 +00:00
|
|
|
|
2021-01-03 22:31:16 +00:00
|
|
|
"github.com/urfave/cli/v2"
|
2021-01-10 00:44:02 +00:00
|
|
|
log "github.com/sirupsen/logrus"
|
2021-01-03 03:21:11 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var CmdServe = cli.Command{
|
2021-01-03 22:31:16 +00:00
|
|
|
Name: "serve",
|
|
|
|
Aliases: []string{"s"},
|
|
|
|
Usage: "Start Imagini web server.",
|
|
|
|
Action: serveWeb,
|
2021-01-03 03:21:11 +00:00
|
|
|
}
|
|
|
|
|
2021-01-12 04:48:32 +00:00
|
|
|
func serveWeb(cliCtx *cli.Context) error {
|
2021-01-10 00:44:02 +00:00
|
|
|
log.Info("Serving Web")
|
2021-01-08 02:45:59 +00:00
|
|
|
|
2021-01-12 04:48:32 +00:00
|
|
|
ctx := context.NewImaginiContext()
|
|
|
|
routes.RegisterRoutes(ctx)
|
2021-01-08 02:45:59 +00:00
|
|
|
|
2021-01-12 04:48:32 +00:00
|
|
|
if err := http.ListenAndServe(":" + ctx.Config.ListenPort, nil); err != nil {
|
|
|
|
log.Fatal(err)
|
2021-01-10 00:44:02 +00:00
|
|
|
}
|
2021-01-08 02:45:59 +00:00
|
|
|
|
2021-01-04 05:16:58 +00:00
|
|
|
return nil
|
|
|
|
}
|
2021-01-12 04:48:32 +00:00
|
|
|
|
|
|
|
// 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
|
|
|
|
// }
|