mirror of
https://github.com/KaySar12/NextZen-UserService.git
synced 2025-10-06 19:59:42 +07:00
update
This commit is contained in:
+22
-2
@@ -7,20 +7,38 @@ import (
|
||||
"net/http"
|
||||
|
||||
model2 "github.com/IceWhaleTech/CasaOS-UserService/service/model"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type AuthentikService interface {
|
||||
GetUserInfo(accessToken string, baseURL string) (model2.AuthentikUser, error)
|
||||
GetUserApp(accessToken string, baseURL string) (model2.AuthentikApplication, error)
|
||||
CreateCredential(m model2.AuthentikCredentialsDBModel) model2.AuthentikCredentialsDBModel
|
||||
UpdateCredential(m model2.AuthentikCredentialsDBModel) model2.AuthentikCredentialsDBModel
|
||||
GetCredential(id int) model2.AuthentikCredentialsDBModel
|
||||
}
|
||||
|
||||
type authentikService struct {
|
||||
db *gorm.DB
|
||||
}
|
||||
|
||||
var (
|
||||
APICorePrefix = "/api/v3/core"
|
||||
)
|
||||
|
||||
func (a *authentikService) CreateCredential(m model2.AuthentikCredentialsDBModel) model2.AuthentikCredentialsDBModel {
|
||||
a.db.Create(&m)
|
||||
return m
|
||||
}
|
||||
func (a *authentikService) UpdateCredential(m model2.AuthentikCredentialsDBModel) model2.AuthentikCredentialsDBModel {
|
||||
a.db.Model(&m).Where("id = ?", m.Id).Updates(m)
|
||||
return m
|
||||
}
|
||||
func (a *authentikService) GetCredential(id int) model2.AuthentikCredentialsDBModel {
|
||||
var m model2.AuthentikCredentialsDBModel
|
||||
a.db.Limit(1).Where("id = ?", id).First(&m)
|
||||
return m
|
||||
}
|
||||
func (a *authentikService) GetUserApp(accessToken string, baseURL string) (model2.AuthentikApplication, error) {
|
||||
bearer := "Bearer " + accessToken
|
||||
path := baseURL + APICorePrefix + "/applications/"
|
||||
@@ -93,6 +111,8 @@ func (a *authentikService) GetUserInfo(accessToken string, baseURL string) (mode
|
||||
|
||||
return user, nil
|
||||
}
|
||||
func NewAuthentikService() AuthentikService {
|
||||
return &authentikService{}
|
||||
func NewAuthentikService(db *gorm.DB) AuthentikService {
|
||||
return &authentikService{
|
||||
db: db,
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -8,7 +8,7 @@ import (
|
||||
)
|
||||
|
||||
type EventService interface {
|
||||
CreateEvemt(m model.EventModel) model.EventModel
|
||||
CreateEvent(m model.EventModel) model.EventModel
|
||||
GetEvents() (list []model.EventModel)
|
||||
GetEventByUUID(uuid string) (m model.EventModel)
|
||||
DeleteEvent(uuid string)
|
||||
@@ -19,7 +19,7 @@ type eventService struct {
|
||||
db *gorm.DB
|
||||
}
|
||||
|
||||
func (e *eventService) CreateEvemt(m model.EventModel) model.EventModel {
|
||||
func (e *eventService) CreateEvent(m model.EventModel) model.EventModel {
|
||||
e.db.Create(&m)
|
||||
return m
|
||||
}
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
package model
|
||||
|
||||
import "time"
|
||||
|
||||
// Soon to be removed
|
||||
type AuthentikCredentialsDBModel struct {
|
||||
Id int `gorm:"column:id;primary_key" json:"id"`
|
||||
ClientID string `json:"clientId"`
|
||||
ClientSecret string `json:"clientSecret"`
|
||||
Server string `json:"server"`
|
||||
CreatedAt time.Time `gorm:"<-:create;autoCreateTime" json:"created_at,omitempty"`
|
||||
UpdatedAt time.Time `gorm:"<-:create;<-:update;autoUpdateTime" json:"updated_at,omitempty"`
|
||||
}
|
||||
|
||||
func (p *AuthentikCredentialsDBModel) TableName() string {
|
||||
return "o_authentik_credentials"
|
||||
}
|
||||
+1
-1
@@ -30,7 +30,7 @@ func NewService(db *gorm.DB, RuntimePath string) Repository {
|
||||
user: NewUserService(db),
|
||||
event: NewEventService(db),
|
||||
omv: NewOMVService(),
|
||||
authentik: NewAuthentikService(),
|
||||
authentik: NewAuthentikService(db),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user