mirror of
https://github.com/sonr-io/sonr.git
synced 2026-08-03 01:41:44 +00:00
refactor: migrate UI components to nebula module
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
package index
|
||||
|
||||
import "github.com/onsonr/sonr/pkg/styles/layout"
|
||||
import "github.com/onsonr/nebula/ui/layout"
|
||||
|
||||
templ NoWebauthnErrorView() {
|
||||
@layout.Root("Error | Sonr.ID") {
|
||||
|
||||
@@ -8,7 +8,7 @@ package index
|
||||
import "github.com/a-h/templ"
|
||||
import templruntime "github.com/a-h/templ/runtime"
|
||||
|
||||
import "github.com/onsonr/sonr/pkg/styles/layout"
|
||||
import "github.com/onsonr/nebula/ui/layout"
|
||||
|
||||
func NoWebauthnErrorView() templ.Component {
|
||||
return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) {
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package index
|
||||
|
||||
import (
|
||||
"github.com/onsonr/sonr/pkg/styles/layout"
|
||||
"github.com/onsonr/sonr/pkg/styles/text"
|
||||
"github.com/onsonr/nebula/ui/layout"
|
||||
"github.com/onsonr/nebula/ui/text"
|
||||
)
|
||||
|
||||
templ InitialView() {
|
||||
|
||||
@@ -9,8 +9,8 @@ import "github.com/a-h/templ"
|
||||
import templruntime "github.com/a-h/templ/runtime"
|
||||
|
||||
import (
|
||||
"github.com/onsonr/sonr/pkg/styles/layout"
|
||||
"github.com/onsonr/sonr/pkg/styles/text"
|
||||
"github.com/onsonr/nebula/ui/layout"
|
||||
"github.com/onsonr/nebula/ui/text"
|
||||
)
|
||||
|
||||
func InitialView() templ.Component {
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
package register
|
||||
|
||||
import (
|
||||
"github.com/onsonr/sonr/pkg/styles/details"
|
||||
"github.com/onsonr/sonr/pkg/styles/form"
|
||||
"github.com/onsonr/sonr/pkg/styles/layout"
|
||||
"github.com/onsonr/sonr/pkg/styles/text"
|
||||
"github.com/onsonr/nebula/ui/details"
|
||||
"github.com/onsonr/nebula/ui/form"
|
||||
"github.com/onsonr/nebula/ui/layout"
|
||||
"github.com/onsonr/nebula/ui/text"
|
||||
)
|
||||
|
||||
templ ProfileFormView(turnstileSiteKey string) {
|
||||
|
||||
@@ -9,10 +9,10 @@ import "github.com/a-h/templ"
|
||||
import templruntime "github.com/a-h/templ/runtime"
|
||||
|
||||
import (
|
||||
"github.com/onsonr/sonr/pkg/styles/details"
|
||||
"github.com/onsonr/sonr/pkg/styles/form"
|
||||
"github.com/onsonr/sonr/pkg/styles/layout"
|
||||
"github.com/onsonr/sonr/pkg/styles/text"
|
||||
"github.com/onsonr/nebula/ui/details"
|
||||
"github.com/onsonr/nebula/ui/form"
|
||||
"github.com/onsonr/nebula/ui/layout"
|
||||
"github.com/onsonr/nebula/ui/text"
|
||||
)
|
||||
|
||||
func ProfileFormView(turnstileSiteKey string) templ.Component {
|
||||
|
||||
@@ -2,8 +2,6 @@ package session
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
"github.com/labstack/echo/v4"
|
||||
"github.com/onsonr/sonr/pkg/common"
|
||||
@@ -12,6 +10,13 @@ import (
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
// HTTPContext is the context for HTTP endpoints.
|
||||
type HTTPContext struct {
|
||||
echo.Context
|
||||
db *gorm.DB
|
||||
sess *database.Session
|
||||
}
|
||||
|
||||
// Get returns the HTTPContext from the echo context
|
||||
func Get(c echo.Context) (*HTTPContext, error) {
|
||||
ctx, ok := c.(*HTTPContext)
|
||||
@@ -21,13 +26,6 @@ func Get(c echo.Context) (*HTTPContext, error) {
|
||||
return ctx, nil
|
||||
}
|
||||
|
||||
// HTTPContext is the context for HTTP endpoints.
|
||||
type HTTPContext struct {
|
||||
echo.Context
|
||||
db *gorm.DB
|
||||
sess *database.Session
|
||||
}
|
||||
|
||||
// NewHTTPContext creates a new session context
|
||||
func NewHTTPContext(c echo.Context, db *gorm.DB) *HTTPContext {
|
||||
return &HTTPContext{
|
||||
@@ -79,31 +77,3 @@ func (s *HTTPContext) getOrCreateSessionID() string {
|
||||
}
|
||||
return sessionID
|
||||
}
|
||||
|
||||
func extractBrowserInfo(c echo.Context) (string, string) {
|
||||
userAgent := common.HeaderRead(c, common.UserAgent)
|
||||
if userAgent == "" {
|
||||
return "N/A", "-1"
|
||||
}
|
||||
|
||||
var name, ver string
|
||||
entries := strings.Split(strings.TrimSpace(userAgent), ",")
|
||||
for _, entry := range entries {
|
||||
entry = strings.TrimSpace(entry)
|
||||
re := regexp.MustCompile(`"([^"]+)";v="([^"]+)"`)
|
||||
matches := re.FindStringSubmatch(entry)
|
||||
|
||||
if len(matches) == 3 {
|
||||
browserName := matches[1]
|
||||
version := matches[2]
|
||||
|
||||
if browserName != common.BrowserNameUnknown.String() &&
|
||||
browserName != common.BrowserNameChromium.String() {
|
||||
name = browserName
|
||||
ver = version
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
return name, ver
|
||||
}
|
||||
|
||||
@@ -1,7 +1,11 @@
|
||||
package session
|
||||
|
||||
import (
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
"github.com/labstack/echo/v4"
|
||||
"github.com/onsonr/sonr/pkg/common"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
@@ -17,3 +21,31 @@ func Middleware(db *gorm.DB) echo.MiddlewareFunc {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func extractBrowserInfo(c echo.Context) (string, string) {
|
||||
userAgent := common.HeaderRead(c, common.UserAgent)
|
||||
if userAgent == "" {
|
||||
return "N/A", "-1"
|
||||
}
|
||||
|
||||
var name, ver string
|
||||
entries := strings.Split(strings.TrimSpace(userAgent), ",")
|
||||
for _, entry := range entries {
|
||||
entry = strings.TrimSpace(entry)
|
||||
re := regexp.MustCompile(`"([^"]+)";v="([^"]+)"`)
|
||||
matches := re.FindStringSubmatch(entry)
|
||||
|
||||
if len(matches) == 3 {
|
||||
browserName := matches[1]
|
||||
version := matches[2]
|
||||
|
||||
if browserName != common.BrowserNameUnknown.String() &&
|
||||
browserName != common.BrowserNameChromium.String() {
|
||||
name = browserName
|
||||
ver = version
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
return name, ver
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user