Skip to content

Commit

Permalink
feat: rebuild Single sign-on system (#3649 close #3571)
Browse files Browse the repository at this point in the history
* rebuild single sign on system

* perf: use cache

* fix: codefactor check

---------

Co-authored-by: Andy Hsu <i@nn.ci>
  • Loading branch information
itsHenry35 and xhofe authored Mar 2, 2023
1 parent f442185 commit 603681f
Show file tree
Hide file tree
Showing 9 changed files with 237 additions and 155 deletions.
9 changes: 5 additions & 4 deletions internal/bootstrap/data/setting.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,11 @@ func InitialSettings() []model.SettingItem {
{Key: conf.MaxIndexDepth, Value: "20", Type: conf.TypeNumber, Group: model.INDEX, Flag: model.PRIVATE, Help: `max depth of index`},
{Key: conf.IndexProgress, Value: "{}", Type: conf.TypeText, Group: model.SINGLE, Flag: model.PRIVATE},

// GitHub settings
{Key: conf.GithubClientId, Value: "", Type: conf.TypeString, Group: model.GITHUB, Flag: model.PRIVATE},
{Key: conf.GithubClientSecrets, Value: "", Type: conf.TypeString, Group: model.GITHUB, Flag: model.PRIVATE},
{Key: conf.GithubLoginEnabled, Value: "false", Type: conf.TypeBool, Group: model.GITHUB, Flag: model.PUBLIC},
// SSO settings
{Key: conf.SSOClientId, Value: "", Type: conf.TypeString, Group: model.SSO, Flag: model.PRIVATE},
{Key: conf.SSOClientSecret, Value: "", Type: conf.TypeString, Group: model.SSO, Flag: model.PRIVATE},
{Key: conf.SSOLoginEnabled, Value: "false", Type: conf.TypeBool, Group: model.SSO, Flag: model.PUBLIC},
{Key: conf.SSOLoginplatform, Type: conf.TypeSelect, Options: "Github,Microsoft,Google,Dingtalk", Group: model.SSO, Flag: model.PUBLIC},

// qbittorrent settings
{Key: conf.QbittorrentUrl, Value: "http://admin:adminadmin@localhost:8080/", Type: conf.TypeString, Group: model.SINGLE, Flag: model.PRIVATE},
Expand Down
85 changes: 43 additions & 42 deletions internal/conf/const.go
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
package conf

const (
TypeString = "string"
TypeSelect = "select"
TypeBool = "bool"
TypeText = "text"
TypeNumber = "number"
TypeString = "string"
TypeSelect = "select"
TypeBool = "bool"
TypeText = "text"
TypeNumber = "number"
)

const (
// site
VERSION = "version"
SiteTitle = "site_title"
Announcement = "announcement"
AllowIndexed = "allow_indexed"
// site
VERSION = "version"
SiteTitle = "site_title"
Announcement = "announcement"
AllowIndexed = "allow_indexed"

Logo = "logo"
Favicon = "favicon"
MainColor = "main_color"
Logo = "logo"
Favicon = "favicon"
MainColor = "main_color"

// preview
TextTypes = "text_types"
AudioTypes = "audio_types"
VideoTypes = "video_types"
ImageTypes = "image_types"
ProxyTypes = "proxy_types"
ProxyIgnoreHeaders = "proxy_ignore_headers"
AudioAutoplay = "audio_autoplay"
VideoAutoplay = "video_autoplay"
// preview
TextTypes = "text_types"
AudioTypes = "audio_types"
VideoTypes = "video_types"
ImageTypes = "image_types"
ProxyTypes = "proxy_types"
ProxyIgnoreHeaders = "proxy_ignore_headers"
AudioAutoplay = "audio_autoplay"
VideoAutoplay = "video_autoplay"

// global
HideFiles = "hide_files"
Expand All @@ -39,36 +39,37 @@ const (
OcrApi = "ocr_api"
FilenameCharMapping = "filename_char_mapping"
ForwardDirectLinkParams = "forward_direct_link_params"

// index
SearchIndex = "search_index"
AutoUpdateIndex = "auto_update_index"
IgnorePaths = "ignore_paths"
MaxIndexDepth = "max_index_depth"

// aria2
Aria2Uri = "aria2_uri"
Aria2Secret = "aria2_secret"
// aria2
Aria2Uri = "aria2_uri"
Aria2Secret = "aria2_secret"

// single
Token = "token"
IndexProgress = "index_progress"
// single
Token = "token"
IndexProgress = "index_progress"

//Github
GithubClientId = "github_client_id"
GithubClientSecrets = "github_client_secrets"
GithubLoginEnabled = "github_login_enabled"
//SSO
SSOClientId = "sso_client_id"
SSOClientSecret = "sso_client_secret"
SSOLoginEnabled = "sso_login_enabled"
SSOLoginplatform = "sso_login_platform"

// qbittorrent
QbittorrentUrl = "qbittorrent_url"
// qbittorrent
QbittorrentUrl = "qbittorrent_url"
)

const (
UNKNOWN = iota
FOLDER
//OFFICE
VIDEO
AUDIO
TEXT
IMAGE
UNKNOWN = iota
FOLDER
//OFFICE
VIDEO
AUDIO
TEXT
IMAGE
)
6 changes: 3 additions & 3 deletions internal/db/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ func GetUserByName(username string) (*model.User, error) {
return &user, nil
}

func GetUserByGithubID(githubID int) (*model.User, error) {
user := model.User{GithubID: githubID}
func GetUserBySSOID(ssoID string) (*model.User, error) {
user := model.User{SsoID: ssoID}
if err := db.Where(user).First(&user).Error; err != nil {
return nil, errors.Wrapf(err, "The Github ID is not associated with a user")
return nil, errors.Wrapf(err, "The single sign on platform is not bound to any users")
}
return &user, nil
}
Expand Down
2 changes: 1 addition & 1 deletion internal/model/setting.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const (
GLOBAL
ARIA2
INDEX
GITHUB
SSO
)

const (
Expand Down
2 changes: 1 addition & 1 deletion internal/model/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ type User struct {
// 10: can add qbittorrent tasks
Permission int32 `json:"permission"`
OtpSecret string `json:"-"`
GithubID int `json:"github_id"`
SsoID string `json:"sso_id"`
}

func (u User) IsGuest() bool {
Expand Down
2 changes: 1 addition & 1 deletion server/handles/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func UpdateCurrent(c *gin.Context) {
if req.Password != "" {
user.Password = req.Password
}
user.GithubID = req.GithubID
user.SsoID = req.SsoID
if err := op.UpdateUser(user); err != nil {
common.ErrorResp(c, err, 500)
} else {
Expand Down
101 changes: 0 additions & 101 deletions server/handles/githublogin.go

This file was deleted.

Loading

0 comments on commit 603681f

Please sign in to comment.