diff --git a/.gitignore b/.gitignore
index ee55fcd..f9f8893 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,4 +1,4 @@
-/frontend/node_modules/
-/frontend/dist/
+/webapp/node_modules/
+/webapp/dist/
clortho.db
clortho_test.db
diff --git a/.idea/dataSources.xml b/.idea/dataSources.xml
new file mode 100644
index 0000000..2331a9d
--- /dev/null
+++ b/.idea/dataSources.xml
@@ -0,0 +1,15 @@
+
+
+
+
+ sqlite.xerial
+ true
+ org.sqlite.JDBC
+ jdbc:sqlite:$PROJECT_DIR$/clortho.db
+
+
+
+ $ProjectFileDir$
+
+
+
\ No newline at end of file
diff --git a/cmd/server/main.go b/cmd/server/main.go
index 9735432..c9ad762 100644
--- a/cmd/server/main.go
+++ b/cmd/server/main.go
@@ -1,9 +1,9 @@
package main
import (
- "clortho/apis"
- "clortho/db"
- "clortho/users"
+ "clortho/lib/apis"
+ "clortho/lib/db"
+ "clortho/lib/users"
"github.com/gin-gonic/gin"
"log"
)
diff --git a/apis/apis.go b/lib/apis/apis.go
similarity index 83%
rename from apis/apis.go
rename to lib/apis/apis.go
index 757c91f..3b43346 100644
--- a/apis/apis.go
+++ b/lib/apis/apis.go
@@ -7,6 +7,12 @@ import (
)
func SetupRouter(r *gin.Engine, authMiddleware gin.HandlerFunc) {
+ r.NoRoute(func(c *gin.Context) {
+ c.JSON(http.StatusNotFound, gin.H{
+ "error": "Resource not found",
+ })
+ })
+
private := r.Group("/gui")
// Gets the session from the cookie, and puts it in the current request.
if authMiddleware != nil {
diff --git a/apis/apis_test.go b/lib/apis/apis_test.go
similarity index 53%
rename from apis/apis_test.go
rename to lib/apis/apis_test.go
index b9a515f..1841ce3 100644
--- a/apis/apis_test.go
+++ b/lib/apis/apis_test.go
@@ -1,13 +1,33 @@
package apis
import (
+ "clortho/lib/db"
+ "fmt"
"github.com/gin-gonic/gin"
"github.com/stretchr/testify/assert"
"net/http"
"net/http/httptest"
+ "os"
"testing"
)
+func TestMain(m *testing.M) {
+ // Set up test database file
+ os.Setenv("CLORTHO_DB_FILE", "clortho_test.db")
+ // Global setup
+ fmt.Println("Setting up resources...")
+
+ db.InitDb()
+ defer db.ResetDb()
+
+ exitCode := m.Run() // Run all tests
+
+ // Global teardown
+ fmt.Println("Cleaning up resources...")
+
+ os.Exit(exitCode)
+}
+
func TestPingRoute(t *testing.T) {
r := gin.Default()
SetupRouter(r, nil)
diff --git a/apis/apis_utils_test.go b/lib/apis/apis_utils_test.go
similarity index 93%
rename from apis/apis_utils_test.go
rename to lib/apis/apis_utils_test.go
index a6bcf50..44273ff 100644
--- a/apis/apis_utils_test.go
+++ b/lib/apis/apis_utils_test.go
@@ -1,8 +1,8 @@
package apis
import (
- "clortho/db"
- "clortho/users"
+ "clortho/lib/db"
+ "clortho/lib/users"
"github.com/gin-gonic/gin"
)
diff --git a/apis/auth_endpoints.go b/lib/apis/auth_endpoints.go
similarity index 97%
rename from apis/auth_endpoints.go
rename to lib/apis/auth_endpoints.go
index ce685c1..97eb907 100644
--- a/apis/auth_endpoints.go
+++ b/lib/apis/auth_endpoints.go
@@ -1,8 +1,8 @@
package apis
import (
- "clortho/db"
- "clortho/users"
+ "clortho/lib/db"
+ "clortho/lib/users"
"github.com/gin-gonic/gin"
)
diff --git a/apis/auth_endpoints_test.go b/lib/apis/auth_endpoints_test.go
similarity index 74%
rename from apis/auth_endpoints_test.go
rename to lib/apis/auth_endpoints_test.go
index 82af324..3ec8042 100644
--- a/apis/auth_endpoints_test.go
+++ b/lib/apis/auth_endpoints_test.go
@@ -1,38 +1,18 @@
package apis
import (
- "clortho/db"
- "clortho/users"
"encoding/json"
"fmt"
"github.com/gin-gonic/gin"
"github.com/stretchr/testify/assert"
"net/http"
"net/http/httptest"
- "os"
"strings"
"testing"
)
-func TestMain(m *testing.M) {
- // Set up test database file
- os.Setenv("CLORTHO_DB_FILE", "clortho_test.db")
- // Global setup
- fmt.Println("Setting up resources...")
-
- db.InitDb()
- defer db.ResetDb()
-
- exitCode := m.Run() // Run all tests
-
- // Global teardown
- fmt.Println("Cleaning up resources...")
-
- os.Exit(exitCode)
-}
-
func TestInitAuthEndpoints_authSignin(t *testing.T) {
- adminPass, err := users.InitAdminUser()
+ _, err := InitUser("admin", "password")
if err != nil {
t.Fatal(err)
}
@@ -40,7 +20,7 @@ func TestInitAuthEndpoints_authSignin(t *testing.T) {
r := gin.Default()
SetupRouter(r, nil)
- reqBody := loginRequest{Username: "admin", Password: *adminPass}
+ reqBody := loginRequest{Username: "admin", Password: "password"}
strReqBody, _ := json.Marshal(reqBody)
w := httptest.NewRecorder()
req, _ := http.NewRequest("POST", "/gui/auth/signin", strings.NewReader(string(strReqBody)))
@@ -53,7 +33,7 @@ func TestInitAuthEndpoints_authSignin(t *testing.T) {
}
func TestInitAuthEndpoints_authSignout(t *testing.T) {
- adminPass, err := users.InitAdminUser()
+ _, err := InitUser("admin", "admin")
if err != nil {
t.Fatal(err)
}
@@ -61,7 +41,7 @@ func TestInitAuthEndpoints_authSignout(t *testing.T) {
r := gin.Default()
SetupRouter(r, nil)
- reqBody := loginRequest{Username: "admin", Password: *adminPass}
+ reqBody := loginRequest{Username: "admin", Password: "admin"}
strReqBody, _ := json.Marshal(reqBody)
w := httptest.NewRecorder()
req, _ := http.NewRequest("POST", "/gui/auth/signout", strings.NewReader(string(strReqBody)))
diff --git a/apis/auth_middleware.go b/lib/apis/auth_middleware.go
similarity index 97%
rename from apis/auth_middleware.go
rename to lib/apis/auth_middleware.go
index 9d68523..4fc49b1 100644
--- a/apis/auth_middleware.go
+++ b/lib/apis/auth_middleware.go
@@ -1,7 +1,7 @@
package apis
import (
- "clortho/users"
+ "clortho/lib/users"
"github.com/gin-gonic/gin"
"net/http"
)
diff --git a/lib/apis/systems_endpoints.go b/lib/apis/systems_endpoints.go
new file mode 100644
index 0000000..3529442
--- /dev/null
+++ b/lib/apis/systems_endpoints.go
@@ -0,0 +1,18 @@
+package apis
+
+import (
+ "clortho/lib/users"
+ "github.com/gin-gonic/gin"
+)
+
+func InitSystemsEndpoints(r *gin.RouterGroup) {
+ group := r.Group("/users")
+ group.Use(LoggedInMiddleware())
+ group.GET("/", getUsers)
+ group.GET("/me", getMe)
+}
+
+func getServers(c *gin.Context) {
+ userList := users.GetUsers()
+ c.JSON(200, &userList)
+}
diff --git a/lib/apis/systems_endpoints_test.go b/lib/apis/systems_endpoints_test.go
new file mode 100644
index 0000000..473b613
--- /dev/null
+++ b/lib/apis/systems_endpoints_test.go
@@ -0,0 +1,32 @@
+package apis
+
+import (
+ "encoding/json"
+ "github.com/gin-gonic/gin"
+ "github.com/stretchr/testify/assert"
+ "net/http"
+ "net/http/httptest"
+ "strings"
+ "testing"
+)
+
+func TestInitSystemsEndpoints_getSystems(t *testing.T) {
+ _, err := InitUser("admin", "password")
+ if err != nil {
+ t.Fatal(err)
+ }
+
+ r := gin.Default()
+ SetupRouter(r, nil)
+
+ reqBody := loginRequest{Username: "admin", Password: "password"}
+ strReqBody, _ := json.Marshal(reqBody)
+ w := httptest.NewRecorder()
+ req, _ := http.NewRequest("POST", "/gui/auth/signin", strings.NewReader(string(strReqBody)))
+ r.ServeHTTP(w, req)
+
+ assert.Equal(t, 200, w.Code)
+ assert.JSONEq(t, `{"valid": true}`, w.Body.String())
+ setCookie := w.Header().Get("Set-Cookie")
+ assert.True(t, strings.Contains(setCookie, "CLORTHO_AUTH="))
+}
diff --git a/apis/users_endpoints.go b/lib/apis/users_endpoints.go
similarity index 93%
rename from apis/users_endpoints.go
rename to lib/apis/users_endpoints.go
index 84b7638..5b83f75 100644
--- a/apis/users_endpoints.go
+++ b/lib/apis/users_endpoints.go
@@ -1,7 +1,7 @@
package apis
import (
- "clortho/users"
+ "clortho/lib/users"
"github.com/gin-gonic/gin"
)
diff --git a/db/db.go b/lib/db/db.go
similarity index 100%
rename from db/db.go
rename to lib/db/db.go
diff --git a/db/db_test.go b/lib/db/db_test.go
similarity index 100%
rename from db/db_test.go
rename to lib/db/db_test.go
diff --git a/db/entities.go b/lib/db/entities.go
similarity index 73%
rename from db/entities.go
rename to lib/db/entities.go
index 1ef69b7..71912f6 100644
--- a/db/entities.go
+++ b/lib/db/entities.go
@@ -26,15 +26,15 @@ type User struct {
type UserSession struct {
ClorthoModel
- UserID uint `gorm:"not null" json:"-"`
- User User `gorm:"foreignKey:UserID" json:"user"`
+ UserID uint `gorm:"not null" json:"-"`
+ User *User `gorm:"foreignKey:UserID" json:"user"`
}
type Key struct {
ClorthoModel
UserID uint `gorm:"not null" json:"-"`
- User User `gorm:"foreignKey:UserID" json:"user"`
+ User *User `gorm:"foreignKey:UserID" json:"user"`
Content string `gorm:"not null" json:"-" json:"content"`
}
@@ -64,10 +64,10 @@ type SystemGroup struct {
type Grant struct {
ClorthoModel
- UserID uint `gorm:"not null" json:"-"`
- User User `gorm:"foreignKey:UserID" json:"user"`
- SystemID uint `gorm:"not null" json:"-"`
- System System `gorm:"foreignKey:SystemID" json:"system"`
- GrantedByID uint `gorm:"not null" json:"-"`
- GrantedBy User `gorm:"foreignKey:GrantedByID" json:"grantedBy"`
+ UserID uint `gorm:"not null" json:"-"`
+ User User `gorm:"foreignKey:UserID" json:"user"`
+ SystemID uint `gorm:"not null" json:"-"`
+ System *System `gorm:"foreignKey:SystemID" json:"system"`
+ GrantedByID uint `gorm:"not null" json:"-"`
+ GrantedBy *User `gorm:"foreignKey:GrantedByID" json:"grantedBy"`
}
diff --git a/lib/systems/systems.go b/lib/systems/systems.go
new file mode 100644
index 0000000..6e592a8
--- /dev/null
+++ b/lib/systems/systems.go
@@ -0,0 +1,18 @@
+package systems
+
+import "clortho/lib/db"
+
+func CreateSystem(name string) (*db.System, error) {
+ system := db.System{Name: name}
+ result := db.Connection.Create(&system)
+ if result.Error != nil {
+ return nil, result.Error
+ }
+ return &system, nil
+}
+
+func GetSystems() []db.System {
+ var systems []db.System
+ db.Connection.Find(&systems)
+ return systems
+}
diff --git a/lib/systems/systems_test.go b/lib/systems/systems_test.go
new file mode 100644
index 0000000..a0717a2
--- /dev/null
+++ b/lib/systems/systems_test.go
@@ -0,0 +1,24 @@
+package systems
+
+import (
+ "clortho/lib/db"
+ "fmt"
+ "os"
+ "testing"
+)
+
+func TestMain(m *testing.M) {
+ // Global setup
+ fmt.Println("Setting up resources...")
+
+ db.InitDb()
+
+ exitCode := m.Run() // Run all tests
+
+ // Global teardown
+ fmt.Println("Cleaning up resources...")
+
+ db.ResetDb()
+
+ os.Exit(exitCode)
+}
diff --git a/users/users.go b/lib/users/users.go
similarity index 96%
rename from users/users.go
rename to lib/users/users.go
index 19c7f00..9959606 100644
--- a/users/users.go
+++ b/lib/users/users.go
@@ -1,8 +1,8 @@
package users
import (
- "clortho/db"
- "clortho/utils"
+ "clortho/lib/db"
+ "clortho/lib/utils"
"crypto/rand"
"errors"
"fmt"
@@ -64,7 +64,7 @@ func GetUsers() []db.User {
func GetSession(id uint) *db.UserSession {
var session db.UserSession
- result := db.Connection.First(&session, id)
+ result := db.Connection.Joins("User").First(&session, id)
if result.RowsAffected != 0 {
return &session
} else {
@@ -151,7 +151,7 @@ func GenerateJwt(sessionId uint) (string, error) {
}
func NewSession(user db.User) *db.UserSession {
- session := db.UserSession{User: user}
+ session := db.UserSession{User: &user}
db.Connection.Create(&session)
return &session
}
diff --git a/users/users_test.go b/lib/users/users_test.go
similarity index 98%
rename from users/users_test.go
rename to lib/users/users_test.go
index ff5f2f6..4bbcfa6 100644
--- a/users/users_test.go
+++ b/lib/users/users_test.go
@@ -1,8 +1,8 @@
package users
import (
- "clortho/db"
- "clortho/utils"
+ "clortho/lib/db"
+ "clortho/lib/utils"
"fmt"
"os"
"testing"
diff --git a/utils/utils.go b/lib/utils/utils.go
similarity index 100%
rename from utils/utils.go
rename to lib/utils/utils.go
diff --git a/frontend/.browserslistrc b/webapp/.browserslistrc
similarity index 100%
rename from frontend/.browserslistrc
rename to webapp/.browserslistrc
diff --git a/frontend/.editorconfig b/webapp/.editorconfig
similarity index 100%
rename from frontend/.editorconfig
rename to webapp/.editorconfig
diff --git a/frontend/.eslintrc-auto-import.json b/webapp/.eslintrc-auto-import.json
similarity index 100%
rename from frontend/.eslintrc-auto-import.json
rename to webapp/.eslintrc-auto-import.json
diff --git a/frontend/.gitignore b/webapp/.gitignore
similarity index 100%
rename from frontend/.gitignore
rename to webapp/.gitignore
diff --git a/frontend/README.md b/webapp/README.md
similarity index 100%
rename from frontend/README.md
rename to webapp/README.md
diff --git a/frontend/env.d.ts b/webapp/env.d.ts
similarity index 100%
rename from frontend/env.d.ts
rename to webapp/env.d.ts
diff --git a/frontend/eslint.config.js b/webapp/eslint.config.js
similarity index 100%
rename from frontend/eslint.config.js
rename to webapp/eslint.config.js
diff --git a/frontend/index.html b/webapp/index.html
similarity index 100%
rename from frontend/index.html
rename to webapp/index.html
diff --git a/frontend/package.json b/webapp/package.json
similarity index 100%
rename from frontend/package.json
rename to webapp/package.json
diff --git a/frontend/pnpm-lock.yaml b/webapp/pnpm-lock.yaml
similarity index 100%
rename from frontend/pnpm-lock.yaml
rename to webapp/pnpm-lock.yaml
diff --git a/frontend/public/favicon.ico b/webapp/public/favicon.ico
similarity index 100%
rename from frontend/public/favicon.ico
rename to webapp/public/favicon.ico
diff --git a/frontend/src/App.vue b/webapp/src/App.vue
similarity index 100%
rename from frontend/src/App.vue
rename to webapp/src/App.vue
diff --git a/frontend/src/assets/logo.png b/webapp/src/assets/logo.png
similarity index 100%
rename from frontend/src/assets/logo.png
rename to webapp/src/assets/logo.png
diff --git a/frontend/src/assets/logo.svg b/webapp/src/assets/logo.svg
similarity index 100%
rename from frontend/src/assets/logo.svg
rename to webapp/src/assets/logo.svg
diff --git a/frontend/src/auto-imports.d.ts b/webapp/src/auto-imports.d.ts
similarity index 100%
rename from frontend/src/auto-imports.d.ts
rename to webapp/src/auto-imports.d.ts
diff --git a/frontend/src/components.d.ts b/webapp/src/components.d.ts
similarity index 100%
rename from frontend/src/components.d.ts
rename to webapp/src/components.d.ts
diff --git a/frontend/src/components/AppFooter.vue b/webapp/src/components/AppFooter.vue
similarity index 100%
rename from frontend/src/components/AppFooter.vue
rename to webapp/src/components/AppFooter.vue
diff --git a/frontend/src/components/HelloWorld.vue b/webapp/src/components/HelloWorld.vue
similarity index 100%
rename from frontend/src/components/HelloWorld.vue
rename to webapp/src/components/HelloWorld.vue
diff --git a/frontend/src/components/README.md b/webapp/src/components/README.md
similarity index 100%
rename from frontend/src/components/README.md
rename to webapp/src/components/README.md
diff --git a/frontend/src/layouts/README.md b/webapp/src/layouts/README.md
similarity index 100%
rename from frontend/src/layouts/README.md
rename to webapp/src/layouts/README.md
diff --git a/frontend/src/layouts/default.vue b/webapp/src/layouts/default.vue
similarity index 65%
rename from frontend/src/layouts/default.vue
rename to webapp/src/layouts/default.vue
index 8ecc3eb..3456cad 100644
--- a/frontend/src/layouts/default.vue
+++ b/webapp/src/layouts/default.vue
@@ -18,19 +18,23 @@
v-bind="props"
/>
-
- {{ appStore.user.displayName }}
-
-
- {{ item.title }}
-
-
-
+
+
+ Hello {{ appStore.user?.displayName }}
+
+
+
+
+ {{ item.title }}
+
+
+
+
diff --git a/frontend/src/main.ts b/webapp/src/main.ts
similarity index 100%
rename from frontend/src/main.ts
rename to webapp/src/main.ts
diff --git a/frontend/src/pages/README.md b/webapp/src/pages/README.md
similarity index 100%
rename from frontend/src/pages/README.md
rename to webapp/src/pages/README.md
diff --git a/frontend/src/pages/auth/signin.vue b/webapp/src/pages/auth/signin.vue
similarity index 96%
rename from frontend/src/pages/auth/signin.vue
rename to webapp/src/pages/auth/signin.vue
index 80f7a2e..4c49bc2 100644
--- a/frontend/src/pages/auth/signin.vue
+++ b/webapp/src/pages/auth/signin.vue
@@ -66,6 +66,12 @@
diff --git a/frontend/src/pages/index.vue b/webapp/src/pages/index.vue
similarity index 61%
rename from frontend/src/pages/index.vue
rename to webapp/src/pages/index.vue
index ce3e0f5..8b9142d 100644
--- a/frontend/src/pages/index.vue
+++ b/webapp/src/pages/index.vue
@@ -3,9 +3,9 @@
diff --git a/frontend/src/plugins/README.md b/webapp/src/plugins/README.md
similarity index 100%
rename from frontend/src/plugins/README.md
rename to webapp/src/plugins/README.md
diff --git a/frontend/src/plugins/index.ts b/webapp/src/plugins/index.ts
similarity index 100%
rename from frontend/src/plugins/index.ts
rename to webapp/src/plugins/index.ts
diff --git a/frontend/src/plugins/vuetify.ts b/webapp/src/plugins/vuetify.ts
similarity index 100%
rename from frontend/src/plugins/vuetify.ts
rename to webapp/src/plugins/vuetify.ts
diff --git a/frontend/src/router/index.ts b/webapp/src/router/index.ts
similarity index 100%
rename from frontend/src/router/index.ts
rename to webapp/src/router/index.ts
diff --git a/frontend/src/stores/README.md b/webapp/src/stores/README.md
similarity index 100%
rename from frontend/src/stores/README.md
rename to webapp/src/stores/README.md
diff --git a/frontend/src/stores/app.ts b/webapp/src/stores/app.ts
similarity index 100%
rename from frontend/src/stores/app.ts
rename to webapp/src/stores/app.ts
diff --git a/frontend/src/stores/index.ts b/webapp/src/stores/index.ts
similarity index 100%
rename from frontend/src/stores/index.ts
rename to webapp/src/stores/index.ts
diff --git a/frontend/src/styles/README.md b/webapp/src/styles/README.md
similarity index 100%
rename from frontend/src/styles/README.md
rename to webapp/src/styles/README.md
diff --git a/frontend/src/styles/settings.scss b/webapp/src/styles/settings.scss
similarity index 100%
rename from frontend/src/styles/settings.scss
rename to webapp/src/styles/settings.scss
diff --git a/frontend/src/typed-router.d.ts b/webapp/src/typed-router.d.ts
similarity index 100%
rename from frontend/src/typed-router.d.ts
rename to webapp/src/typed-router.d.ts
diff --git a/frontend/tsconfig.app.json b/webapp/tsconfig.app.json
similarity index 100%
rename from frontend/tsconfig.app.json
rename to webapp/tsconfig.app.json
diff --git a/frontend/tsconfig.json b/webapp/tsconfig.json
similarity index 100%
rename from frontend/tsconfig.json
rename to webapp/tsconfig.json
diff --git a/frontend/tsconfig.node.json b/webapp/tsconfig.node.json
similarity index 100%
rename from frontend/tsconfig.node.json
rename to webapp/tsconfig.node.json
diff --git a/frontend/vite.config.mts b/webapp/vite.config.mts
similarity index 100%
rename from frontend/vite.config.mts
rename to webapp/vite.config.mts