mirror of
https://github.com/snowykami/neo-blog.git
synced 2025-09-04 00:06:22 +00:00
feat: create random labels page feat: implement login page with OpenID Connect support feat: add Gravatar component for user avatars feat: create Navbar component with navigation menu chore: create Sidebar component placeholder feat: implement login form with OIDC and email/password options feat: add reusable button component feat: create card component for structured content display feat: implement input component for forms feat: create label component for form labels feat: add navigation menu component for site navigation chore: add configuration file for site metadata feat: implement device context for responsive design feat: add utility functions for class name management feat: define OIDC configuration model feat: define base response model for API responses feat: define user model for user data feat: implement i18n for internationalization support feat: add English and Chinese translations for login chore: create index for locale resources chore: add blog home view placeholder
70 lines
1.7 KiB
Go
70 lines
1.7 KiB
Go
package repo
|
|
|
|
import (
|
|
"github.com/snowykami/neo-blog/internal/model"
|
|
"github.com/snowykami/neo-blog/pkg/errs"
|
|
"net/http"
|
|
)
|
|
|
|
type oidcRepo struct {
|
|
}
|
|
|
|
var Oidc = &oidcRepo{}
|
|
|
|
func (o *oidcRepo) CreateOidcConfig(oidcConfig *model.OidcConfig) error {
|
|
if err := GetDB().Create(oidcConfig).Error; err != nil {
|
|
return err
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (o *oidcRepo) DeleteOidcConfig(id string) error {
|
|
if id == "" {
|
|
return errs.New(http.StatusBadRequest, "invalid OIDC config ID", nil)
|
|
}
|
|
if err := GetDB().Where("id = ?", id).Delete(&model.OidcConfig{}).Error; err != nil {
|
|
return err
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (o *oidcRepo) ListOidcConfigs(onlyEnabled bool) ([]model.OidcConfig, error) {
|
|
var configs []model.OidcConfig
|
|
if onlyEnabled {
|
|
if err := GetDB().Where("enabled = ?", true).Find(&configs).Error; err != nil {
|
|
return nil, err
|
|
}
|
|
} else {
|
|
if err := GetDB().Find(&configs).Error; err != nil {
|
|
return nil, err
|
|
}
|
|
}
|
|
return configs, nil
|
|
}
|
|
|
|
func (o *oidcRepo) GetOidcConfigByName(name string) (*model.OidcConfig, error) {
|
|
var config model.OidcConfig
|
|
if err := GetDB().Where("name = ?", name).First(&config).Error; err != nil {
|
|
return nil, err
|
|
}
|
|
return &config, nil
|
|
}
|
|
|
|
func (o *oidcRepo) GetOidcConfigByID(id string) (*model.OidcConfig, error) {
|
|
var config model.OidcConfig
|
|
if err := GetDB().Where("id = ?", id).First(&config).Error; err != nil {
|
|
return nil, err
|
|
}
|
|
return &config, nil
|
|
}
|
|
|
|
func (o *oidcRepo) UpdateOidcConfig(oidcConfig *model.OidcConfig) error {
|
|
if oidcConfig.ID == 0 {
|
|
return errs.New(http.StatusBadRequest, "invalid OIDC config ID", nil)
|
|
}
|
|
if err := GetDB().Select("Enabled").Updates(oidcConfig).Error; err != nil {
|
|
return err
|
|
}
|
|
return nil
|
|
}
|