31 lines
708 B
Go
31 lines
708 B
Go
package oauth
|
|
|
|
import (
|
|
"code.mrmelon54.com/melon/summer/pkg/utils"
|
|
"net/http"
|
|
"xorm.io/xorm"
|
|
)
|
|
|
|
type AuthNamespace struct {
|
|
Id uint64 `xorm:"pk autoincr"`
|
|
BaseDomain string
|
|
AuthDomain string
|
|
WebsiteTitle string
|
|
}
|
|
|
|
func GetNamespaceByDomain(db *xorm.Engine, h string) (AuthNamespace, bool) {
|
|
var n AuthNamespace
|
|
b, err := db.Where("base_domain = ? or auth_domain = ?", h, h).Get(&n)
|
|
if err == nil && b {
|
|
return n, true
|
|
}
|
|
return AuthNamespace{}, false
|
|
}
|
|
|
|
func GetNamespaceByRequest(db *xorm.Engine, req *http.Request) (AuthNamespace, bool) {
|
|
if domain, ok := utils.GetDomainWithoutPort(req.Host); ok {
|
|
return GetNamespaceByDomain(db, domain)
|
|
}
|
|
return AuthNamespace{}, false
|
|
}
|