mirror of
https://github.com/casdoor/casdoor.git
synced 2025-08-16 20:40:45 +08:00
Compare commits
67 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
bfe8e5f3e7 | ||
![]() |
702ee6acd0 | ||
![]() |
0a9587901a | ||
![]() |
577bd6ce58 | ||
![]() |
3c4112dd44 | ||
![]() |
b7a37126ad | ||
![]() |
8669d5bb0d | ||
![]() |
aee3ea4981 | ||
![]() |
516f4b7569 | ||
![]() |
7d7ca10481 | ||
![]() |
a9d4978a0f | ||
![]() |
09f40bb5ce | ||
![]() |
a6f803aff1 | ||
![]() |
fc9528be43 | ||
![]() |
58e8f9f90b | ||
![]() |
e850e33f37 | ||
![]() |
d7110ff8bf | ||
![]() |
f923a8f0d7 | ||
![]() |
7bfb74ba18 | ||
![]() |
38f031bc86 | ||
![]() |
5c441d195c | ||
![]() |
0639564d27 | ||
![]() |
6c647818ca | ||
![]() |
8bc73d17aa | ||
![]() |
1f37c80177 | ||
![]() |
7924fca403 | ||
![]() |
bd06996bab | ||
![]() |
19ab168b12 | ||
![]() |
854a74b73e | ||
![]() |
beefb0b432 | ||
![]() |
d8969e6652 | ||
![]() |
666ff48837 | ||
![]() |
0a0c1b4788 | ||
![]() |
438c999e11 | ||
![]() |
a193ceb33d | ||
![]() |
caec1d1bac | ||
![]() |
0d48da24dc | ||
![]() |
de9eeaa1ef | ||
![]() |
ae6e35ee73 | ||
![]() |
a58df645bf | ||
![]() |
68417a2d7a | ||
![]() |
9511fae9d9 | ||
![]() |
347d3d2b53 | ||
![]() |
6edfc08b28 | ||
![]() |
bc1c4d32f0 | ||
![]() |
96250aa70a | ||
![]() |
3d4ca1adb1 | ||
![]() |
ba97458edd | ||
![]() |
855259c6e7 | ||
![]() |
28297e06f7 | ||
![]() |
f3aed0b6a8 | ||
![]() |
35e1f8538e | ||
![]() |
30a14ff54a | ||
![]() |
1ab7a54133 | ||
![]() |
0e2dad35f3 | ||
![]() |
d31077a510 | ||
![]() |
eee9b8b9fe | ||
![]() |
91cb5f393a | ||
![]() |
807aea5ec7 | ||
![]() |
1c42b6e395 | ||
![]() |
49a73f8138 | ||
![]() |
55784c68a3 | ||
![]() |
8080b10b3b | ||
![]() |
cd7589775c | ||
![]() |
0a8c2a35fe | ||
![]() |
d1e734e4ce | ||
![]() |
68f032b54d |
@@ -37,8 +37,8 @@
|
|||||||
<a href="https://crowdin.com/project/casdoor-site">
|
<a href="https://crowdin.com/project/casdoor-site">
|
||||||
<img alt="Crowdin" src="https://badges.crowdin.net/casdoor-site/localized.svg">
|
<img alt="Crowdin" src="https://badges.crowdin.net/casdoor-site/localized.svg">
|
||||||
</a>
|
</a>
|
||||||
<a href="https://gitter.im/casbin/casdoor">
|
<a href="https://discord.gg/5rPsrAzK7S">
|
||||||
<img alt="Gitter" src="https://badges.gitter.im/casbin/casdoor.svg">
|
<img alt="Discord" src="https://img.shields.io/discord/1022748306096537660?style=flat-square&logo=discord&label=discord&color=5865F2">
|
||||||
</a>
|
</a>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
@@ -71,7 +71,7 @@ https://casdoor.org/docs/category/integrations
|
|||||||
|
|
||||||
## How to contact?
|
## How to contact?
|
||||||
|
|
||||||
- Gitter: https://gitter.im/casbin/casdoor
|
- Discord: https://discord.gg/5rPsrAzK7S
|
||||||
- Forum: https://forum.casbin.com
|
- Forum: https://forum.casbin.com
|
||||||
- Contact: https://tawk.to/chat/623352fea34c2456412b8c51/1fuc7od6e
|
- Contact: https://tawk.to/chat/623352fea34c2456412b8c51/1fuc7od6e
|
||||||
|
|
||||||
|
2
ai/ai.go
2
ai/ai.go
@@ -129,7 +129,7 @@ func QueryAnswerStream(authToken string, question string, writer io.Writer, buil
|
|||||||
fmt.Printf("%s", data)
|
fmt.Printf("%s", data)
|
||||||
|
|
||||||
// Write the streamed data as Server-Sent Events
|
// Write the streamed data as Server-Sent Events
|
||||||
if _, err = fmt.Fprintf(writer, "data: %s\n\n", data); err != nil {
|
if _, err = fmt.Fprintf(writer, "event: message\ndata: %s\n\n", data); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
flusher.Flush()
|
flusher.Flush()
|
||||||
|
@@ -368,9 +368,11 @@ func (c *ApiController) GetAccount() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
user.Permissions = object.GetMaskedPermissions(user.Permissions)
|
if user != nil {
|
||||||
user.Roles = object.GetMaskedRoles(user.Roles)
|
user.Permissions = object.GetMaskedPermissions(user.Permissions)
|
||||||
user.MultiFactorAuths = object.GetAllMfaProps(user, true)
|
user.Roles = object.GetMaskedRoles(user.Roles)
|
||||||
|
user.MultiFactorAuths = object.GetAllMfaProps(user, true)
|
||||||
|
}
|
||||||
|
|
||||||
organization, err := object.GetMaskedOrganization(object.GetOrganizationByUser(user))
|
organization, err := object.GetMaskedOrganization(object.GetOrganizationByUser(user))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -378,7 +380,8 @@ func (c *ApiController) GetAccount() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
u, err := object.GetMaskedUser(user)
|
isAdminOrSelf := c.IsAdminOrSelf(user)
|
||||||
|
u, err := object.GetMaskedUser(user, isAdminOrSelf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.ResponseError(err.Error())
|
c.ResponseError(err.Error())
|
||||||
return
|
return
|
||||||
|
@@ -48,24 +48,24 @@ func (c *ApiController) GetApplications() {
|
|||||||
} else {
|
} else {
|
||||||
applications, err = object.GetOrganizationApplications(owner, organization)
|
applications, err = object.GetOrganizationApplications(owner, organization)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
c.ResponseError(err.Error())
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
c.ResponseOk(object.GetMaskedApplications(applications, userId))
|
||||||
c.Data["json"] = object.GetMaskedApplications(applications, userId)
|
|
||||||
c.ServeJSON()
|
|
||||||
} else {
|
} else {
|
||||||
limit := util.ParseInt(limit)
|
limit := util.ParseInt(limit)
|
||||||
count, err := object.GetApplicationCount(owner, field, value)
|
count, err := object.GetApplicationCount(owner, field, value)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
c.ResponseError(err.Error())
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
paginator := pagination.SetPaginator(c.Ctx, limit, count)
|
paginator := pagination.SetPaginator(c.Ctx, limit, count)
|
||||||
app, err := object.GetPaginationApplications(owner, paginator.Offset(), limit, field, value, sortField, sortOrder)
|
app, err := object.GetPaginationApplications(owner, paginator.Offset(), limit, field, value, sortField, sortOrder)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
c.ResponseError(err.Error())
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
applications := object.GetMaskedApplications(app, userId)
|
applications := object.GetMaskedApplications(app, userId)
|
||||||
@@ -83,13 +83,14 @@ func (c *ApiController) GetApplications() {
|
|||||||
func (c *ApiController) GetApplication() {
|
func (c *ApiController) GetApplication() {
|
||||||
userId := c.GetSessionUsername()
|
userId := c.GetSessionUsername()
|
||||||
id := c.Input().Get("id")
|
id := c.Input().Get("id")
|
||||||
|
|
||||||
app, err := object.GetApplication(id)
|
app, err := object.GetApplication(id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
c.ResponseError(err.Error())
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
c.Data["json"] = object.GetMaskedApplication(app, userId)
|
c.ResponseOk(object.GetMaskedApplication(app, userId))
|
||||||
c.ServeJSON()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetUserApplication
|
// GetUserApplication
|
||||||
@@ -102,23 +103,24 @@ func (c *ApiController) GetApplication() {
|
|||||||
func (c *ApiController) GetUserApplication() {
|
func (c *ApiController) GetUserApplication() {
|
||||||
userId := c.GetSessionUsername()
|
userId := c.GetSessionUsername()
|
||||||
id := c.Input().Get("id")
|
id := c.Input().Get("id")
|
||||||
|
|
||||||
user, err := object.GetUser(id)
|
user, err := object.GetUser(id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
c.ResponseError(err.Error())
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if user == nil {
|
if user == nil {
|
||||||
c.ResponseError(fmt.Sprintf(c.T("general:The user: %s doesn't exist"), id))
|
c.ResponseError(fmt.Sprintf(c.T("general:The user: %s doesn't exist"), id))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
app, err := object.GetApplicationByUser(user)
|
application, err := object.GetApplicationByUser(user)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
c.ResponseError(err.Error())
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
c.Data["json"] = object.GetMaskedApplication(app, userId)
|
c.ResponseOk(object.GetMaskedApplication(application, userId))
|
||||||
c.ServeJSON()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetOrganizationApplications
|
// GetOrganizationApplications
|
||||||
@@ -147,11 +149,11 @@ func (c *ApiController) GetOrganizationApplications() {
|
|||||||
if limit == "" || page == "" {
|
if limit == "" || page == "" {
|
||||||
applications, err := object.GetOrganizationApplications(owner, organization)
|
applications, err := object.GetOrganizationApplications(owner, organization)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
c.ResponseError(err.Error())
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
c.Data["json"] = object.GetMaskedApplications(applications, userId)
|
c.ResponseOk(object.GetMaskedApplications(applications, userId))
|
||||||
c.ServeJSON()
|
|
||||||
} else {
|
} else {
|
||||||
limit := util.ParseInt(limit)
|
limit := util.ParseInt(limit)
|
||||||
|
|
||||||
|
@@ -69,10 +69,13 @@ func (c *ApiController) HandleLoggedIn(application *object.Application, user *ob
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if form.Password != "" && user.IsMfaEnabled() {
|
// check user's tag
|
||||||
c.setMfaSessionData(&object.MfaSessionData{UserId: userId})
|
if !user.IsGlobalAdmin && !user.IsAdmin && len(application.Tags) > 0 {
|
||||||
resp = &Response{Status: object.NextMfa, Data: user.GetPreferredMfaProps(true)}
|
// only users with the tag that is listed in the application tags can login
|
||||||
return
|
if !util.InSlice(application.Tags, user.Tag) {
|
||||||
|
c.ResponseError(fmt.Sprintf(c.T("auth:User's tag: %s is not listed in the application's tags"), user.Tag))
|
||||||
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if form.Type == ResponseTypeLogin {
|
if form.Type == ResponseTypeLogin {
|
||||||
@@ -120,6 +123,11 @@ func (c *ApiController) HandleLoggedIn(application *object.Application, user *ob
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
resp = &Response{Status: "ok", Msg: "", Data: res, Data2: map[string]string{"redirectUrl": redirectUrl, "method": method}}
|
resp = &Response{Status: "ok", Msg: "", Data: res, Data2: map[string]string{"redirectUrl": redirectUrl, "method": method}}
|
||||||
|
|
||||||
|
if application.EnableSigninSession || application.HasPromptPage() {
|
||||||
|
// The prompt page needs the user to be signed in
|
||||||
|
c.SetSessionUsername(userId)
|
||||||
|
}
|
||||||
} else if form.Type == ResponseTypeCas {
|
} else if form.Type == ResponseTypeCas {
|
||||||
// not oauth but CAS SSO protocol
|
// not oauth but CAS SSO protocol
|
||||||
service := c.Input().Get("service")
|
service := c.Input().Get("service")
|
||||||
@@ -132,11 +140,11 @@ func (c *ApiController) HandleLoggedIn(application *object.Application, user *ob
|
|||||||
resp.Data = st
|
resp.Data = st
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if application.EnableSigninSession || application.HasPromptPage() {
|
if application.EnableSigninSession || application.HasPromptPage() {
|
||||||
// The prompt page needs the user to be signed in
|
// The prompt page needs the user to be signed in
|
||||||
c.SetSessionUsername(userId)
|
c.SetSessionUsername(userId)
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
resp = wrapErrorResponse(fmt.Errorf("unknown response type: %s", form.Type))
|
resp = wrapErrorResponse(fmt.Errorf("unknown response type: %s", form.Type))
|
||||||
}
|
}
|
||||||
@@ -238,7 +246,7 @@ func isProxyProviderType(providerType string) bool {
|
|||||||
// @Param code_challenge_method query string false code_challenge_method
|
// @Param code_challenge_method query string false code_challenge_method
|
||||||
// @Param code_challenge query string false code_challenge
|
// @Param code_challenge query string false code_challenge
|
||||||
// @Param form body controllers.AuthForm true "Login information"
|
// @Param form body controllers.AuthForm true "Login information"
|
||||||
// @Success 200 {object} Response The Response object
|
// @Success 200 {object} controllers.Response The Response object
|
||||||
// @router /login [post]
|
// @router /login [post]
|
||||||
func (c *ApiController) Login() {
|
func (c *ApiController) Login() {
|
||||||
resp := &Response{}
|
resp := &Response{}
|
||||||
@@ -344,17 +352,26 @@ func (c *ApiController) Login() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
resp = c.HandleLoggedIn(application, user, &authForm)
|
|
||||||
|
|
||||||
organization, err := object.GetOrganizationByUser(user)
|
organization, err := object.GetOrganizationByUser(user)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.ResponseError(err.Error())
|
c.ResponseError(err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
if user != nil && organization.HasRequiredMfa() && !user.IsMfaEnabled() {
|
if object.IsNeedPromptMfa(organization, user) {
|
||||||
resp.Msg = object.RequiredMfa
|
// The prompt page needs the user to be signed in
|
||||||
|
c.SetSessionUsername(user.GetId())
|
||||||
|
c.ResponseOk(object.RequiredMfa)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if user.IsMfaEnabled() {
|
||||||
|
c.setMfaUserSession(user.GetId())
|
||||||
|
c.ResponseOk(object.NextMfa, user.GetPreferredMfaProps(true))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
resp = c.HandleLoggedIn(application, user, &authForm)
|
||||||
|
|
||||||
record := object.NewRecord(c.Ctx)
|
record := object.NewRecord(c.Ctx)
|
||||||
record.Organization = application.Organization
|
record.Organization = application.Organization
|
||||||
record.User = user.Name
|
record.User = user.Name
|
||||||
@@ -405,17 +422,10 @@ func (c *ApiController) Login() {
|
|||||||
c.ResponseError(err.Error())
|
c.ResponseError(err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
} else if provider.Category == "OAuth" {
|
} else if provider.Category == "OAuth" || provider.Category == "Web3" {
|
||||||
// OAuth
|
// OAuth
|
||||||
|
idpInfo := object.FromProviderToIdpInfo(c.Ctx, provider)
|
||||||
clientId := provider.ClientId
|
idProvider := idp.GetIdProvider(idpInfo, authForm.RedirectUri)
|
||||||
clientSecret := provider.ClientSecret
|
|
||||||
if provider.Type == "WeChat" && strings.Contains(c.Ctx.Request.UserAgent(), "MicroMessenger") {
|
|
||||||
clientId = provider.ClientId2
|
|
||||||
clientSecret = provider.ClientSecret2
|
|
||||||
}
|
|
||||||
|
|
||||||
idProvider := idp.GetIdProvider(provider.Type, provider.SubType, clientId, clientSecret, provider.AppId, authForm.RedirectUri, provider.Domain, provider.CustomAuthUrl, provider.CustomTokenUrl, provider.CustomUserInfoUrl)
|
|
||||||
if idProvider == nil {
|
if idProvider == nil {
|
||||||
c.ResponseError(fmt.Sprintf(c.T("storage:The provider type: %s is not supported"), provider.Type))
|
c.ResponseError(fmt.Sprintf(c.T("storage:The provider type: %s is not supported"), provider.Type))
|
||||||
return
|
return
|
||||||
@@ -455,7 +465,7 @@ func (c *ApiController) Login() {
|
|||||||
c.ResponseError(err.Error())
|
c.ResponseError(err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
} else if provider.Category == "OAuth" {
|
} else if provider.Category == "OAuth" || provider.Category == "Web3" {
|
||||||
user, err = object.GetUserByField(application.Organization, provider.Type, userInfo.Id)
|
user, err = object.GetUserByField(application.Organization, provider.Type, userInfo.Id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.ResponseError(err.Error())
|
c.ResponseError(err.Error())
|
||||||
@@ -476,7 +486,7 @@ func (c *ApiController) Login() {
|
|||||||
record.Organization = application.Organization
|
record.Organization = application.Organization
|
||||||
record.User = user.Name
|
record.User = user.Name
|
||||||
util.SafeGoroutine(func() { object.AddRecord(record) })
|
util.SafeGoroutine(func() { object.AddRecord(record) })
|
||||||
} else if provider.Category == "OAuth" {
|
} else if provider.Category == "OAuth" || provider.Category == "Web3" {
|
||||||
// Sign up via OAuth
|
// Sign up via OAuth
|
||||||
if application.EnableLinkWithEmail {
|
if application.EnableLinkWithEmail {
|
||||||
if userInfo.Email != "" {
|
if userInfo.Email != "" {
|
||||||
@@ -647,13 +657,16 @@ func (c *ApiController) Login() {
|
|||||||
resp = &Response{Status: "error", Msg: "Failed to link user account", Data: isLinked}
|
resp = &Response{Status: "error", Msg: "Failed to link user account", Data: isLinked}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if c.getMfaSessionData() != nil {
|
} else if c.getMfaUserSession() != "" {
|
||||||
mfaSession := c.getMfaSessionData()
|
user, err := object.GetUser(c.getMfaUserSession())
|
||||||
user, err := object.GetUser(mfaSession.UserId)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.ResponseError(err.Error())
|
c.ResponseError(err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if user == nil {
|
||||||
|
c.ResponseError("expired user session")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
if authForm.Passcode != "" {
|
if authForm.Passcode != "" {
|
||||||
mfaUtil := object.GetMfaUtil(authForm.MfaType, user.GetPreferredMfaProps(false))
|
mfaUtil := object.GetMfaUtil(authForm.MfaType, user.GetPreferredMfaProps(false))
|
||||||
@@ -667,13 +680,15 @@ func (c *ApiController) Login() {
|
|||||||
c.ResponseError(err.Error())
|
c.ResponseError(err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
} else if authForm.RecoveryCode != "" {
|
||||||
if authForm.RecoveryCode != "" {
|
|
||||||
err = object.MfaRecover(user, authForm.RecoveryCode)
|
err = object.MfaRecover(user, authForm.RecoveryCode)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.ResponseError(err.Error())
|
c.ResponseError(err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
c.ResponseError("missing passcode or recovery code")
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
application, err := object.GetApplication(fmt.Sprintf("admin/%s", authForm.Application))
|
application, err := object.GetApplication(fmt.Sprintf("admin/%s", authForm.Application))
|
||||||
@@ -688,6 +703,7 @@ func (c *ApiController) Login() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
resp = c.HandleLoggedIn(application, user, &authForm)
|
resp = c.HandleLoggedIn(application, user, &authForm)
|
||||||
|
c.setMfaUserSession("")
|
||||||
|
|
||||||
record := object.NewRecord(c.Ctx)
|
record := object.NewRecord(c.Ctx)
|
||||||
record.Organization = application.Organization
|
record.Organization = application.Organization
|
||||||
@@ -756,7 +772,8 @@ func (c *ApiController) HandleSamlLogin() {
|
|||||||
func (c *ApiController) HandleOfficialAccountEvent() {
|
func (c *ApiController) HandleOfficialAccountEvent() {
|
||||||
respBytes, err := ioutil.ReadAll(c.Ctx.Request.Body)
|
respBytes, err := ioutil.ReadAll(c.Ctx.Request.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
c.ResponseError(err.Error())
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
var data struct {
|
var data struct {
|
||||||
@@ -766,7 +783,8 @@ func (c *ApiController) HandleOfficialAccountEvent() {
|
|||||||
}
|
}
|
||||||
err = xml.Unmarshal(respBytes, &data)
|
err = xml.Unmarshal(respBytes, &data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
c.ResponseError(err.Error())
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
lock.Lock()
|
lock.Lock()
|
||||||
|
@@ -55,6 +55,18 @@ func (c *ApiController) IsAdmin() bool {
|
|||||||
return isGlobalAdmin || user.IsAdmin
|
return isGlobalAdmin || user.IsAdmin
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *ApiController) IsAdminOrSelf(user2 *object.User) bool {
|
||||||
|
isGlobalAdmin, user := c.isGlobalAdmin()
|
||||||
|
if isGlobalAdmin || (user != nil && user.IsAdmin) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
if user.Owner == user2.Owner && user.Name == user2.Name {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
func (c *ApiController) isGlobalAdmin() (bool, *object.User) {
|
func (c *ApiController) isGlobalAdmin() (bool, *object.User) {
|
||||||
username := c.GetSessionUsername()
|
username := c.GetSessionUsername()
|
||||||
if strings.HasPrefix(username, "app/") {
|
if strings.HasPrefix(username, "app/") {
|
||||||
@@ -79,7 +91,8 @@ func (c *ApiController) getCurrentUser() *object.User {
|
|||||||
} else {
|
} else {
|
||||||
user, err = object.GetUser(userId)
|
user, err = object.GetUser(userId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
c.ResponseError(err.Error())
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return user
|
return user
|
||||||
@@ -112,7 +125,8 @@ func (c *ApiController) GetSessionApplication() *object.Application {
|
|||||||
}
|
}
|
||||||
application, err := object.GetApplicationByClientId(clientId.(string))
|
application, err := object.GetApplicationByClientId(clientId.(string))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
c.ResponseError(err.Error())
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
return application
|
return application
|
||||||
@@ -176,24 +190,16 @@ func (c *ApiController) SetSessionData(s *SessionData) {
|
|||||||
c.SetSession("SessionData", util.StructToJson(s))
|
c.SetSession("SessionData", util.StructToJson(s))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *ApiController) setMfaSessionData(data *object.MfaSessionData) {
|
func (c *ApiController) setMfaUserSession(userId string) {
|
||||||
if data == nil {
|
c.SetSession(object.MfaSessionUserId, userId)
|
||||||
c.SetSession(object.MfaSessionUserId, nil)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
c.SetSession(object.MfaSessionUserId, data.UserId)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *ApiController) getMfaSessionData() *object.MfaSessionData {
|
func (c *ApiController) getMfaUserSession() string {
|
||||||
userId := c.GetSession(object.MfaSessionUserId)
|
userId := c.Ctx.Input.CruSession.Get(object.MfaSessionUserId)
|
||||||
if userId == nil {
|
if userId == nil {
|
||||||
return nil
|
return ""
|
||||||
}
|
}
|
||||||
|
return userId.(string)
|
||||||
data := &object.MfaSessionData{
|
|
||||||
UserId: userId.(string),
|
|
||||||
}
|
|
||||||
return data
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *ApiController) setExpireForSession() {
|
func (c *ApiController) setExpireForSession() {
|
||||||
|
@@ -41,22 +41,24 @@ func (c *ApiController) GetCerts() {
|
|||||||
if limit == "" || page == "" {
|
if limit == "" || page == "" {
|
||||||
maskedCerts, err := object.GetMaskedCerts(object.GetCerts(owner))
|
maskedCerts, err := object.GetMaskedCerts(object.GetCerts(owner))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
c.ResponseError(err.Error())
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
c.Data["json"] = maskedCerts
|
c.ResponseOk(maskedCerts)
|
||||||
c.ServeJSON()
|
|
||||||
} else {
|
} else {
|
||||||
limit := util.ParseInt(limit)
|
limit := util.ParseInt(limit)
|
||||||
count, err := object.GetCertCount(owner, field, value)
|
count, err := object.GetCertCount(owner, field, value)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
c.ResponseError(err.Error())
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
paginator := pagination.SetPaginator(c.Ctx, limit, count)
|
paginator := pagination.SetPaginator(c.Ctx, limit, count)
|
||||||
certs, err := object.GetMaskedCerts(object.GetPaginationCerts(owner, paginator.Offset(), limit, field, value, sortField, sortOrder))
|
certs, err := object.GetMaskedCerts(object.GetPaginationCerts(owner, paginator.Offset(), limit, field, value, sortField, sortOrder))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
c.ResponseError(err.Error())
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
c.ResponseOk(certs, paginator.Nums())
|
c.ResponseOk(certs, paginator.Nums())
|
||||||
@@ -80,22 +82,24 @@ func (c *ApiController) GetGlobleCerts() {
|
|||||||
if limit == "" || page == "" {
|
if limit == "" || page == "" {
|
||||||
maskedCerts, err := object.GetMaskedCerts(object.GetGlobleCerts())
|
maskedCerts, err := object.GetMaskedCerts(object.GetGlobleCerts())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
c.ResponseError(err.Error())
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
c.Data["json"] = maskedCerts
|
c.ResponseOk(maskedCerts)
|
||||||
c.ServeJSON()
|
|
||||||
} else {
|
} else {
|
||||||
limit := util.ParseInt(limit)
|
limit := util.ParseInt(limit)
|
||||||
count, err := object.GetGlobalCertsCount(field, value)
|
count, err := object.GetGlobalCertsCount(field, value)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
c.ResponseError(err.Error())
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
paginator := pagination.SetPaginator(c.Ctx, limit, count)
|
paginator := pagination.SetPaginator(c.Ctx, limit, count)
|
||||||
certs, err := object.GetMaskedCerts(object.GetPaginationGlobalCerts(paginator.Offset(), limit, field, value, sortField, sortOrder))
|
certs, err := object.GetMaskedCerts(object.GetPaginationGlobalCerts(paginator.Offset(), limit, field, value, sortField, sortOrder))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
c.ResponseError(err.Error())
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
c.ResponseOk(certs, paginator.Nums())
|
c.ResponseOk(certs, paginator.Nums())
|
||||||
@@ -113,11 +117,11 @@ func (c *ApiController) GetCert() {
|
|||||||
id := c.Input().Get("id")
|
id := c.Input().Get("id")
|
||||||
cert, err := object.GetCert(id)
|
cert, err := object.GetCert(id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
c.ResponseError(err.Error())
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
c.Data["json"] = object.GetMaskedCert(cert)
|
c.ResponseOk(object.GetMaskedCert(cert))
|
||||||
c.ServeJSON()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// UpdateCert
|
// UpdateCert
|
||||||
|
@@ -41,11 +41,11 @@ func (c *ApiController) GetChats() {
|
|||||||
if limit == "" || page == "" {
|
if limit == "" || page == "" {
|
||||||
maskedChats, err := object.GetMaskedChats(object.GetChats(owner))
|
maskedChats, err := object.GetMaskedChats(object.GetChats(owner))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
c.ResponseError(err.Error())
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
c.Data["json"] = maskedChats
|
c.ResponseOk(maskedChats)
|
||||||
c.ServeJSON()
|
|
||||||
} else {
|
} else {
|
||||||
limit := util.ParseInt(limit)
|
limit := util.ParseInt(limit)
|
||||||
count, err := object.GetChatCount(owner, field, value)
|
count, err := object.GetChatCount(owner, field, value)
|
||||||
@@ -77,11 +77,11 @@ func (c *ApiController) GetChat() {
|
|||||||
|
|
||||||
maskedChat, err := object.GetMaskedChat(object.GetChat(id))
|
maskedChat, err := object.GetMaskedChat(object.GetChat(id))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
c.ResponseError(err.Error())
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
c.Data["json"] = maskedChat
|
c.ResponseOk(maskedChat)
|
||||||
c.ServeJSON()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// UpdateChat
|
// UpdateChat
|
||||||
|
@@ -82,9 +82,9 @@ func (c *ApiController) GetGroup() {
|
|||||||
group, err := object.GetGroup(id)
|
group, err := object.GetGroup(id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.ResponseError(err.Error())
|
c.ResponseError(err.Error())
|
||||||
} else {
|
return
|
||||||
c.ResponseOk(group)
|
|
||||||
}
|
}
|
||||||
|
c.ResponseOk(group)
|
||||||
}
|
}
|
||||||
|
|
||||||
// UpdateGroup
|
// UpdateGroup
|
||||||
|
@@ -38,8 +38,11 @@ type LdapSyncResp struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetLdapUsers
|
// GetLdapUsers
|
||||||
// @Tag Account API
|
|
||||||
// @Title GetLdapser
|
// @Title GetLdapser
|
||||||
|
// @Tag Account API
|
||||||
|
// @Description get ldap users
|
||||||
|
// Param id string true "id"
|
||||||
|
// @Success 200 {object} LdapResp The Response object
|
||||||
// @router /get-ldap-users [get]
|
// @router /get-ldap-users [get]
|
||||||
func (c *ApiController) GetLdapUsers() {
|
func (c *ApiController) GetLdapUsers() {
|
||||||
id := c.Input().Get("id")
|
id := c.Input().Get("id")
|
||||||
@@ -94,18 +97,24 @@ func (c *ApiController) GetLdapUsers() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetLdaps
|
// GetLdaps
|
||||||
// @Tag Account API
|
|
||||||
// @Title GetLdaps
|
// @Title GetLdaps
|
||||||
|
// @Tag Account API
|
||||||
|
// @Description get ldaps
|
||||||
|
// @Param owner query string false "owner"
|
||||||
|
// @Success 200 {array} object.Ldap The Response object
|
||||||
// @router /get-ldaps [get]
|
// @router /get-ldaps [get]
|
||||||
func (c *ApiController) GetLdaps() {
|
func (c *ApiController) GetLdaps() {
|
||||||
owner := c.Input().Get("owner")
|
owner := c.Input().Get("owner")
|
||||||
|
|
||||||
c.ResponseOk(object.GetLdaps(owner))
|
c.ResponseOk(object.GetMaskedLdaps(object.GetLdaps(owner)))
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetLdap
|
// GetLdap
|
||||||
// @Tag Account API
|
|
||||||
// @Title GetLdap
|
// @Title GetLdap
|
||||||
|
// @Tag Account API
|
||||||
|
// @Description get ldap
|
||||||
|
// @Param id query string true "id"
|
||||||
|
// @Success 200 {object} object.Ldap The Response object
|
||||||
// @router /get-ldap [get]
|
// @router /get-ldap [get]
|
||||||
func (c *ApiController) GetLdap() {
|
func (c *ApiController) GetLdap() {
|
||||||
id := c.Input().Get("id")
|
id := c.Input().Get("id")
|
||||||
@@ -116,12 +125,20 @@ func (c *ApiController) GetLdap() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_, name := util.GetOwnerAndNameFromId(id)
|
_, name := util.GetOwnerAndNameFromId(id)
|
||||||
c.ResponseOk(object.GetLdap(name))
|
ldap, err := object.GetLdap(name)
|
||||||
|
if err != nil {
|
||||||
|
c.ResponseError(err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
c.ResponseOk(object.GetMaskedLdap(ldap))
|
||||||
}
|
}
|
||||||
|
|
||||||
// AddLdap
|
// AddLdap
|
||||||
// @Tag Account API
|
|
||||||
// @Title AddLdap
|
// @Title AddLdap
|
||||||
|
// @Tag Account API
|
||||||
|
// @Description add ldap
|
||||||
|
// @Param body body object.Ldap true "The details of the ldap"
|
||||||
|
// @Success 200 {object} controllers.Response The Response object
|
||||||
// @router /add-ldap [post]
|
// @router /add-ldap [post]
|
||||||
func (c *ApiController) AddLdap() {
|
func (c *ApiController) AddLdap() {
|
||||||
var ldap object.Ldap
|
var ldap object.Ldap
|
||||||
@@ -160,8 +177,11 @@ func (c *ApiController) AddLdap() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// UpdateLdap
|
// UpdateLdap
|
||||||
// @Tag Account API
|
|
||||||
// @Title UpdateLdap
|
// @Title UpdateLdap
|
||||||
|
// @Tag Account API
|
||||||
|
// @Description update ldap
|
||||||
|
// @Param body body object.Ldap true "The details of the ldap"
|
||||||
|
// @Success 200 {object} controllers.Response The Response object
|
||||||
// @router /update-ldap [post]
|
// @router /update-ldap [post]
|
||||||
func (c *ApiController) UpdateLdap() {
|
func (c *ApiController) UpdateLdap() {
|
||||||
var ldap object.Ldap
|
var ldap object.Ldap
|
||||||
@@ -198,8 +218,11 @@ func (c *ApiController) UpdateLdap() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// DeleteLdap
|
// DeleteLdap
|
||||||
// @Tag Account API
|
|
||||||
// @Title DeleteLdap
|
// @Title DeleteLdap
|
||||||
|
// @Tag Account API
|
||||||
|
// @Description delete ldap
|
||||||
|
// @Param body body object.Ldap true "The details of the ldap"
|
||||||
|
// @Success 200 {object} controllers.Response The Response object
|
||||||
// @router /delete-ldap [post]
|
// @router /delete-ldap [post]
|
||||||
func (c *ApiController) DeleteLdap() {
|
func (c *ApiController) DeleteLdap() {
|
||||||
var ldap object.Ldap
|
var ldap object.Ldap
|
||||||
@@ -222,12 +245,16 @@ func (c *ApiController) DeleteLdap() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// SyncLdapUsers
|
// SyncLdapUsers
|
||||||
// @Tag Account API
|
|
||||||
// @Title SyncLdapUsers
|
// @Title SyncLdapUsers
|
||||||
|
// @Tag Account API
|
||||||
|
// @Description sync ldap users
|
||||||
|
// @Param id query string true "id"
|
||||||
|
// @Success 200 {object} LdapSyncResp The Response object
|
||||||
// @router /sync-ldap-users [post]
|
// @router /sync-ldap-users [post]
|
||||||
func (c *ApiController) SyncLdapUsers() {
|
func (c *ApiController) SyncLdapUsers() {
|
||||||
owner := c.Input().Get("owner")
|
id := c.Input().Get("id")
|
||||||
ldapId := c.Input().Get("ldapId")
|
|
||||||
|
owner, ldapId := util.GetOwnerAndNameFromId(id)
|
||||||
var users []object.LdapUser
|
var users []object.LdapUser
|
||||||
err := json.Unmarshal(c.Ctx.Input.RequestBody, &users)
|
err := json.Unmarshal(c.Ctx.Input.RequestBody, &users)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@@ -53,11 +53,11 @@ func (c *ApiController) GetMessages() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
c.ResponseError(err.Error())
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
c.Data["json"] = object.GetMaskedMessages(messages)
|
c.ResponseOk(object.GetMaskedMessages(messages))
|
||||||
c.ServeJSON()
|
|
||||||
} else {
|
} else {
|
||||||
limit := util.ParseInt(limit)
|
limit := util.ParseInt(limit)
|
||||||
count, err := object.GetMessageCount(owner, organization, field, value)
|
count, err := object.GetMessageCount(owner, organization, field, value)
|
||||||
@@ -89,18 +89,19 @@ func (c *ApiController) GetMessage() {
|
|||||||
id := c.Input().Get("id")
|
id := c.Input().Get("id")
|
||||||
message, err := object.GetMessage(id)
|
message, err := object.GetMessage(id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
c.ResponseError(err.Error())
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
c.Data["json"] = object.GetMaskedMessage(message)
|
c.ResponseOk(message)
|
||||||
c.ServeJSON()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *ApiController) ResponseErrorStream(errorText string) {
|
func (c *ApiController) ResponseErrorStream(errorText string) {
|
||||||
event := fmt.Sprintf("event: myerror\ndata: %s\n\n", errorText)
|
event := fmt.Sprintf("event: myerror\ndata: %s\n\n", errorText)
|
||||||
_, err := c.Ctx.ResponseWriter.Write([]byte(event))
|
_, err := c.Ctx.ResponseWriter.Write([]byte(event))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
c.ResponseError(err.Error())
|
||||||
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -196,7 +197,8 @@ func (c *ApiController) GetMessageAnswer() {
|
|||||||
event := fmt.Sprintf("event: end\ndata: %s\n\n", "end")
|
event := fmt.Sprintf("event: end\ndata: %s\n\n", "end")
|
||||||
_, err = c.Ctx.ResponseWriter.Write([]byte(event))
|
_, err = c.Ctx.ResponseWriter.Write([]byte(event))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
c.ResponseError(err.Error())
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
answer := stringBuilder.String()
|
answer := stringBuilder.String()
|
||||||
@@ -204,7 +206,8 @@ func (c *ApiController) GetMessageAnswer() {
|
|||||||
message.Text = answer
|
message.Text = answer
|
||||||
_, err = object.UpdateMessage(message.GetId(), message)
|
_, err = object.UpdateMessage(message.GetId(), message)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
c.ResponseError(err.Error())
|
||||||
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -17,7 +17,6 @@ package controllers
|
|||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/beego/beego"
|
|
||||||
"github.com/casdoor/casdoor/object"
|
"github.com/casdoor/casdoor/object"
|
||||||
"github.com/casdoor/casdoor/util"
|
"github.com/casdoor/casdoor/util"
|
||||||
)
|
)
|
||||||
@@ -29,7 +28,7 @@ import (
|
|||||||
// @param owner form string true "owner of user"
|
// @param owner form string true "owner of user"
|
||||||
// @param name form string true "name of user"
|
// @param name form string true "name of user"
|
||||||
// @param type form string true "MFA auth type"
|
// @param type form string true "MFA auth type"
|
||||||
// @Success 200 {object} The Response object
|
// @Success 200 {object} controllers.Response The Response object
|
||||||
// @router /mfa/setup/initiate [post]
|
// @router /mfa/setup/initiate [post]
|
||||||
func (c *ApiController) MfaSetupInitiate() {
|
func (c *ApiController) MfaSetupInitiate() {
|
||||||
owner := c.Ctx.Request.Form.Get("owner")
|
owner := c.Ctx.Request.Form.Get("owner")
|
||||||
@@ -58,10 +57,7 @@ func (c *ApiController) MfaSetupInitiate() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
issuer := beego.AppConfig.String("appname")
|
mfaProps, err := MfaUtil.Initiate(c.Ctx, user.GetId())
|
||||||
accountName := user.GetId()
|
|
||||||
|
|
||||||
mfaProps, err := MfaUtil.Initiate(c.Ctx, issuer, accountName)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.ResponseError(err.Error())
|
c.ResponseError(err.Error())
|
||||||
return
|
return
|
||||||
|
@@ -41,11 +41,11 @@ func (c *ApiController) GetModels() {
|
|||||||
if limit == "" || page == "" {
|
if limit == "" || page == "" {
|
||||||
models, err := object.GetModels(owner)
|
models, err := object.GetModels(owner)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
c.ResponseError(err.Error())
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
c.Data["json"] = models
|
c.ResponseOk(models)
|
||||||
c.ServeJSON()
|
|
||||||
} else {
|
} else {
|
||||||
limit := util.ParseInt(limit)
|
limit := util.ParseInt(limit)
|
||||||
count, err := object.GetModelCount(owner, field, value)
|
count, err := object.GetModelCount(owner, field, value)
|
||||||
@@ -77,11 +77,11 @@ func (c *ApiController) GetModel() {
|
|||||||
|
|
||||||
model, err := object.GetModel(id)
|
model, err := object.GetModel(id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
c.ResponseError(err.Error())
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
c.Data["json"] = model
|
c.ResponseOk(model)
|
||||||
c.ServeJSON()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// UpdateModel
|
// UpdateModel
|
||||||
|
@@ -37,17 +37,26 @@ func (c *ApiController) GetOrganizations() {
|
|||||||
value := c.Input().Get("value")
|
value := c.Input().Get("value")
|
||||||
sortField := c.Input().Get("sortField")
|
sortField := c.Input().Get("sortField")
|
||||||
sortOrder := c.Input().Get("sortOrder")
|
sortOrder := c.Input().Get("sortOrder")
|
||||||
|
organizationName := c.Input().Get("organizationName")
|
||||||
|
|
||||||
|
isGlobalAdmin := c.IsGlobalAdmin()
|
||||||
if limit == "" || page == "" {
|
if limit == "" || page == "" {
|
||||||
maskedOrganizations, err := object.GetMaskedOrganizations(object.GetOrganizations(owner))
|
var maskedOrganizations []*object.Organization
|
||||||
if err != nil {
|
var err error
|
||||||
panic(err)
|
|
||||||
|
if isGlobalAdmin {
|
||||||
|
maskedOrganizations, err = object.GetMaskedOrganizations(object.GetOrganizations(owner))
|
||||||
|
} else {
|
||||||
|
maskedOrganizations, err = object.GetMaskedOrganizations(object.GetOrganizations(owner, c.getCurrentUser().Owner))
|
||||||
}
|
}
|
||||||
|
|
||||||
c.Data["json"] = maskedOrganizations
|
if err != nil {
|
||||||
c.ServeJSON()
|
c.ResponseError(err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
c.ResponseOk(maskedOrganizations)
|
||||||
} else {
|
} else {
|
||||||
isGlobalAdmin := c.IsGlobalAdmin()
|
|
||||||
if !isGlobalAdmin {
|
if !isGlobalAdmin {
|
||||||
maskedOrganizations, err := object.GetMaskedOrganizations(object.GetOrganizations(owner, c.getCurrentUser().Owner))
|
maskedOrganizations, err := object.GetMaskedOrganizations(object.GetOrganizations(owner, c.getCurrentUser().Owner))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -64,7 +73,7 @@ func (c *ApiController) GetOrganizations() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
paginator := pagination.SetPaginator(c.Ctx, limit, count)
|
paginator := pagination.SetPaginator(c.Ctx, limit, count)
|
||||||
organizations, err := object.GetMaskedOrganizations(object.GetPaginationOrganizations(owner, paginator.Offset(), limit, field, value, sortField, sortOrder))
|
organizations, err := object.GetMaskedOrganizations(object.GetPaginationOrganizations(owner, organizationName, paginator.Offset(), limit, field, value, sortField, sortOrder))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.ResponseError(err.Error())
|
c.ResponseError(err.Error())
|
||||||
return
|
return
|
||||||
@@ -174,6 +183,8 @@ func (c *ApiController) DeleteOrganization() {
|
|||||||
func (c *ApiController) GetDefaultApplication() {
|
func (c *ApiController) GetDefaultApplication() {
|
||||||
userId := c.GetSessionUsername()
|
userId := c.GetSessionUsername()
|
||||||
id := c.Input().Get("id")
|
id := c.Input().Get("id")
|
||||||
|
redirectUri := c.Input().Get("redirectUri")
|
||||||
|
typ := c.Input().Get("type")
|
||||||
|
|
||||||
application, err := object.GetDefaultApplication(id)
|
application, err := object.GetDefaultApplication(id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -181,6 +192,14 @@ func (c *ApiController) GetDefaultApplication() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if typ == "cas" {
|
||||||
|
err = object.CheckCasRestrict(application, c.GetAcceptLanguage(), redirectUri)
|
||||||
|
if err != nil {
|
||||||
|
c.ResponseError(err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
maskedApplication := object.GetMaskedApplication(application, userId)
|
maskedApplication := object.GetMaskedApplication(application, userId)
|
||||||
c.ResponseOk(maskedApplication)
|
c.ResponseOk(maskedApplication)
|
||||||
}
|
}
|
||||||
|
@@ -42,22 +42,24 @@ func (c *ApiController) GetPayments() {
|
|||||||
if limit == "" || page == "" {
|
if limit == "" || page == "" {
|
||||||
payments, err := object.GetPayments(owner)
|
payments, err := object.GetPayments(owner)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
c.ResponseError(err.Error())
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
c.Data["json"] = payments
|
c.ResponseOk(payments)
|
||||||
c.ServeJSON()
|
|
||||||
} else {
|
} else {
|
||||||
limit := util.ParseInt(limit)
|
limit := util.ParseInt(limit)
|
||||||
count, err := object.GetPaymentCount(owner, organization, field, value)
|
count, err := object.GetPaymentCount(owner, organization, field, value)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
c.ResponseError(err.Error())
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
paginator := pagination.SetPaginator(c.Ctx, limit, count)
|
paginator := pagination.SetPaginator(c.Ctx, limit, count)
|
||||||
payments, err := object.GetPaginationPayments(owner, organization, paginator.Offset(), limit, field, value, sortField, sortOrder)
|
payments, err := object.GetPaginationPayments(owner, organization, paginator.Offset(), limit, field, value, sortField, sortOrder)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
c.ResponseError(err.Error())
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
c.ResponseOk(payments, paginator.Nums())
|
c.ResponseOk(payments, paginator.Nums())
|
||||||
@@ -99,11 +101,11 @@ func (c *ApiController) GetPayment() {
|
|||||||
|
|
||||||
payment, err := object.GetPayment(id)
|
payment, err := object.GetPayment(id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
c.ResponseError(err.Error())
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
c.Data["json"] = payment
|
c.ResponseOk(payment)
|
||||||
c.ServeJSON()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// UpdatePayment
|
// UpdatePayment
|
||||||
@@ -190,7 +192,8 @@ func (c *ApiController) NotifyPayment() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
c.ResponseError(err.Error())
|
||||||
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -41,22 +41,24 @@ func (c *ApiController) GetPermissions() {
|
|||||||
if limit == "" || page == "" {
|
if limit == "" || page == "" {
|
||||||
permissions, err := object.GetPermissions(owner)
|
permissions, err := object.GetPermissions(owner)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
c.ResponseError(err.Error())
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
c.Data["json"] = permissions
|
c.ResponseOk(permissions)
|
||||||
c.ServeJSON()
|
|
||||||
} else {
|
} else {
|
||||||
limit := util.ParseInt(limit)
|
limit := util.ParseInt(limit)
|
||||||
count, err := object.GetPermissionCount(owner, field, value)
|
count, err := object.GetPermissionCount(owner, field, value)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
c.ResponseError(err.Error())
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
paginator := pagination.SetPaginator(c.Ctx, limit, count)
|
paginator := pagination.SetPaginator(c.Ctx, limit, count)
|
||||||
permissions, err := object.GetPaginationPermissions(owner, paginator.Offset(), limit, field, value, sortField, sortOrder)
|
permissions, err := object.GetPaginationPermissions(owner, paginator.Offset(), limit, field, value, sortField, sortOrder)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
c.ResponseError(err.Error())
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
c.ResponseOk(permissions, paginator.Nums())
|
c.ResponseOk(permissions, paginator.Nums())
|
||||||
@@ -82,7 +84,6 @@ func (c *ApiController) GetPermissionsBySubmitter() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
c.ResponseOk(permissions, len(permissions))
|
c.ResponseOk(permissions, len(permissions))
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetPermissionsByRole
|
// GetPermissionsByRole
|
||||||
@@ -101,7 +102,6 @@ func (c *ApiController) GetPermissionsByRole() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
c.ResponseOk(permissions, len(permissions))
|
c.ResponseOk(permissions, len(permissions))
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetPermission
|
// GetPermission
|
||||||
@@ -116,11 +116,11 @@ func (c *ApiController) GetPermission() {
|
|||||||
|
|
||||||
permission, err := object.GetPermission(id)
|
permission, err := object.GetPermission(id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
c.ResponseError(err.Error())
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
c.Data["json"] = permission
|
c.ResponseOk(permission)
|
||||||
c.ServeJSON()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// UpdatePermission
|
// UpdatePermission
|
||||||
|
@@ -41,11 +41,11 @@ func (c *ApiController) GetPlans() {
|
|||||||
if limit == "" || page == "" {
|
if limit == "" || page == "" {
|
||||||
plans, err := object.GetPlans(owner)
|
plans, err := object.GetPlans(owner)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
c.ResponseError(err.Error())
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
c.Data["json"] = plans
|
c.ResponseOk(plans)
|
||||||
c.ServeJSON()
|
|
||||||
} else {
|
} else {
|
||||||
limit := util.ParseInt(limit)
|
limit := util.ParseInt(limit)
|
||||||
count, err := object.GetPlanCount(owner, field, value)
|
count, err := object.GetPlanCount(owner, field, value)
|
||||||
@@ -79,24 +79,25 @@ func (c *ApiController) GetPlan() {
|
|||||||
|
|
||||||
plan, err := object.GetPlan(id)
|
plan, err := object.GetPlan(id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
c.ResponseError(err.Error())
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if includeOption {
|
if includeOption {
|
||||||
options, err := object.GetPermissionsByRole(plan.Role)
|
options, err := object.GetPermissionsByRole(plan.Role)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
c.ResponseError(err.Error())
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, option := range options {
|
for _, option := range options {
|
||||||
plan.Options = append(plan.Options, option.DisplayName)
|
plan.Options = append(plan.Options, option.DisplayName)
|
||||||
}
|
}
|
||||||
|
|
||||||
c.Data["json"] = plan
|
c.ResponseOk(plan)
|
||||||
} else {
|
} else {
|
||||||
c.Data["json"] = plan
|
c.ResponseOk(plan)
|
||||||
}
|
}
|
||||||
c.ServeJSON()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// UpdatePlan
|
// UpdatePlan
|
||||||
|
@@ -41,11 +41,11 @@ func (c *ApiController) GetPricings() {
|
|||||||
if limit == "" || page == "" {
|
if limit == "" || page == "" {
|
||||||
pricings, err := object.GetPricings(owner)
|
pricings, err := object.GetPricings(owner)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
c.ResponseError(err.Error())
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
c.Data["json"] = pricings
|
c.ResponseOk(pricings)
|
||||||
c.ServeJSON()
|
|
||||||
} else {
|
} else {
|
||||||
limit := util.ParseInt(limit)
|
limit := util.ParseInt(limit)
|
||||||
count, err := object.GetPricingCount(owner, field, value)
|
count, err := object.GetPricingCount(owner, field, value)
|
||||||
@@ -70,18 +70,18 @@ func (c *ApiController) GetPricings() {
|
|||||||
// @Tag Pricing API
|
// @Tag Pricing API
|
||||||
// @Description get pricing
|
// @Description get pricing
|
||||||
// @Param id query string true "The id ( owner/name ) of the pricing"
|
// @Param id query string true "The id ( owner/name ) of the pricing"
|
||||||
// @Success 200 {object} object.pricing The Response object
|
// @Success 200 {object} object.Pricing The Response object
|
||||||
// @router /get-pricing [get]
|
// @router /get-pricing [get]
|
||||||
func (c *ApiController) GetPricing() {
|
func (c *ApiController) GetPricing() {
|
||||||
id := c.Input().Get("id")
|
id := c.Input().Get("id")
|
||||||
|
|
||||||
pricing, err := object.GetPricing(id)
|
pricing, err := object.GetPricing(id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
c.ResponseError(err.Error())
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
c.Data["json"] = pricing
|
c.ResponseOk(pricing)
|
||||||
c.ServeJSON()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// UpdatePricing
|
// UpdatePricing
|
||||||
|
@@ -42,11 +42,11 @@ func (c *ApiController) GetProducts() {
|
|||||||
if limit == "" || page == "" {
|
if limit == "" || page == "" {
|
||||||
products, err := object.GetProducts(owner)
|
products, err := object.GetProducts(owner)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
c.ResponseError(err.Error())
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
c.Data["json"] = products
|
c.ResponseOk(products)
|
||||||
c.ServeJSON()
|
|
||||||
} else {
|
} else {
|
||||||
limit := util.ParseInt(limit)
|
limit := util.ParseInt(limit)
|
||||||
count, err := object.GetProductCount(owner, field, value)
|
count, err := object.GetProductCount(owner, field, value)
|
||||||
@@ -78,16 +78,17 @@ func (c *ApiController) GetProduct() {
|
|||||||
|
|
||||||
product, err := object.GetProduct(id)
|
product, err := object.GetProduct(id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
c.ResponseError(err.Error())
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
err = object.ExtendProductWithProviders(product)
|
err = object.ExtendProductWithProviders(product)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
c.ResponseError(err.Error())
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
c.Data["json"] = product
|
c.ResponseOk(product)
|
||||||
c.ServeJSON()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// UpdateProduct
|
// UpdateProduct
|
||||||
|
@@ -46,7 +46,8 @@ func (c *ApiController) GetProviders() {
|
|||||||
if limit == "" || page == "" {
|
if limit == "" || page == "" {
|
||||||
providers, err := object.GetProviders(owner)
|
providers, err := object.GetProviders(owner)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
c.ResponseError(err.Error())
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
c.ResponseOk(object.GetMaskedProviders(providers, isMaskEnabled))
|
c.ResponseOk(object.GetMaskedProviders(providers, isMaskEnabled))
|
||||||
@@ -92,7 +93,8 @@ func (c *ApiController) GetGlobalProviders() {
|
|||||||
if limit == "" || page == "" {
|
if limit == "" || page == "" {
|
||||||
globalProviders, err := object.GetGlobalProviders()
|
globalProviders, err := object.GetGlobalProviders()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
c.ResponseError(err.Error())
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
c.ResponseOk(object.GetMaskedProviders(globalProviders, isMaskEnabled))
|
c.ResponseOk(object.GetMaskedProviders(globalProviders, isMaskEnabled))
|
||||||
|
@@ -42,17 +42,21 @@ func (c *ApiController) GetRecords() {
|
|||||||
value := c.Input().Get("value")
|
value := c.Input().Get("value")
|
||||||
sortField := c.Input().Get("sortField")
|
sortField := c.Input().Get("sortField")
|
||||||
sortOrder := c.Input().Get("sortOrder")
|
sortOrder := c.Input().Get("sortOrder")
|
||||||
|
organizationName := c.Input().Get("organizationName")
|
||||||
|
|
||||||
if limit == "" || page == "" {
|
if limit == "" || page == "" {
|
||||||
records, err := object.GetRecords()
|
records, err := object.GetRecords()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
c.ResponseError(err.Error())
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
c.Data["json"] = records
|
c.ResponseOk(records)
|
||||||
c.ServeJSON()
|
|
||||||
} else {
|
} else {
|
||||||
limit := util.ParseInt(limit)
|
limit := util.ParseInt(limit)
|
||||||
|
if c.IsGlobalAdmin() && organizationName != "" {
|
||||||
|
organization = organizationName
|
||||||
|
}
|
||||||
filterRecord := &object.Record{Organization: organization}
|
filterRecord := &object.Record{Organization: organization}
|
||||||
count, err := object.GetRecordCount(field, value, filterRecord)
|
count, err := object.GetRecordCount(field, value, filterRecord)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -84,16 +88,17 @@ func (c *ApiController) GetRecordsByFilter() {
|
|||||||
record := &object.Record{}
|
record := &object.Record{}
|
||||||
err := util.JsonToStruct(body, record)
|
err := util.JsonToStruct(body, record)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
c.ResponseError(err.Error())
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
records, err := object.GetRecordsByField(record)
|
records, err := object.GetRecordsByField(record)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
c.ResponseError(err.Error())
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
c.Data["json"] = records
|
c.ResponseOk(records)
|
||||||
c.ServeJSON()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// AddRecord
|
// AddRecord
|
||||||
|
@@ -29,9 +29,19 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// GetResources
|
// GetResources
|
||||||
// @router /get-resources [get]
|
|
||||||
// @Tag Resource API
|
// @Tag Resource API
|
||||||
// @Title GetResources
|
// @Title GetResources
|
||||||
|
// @Description get resources
|
||||||
|
// @Param owner query string true "Owner"
|
||||||
|
// @Param user query string true "User"
|
||||||
|
// @Param pageSize query integer false "Page Size"
|
||||||
|
// @Param p query integer false "Page Number"
|
||||||
|
// @Param field query string false "Field"
|
||||||
|
// @Param value query string false "Value"
|
||||||
|
// @Param sortField query string false "Sort Field"
|
||||||
|
// @Param sortOrder query string false "Sort Order"
|
||||||
|
// @Success 200 {array} object.Resource The Response object
|
||||||
|
// @router /get-resources [get]
|
||||||
func (c *ApiController) GetResources() {
|
func (c *ApiController) GetResources() {
|
||||||
owner := c.Input().Get("owner")
|
owner := c.Input().Get("owner")
|
||||||
user := c.Input().Get("user")
|
user := c.Input().Get("user")
|
||||||
@@ -53,11 +63,11 @@ func (c *ApiController) GetResources() {
|
|||||||
if limit == "" || page == "" {
|
if limit == "" || page == "" {
|
||||||
resources, err := object.GetResources(owner, user)
|
resources, err := object.GetResources(owner, user)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
c.ResponseError(err.Error())
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
c.Data["json"] = resources
|
c.ResponseOk(resources)
|
||||||
c.ServeJSON()
|
|
||||||
} else {
|
} else {
|
||||||
limit := util.ParseInt(limit)
|
limit := util.ParseInt(limit)
|
||||||
count, err := object.GetResourceCount(owner, user, field, value)
|
count, err := object.GetResourceCount(owner, user, field, value)
|
||||||
@@ -80,22 +90,29 @@ func (c *ApiController) GetResources() {
|
|||||||
// GetResource
|
// GetResource
|
||||||
// @Tag Resource API
|
// @Tag Resource API
|
||||||
// @Title GetResource
|
// @Title GetResource
|
||||||
|
// @Description get resource
|
||||||
|
// @Param id query string true "The id ( owner/name ) of resource"
|
||||||
|
// @Success 200 {object} object.Resource The Response object
|
||||||
// @router /get-resource [get]
|
// @router /get-resource [get]
|
||||||
func (c *ApiController) GetResource() {
|
func (c *ApiController) GetResource() {
|
||||||
id := c.Input().Get("id")
|
id := c.Input().Get("id")
|
||||||
|
|
||||||
resource, err := object.GetResource(id)
|
resource, err := object.GetResource(id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
c.ResponseError(err.Error())
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
c.Data["json"] = resource
|
c.ResponseOk(resource)
|
||||||
c.ServeJSON()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// UpdateResource
|
// UpdateResource
|
||||||
// @Tag Resource API
|
// @Tag Resource API
|
||||||
// @Title UpdateResource
|
// @Title UpdateResource
|
||||||
|
// @Description get resource
|
||||||
|
// @Param id query string true "The id ( owner/name ) of resource"
|
||||||
|
// @Param resource body object.Resource true "The resource object"
|
||||||
|
// @Success 200 {object} controllers.Response Success or error
|
||||||
// @router /update-resource [post]
|
// @router /update-resource [post]
|
||||||
func (c *ApiController) UpdateResource() {
|
func (c *ApiController) UpdateResource() {
|
||||||
id := c.Input().Get("id")
|
id := c.Input().Get("id")
|
||||||
@@ -114,6 +131,8 @@ func (c *ApiController) UpdateResource() {
|
|||||||
// AddResource
|
// AddResource
|
||||||
// @Tag Resource API
|
// @Tag Resource API
|
||||||
// @Title AddResource
|
// @Title AddResource
|
||||||
|
// @Param resource body object.Resource true "Resource object"
|
||||||
|
// @Success 200 {object} controllers.Response Success or error
|
||||||
// @router /add-resource [post]
|
// @router /add-resource [post]
|
||||||
func (c *ApiController) AddResource() {
|
func (c *ApiController) AddResource() {
|
||||||
var resource object.Resource
|
var resource object.Resource
|
||||||
@@ -130,6 +149,8 @@ func (c *ApiController) AddResource() {
|
|||||||
// DeleteResource
|
// DeleteResource
|
||||||
// @Tag Resource API
|
// @Tag Resource API
|
||||||
// @Title DeleteResource
|
// @Title DeleteResource
|
||||||
|
// @Param resource body object.Resource true "Resource object"
|
||||||
|
// @Success 200 {object} controllers.Response Success or error
|
||||||
// @router /delete-resource [post]
|
// @router /delete-resource [post]
|
||||||
func (c *ApiController) DeleteResource() {
|
func (c *ApiController) DeleteResource() {
|
||||||
var resource object.Resource
|
var resource object.Resource
|
||||||
@@ -158,6 +179,16 @@ func (c *ApiController) DeleteResource() {
|
|||||||
// UploadResource
|
// UploadResource
|
||||||
// @Tag Resource API
|
// @Tag Resource API
|
||||||
// @Title UploadResource
|
// @Title UploadResource
|
||||||
|
// @Param owner query string true "Owner"
|
||||||
|
// @Param user query string true "User"
|
||||||
|
// @Param application query string true "Application"
|
||||||
|
// @Param tag query string false "Tag"
|
||||||
|
// @Param parent query string false "Parent"
|
||||||
|
// @Param fullFilePath query string true "Full File Path"
|
||||||
|
// @Param createdTime query string false "Created Time"
|
||||||
|
// @Param description query string false "Description"
|
||||||
|
// @Param file formData file true "Resource file"
|
||||||
|
// @Success 200 {object} object.Resource FileUrl, objectKey
|
||||||
// @router /upload-resource [post]
|
// @router /upload-resource [post]
|
||||||
func (c *ApiController) UploadResource() {
|
func (c *ApiController) UploadResource() {
|
||||||
owner := c.Input().Get("owner")
|
owner := c.Input().Get("owner")
|
||||||
@@ -196,16 +227,16 @@ func (c *ApiController) UploadResource() {
|
|||||||
|
|
||||||
fileType := "unknown"
|
fileType := "unknown"
|
||||||
contentType := header.Header.Get("Content-Type")
|
contentType := header.Header.Get("Content-Type")
|
||||||
fileType, _ = util.GetOwnerAndNameFromId(contentType)
|
fileType, _ = util.GetOwnerAndNameFromIdNoCheck(contentType + "/")
|
||||||
|
|
||||||
if fileType != "image" && fileType != "video" {
|
if fileType != "image" && fileType != "video" {
|
||||||
ext := filepath.Ext(filename)
|
ext := filepath.Ext(filename)
|
||||||
mimeType := mime.TypeByExtension(ext)
|
mimeType := mime.TypeByExtension(ext)
|
||||||
fileType, _ = util.GetOwnerAndNameFromId(mimeType)
|
fileType, _ = util.GetOwnerAndNameFromIdNoCheck(mimeType + "/")
|
||||||
}
|
}
|
||||||
|
|
||||||
fullFilePath = object.GetTruncatedPath(provider, fullFilePath, 175)
|
fullFilePath = object.GetTruncatedPath(provider, fullFilePath, 175)
|
||||||
if tag != "avatar" && tag != "termsOfUse" {
|
if tag != "avatar" && tag != "termsOfUse" && !strings.HasPrefix(tag, "idCard") {
|
||||||
ext := filepath.Ext(filepath.Base(fullFilePath))
|
ext := filepath.Ext(filepath.Base(fullFilePath))
|
||||||
index := len(fullFilePath) - len(ext)
|
index := len(fullFilePath) - len(ext)
|
||||||
for i := 1; ; i++ {
|
for i := 1; ; i++ {
|
||||||
@@ -292,7 +323,7 @@ func (c *ApiController) UploadResource() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
_, applicationId := util.GetOwnerAndNameFromIdNoCheck(strings.TrimRight(fullFilePath, ".html"))
|
_, applicationId := util.GetOwnerAndNameFromIdNoCheck(strings.TrimSuffix(fullFilePath, ".html"))
|
||||||
applicationObj, err := object.GetApplication(applicationId)
|
applicationObj, err := object.GetApplication(applicationId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.ResponseError(err.Error())
|
c.ResponseError(err.Error())
|
||||||
@@ -305,6 +336,25 @@ func (c *ApiController) UploadResource() {
|
|||||||
c.ResponseError(err.Error())
|
c.ResponseError(err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
case "idCardFront", "idCardBack", "idCardWithPerson":
|
||||||
|
user, err := object.GetUserNoCheck(util.GetId(owner, username))
|
||||||
|
if err != nil {
|
||||||
|
c.ResponseError(err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if user == nil {
|
||||||
|
c.ResponseError(c.T("resource:User is nil for tag: avatar"))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
user.Properties[tag] = fileUrl
|
||||||
|
user.Properties["isIdCardVerified"] = "false"
|
||||||
|
_, err = object.UpdateUser(user.GetId(), user, []string{"properties"}, false)
|
||||||
|
if err != nil {
|
||||||
|
c.ResponseError(err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
c.ResponseOk(fileUrl, objectKey)
|
c.ResponseOk(fileUrl, objectKey)
|
||||||
|
@@ -41,11 +41,11 @@ func (c *ApiController) GetRoles() {
|
|||||||
if limit == "" || page == "" {
|
if limit == "" || page == "" {
|
||||||
roles, err := object.GetRoles(owner)
|
roles, err := object.GetRoles(owner)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
c.ResponseError(err.Error())
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
c.Data["json"] = roles
|
c.ResponseOk(roles)
|
||||||
c.ServeJSON()
|
|
||||||
} else {
|
} else {
|
||||||
limit := util.ParseInt(limit)
|
limit := util.ParseInt(limit)
|
||||||
count, err := object.GetRoleCount(owner, field, value)
|
count, err := object.GetRoleCount(owner, field, value)
|
||||||
@@ -77,11 +77,11 @@ func (c *ApiController) GetRole() {
|
|||||||
|
|
||||||
role, err := object.GetRole(id)
|
role, err := object.GetRole(id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
c.ResponseError(err.Error())
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
c.Data["json"] = role
|
c.ResponseOk(role)
|
||||||
c.ServeJSON()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// UpdateRole
|
// UpdateRole
|
||||||
|
@@ -41,11 +41,11 @@ func (c *ApiController) GetSessions() {
|
|||||||
if limit == "" || page == "" {
|
if limit == "" || page == "" {
|
||||||
sessions, err := object.GetSessions(owner)
|
sessions, err := object.GetSessions(owner)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
c.ResponseError(err.Error())
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
c.Data["json"] = sessions
|
c.ResponseOk(sessions)
|
||||||
c.ServeJSON()
|
|
||||||
} else {
|
} else {
|
||||||
limit := util.ParseInt(limit)
|
limit := util.ParseInt(limit)
|
||||||
count, err := object.GetSessionCount(owner, field, value)
|
count, err := object.GetSessionCount(owner, field, value)
|
||||||
@@ -76,11 +76,11 @@ func (c *ApiController) GetSingleSession() {
|
|||||||
|
|
||||||
session, err := object.GetSingleSession(id)
|
session, err := object.GetSingleSession(id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
c.ResponseError(err.Error())
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
c.Data["json"] = session
|
c.ResponseOk(session)
|
||||||
c.ServeJSON()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// UpdateSession
|
// UpdateSession
|
||||||
@@ -155,10 +155,9 @@ func (c *ApiController) IsSessionDuplicated() {
|
|||||||
|
|
||||||
isUserSessionDuplicated, err := object.IsSessionDuplicated(id, sessionId)
|
isUserSessionDuplicated, err := object.IsSessionDuplicated(id, sessionId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
c.ResponseError(err.Error())
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
c.Data["json"] = &Response{Status: "ok", Msg: "", Data: isUserSessionDuplicated}
|
c.ResponseOk(isUserSessionDuplicated)
|
||||||
|
|
||||||
c.ServeJSON()
|
|
||||||
}
|
}
|
||||||
|
@@ -41,11 +41,11 @@ func (c *ApiController) GetSubscriptions() {
|
|||||||
if limit == "" || page == "" {
|
if limit == "" || page == "" {
|
||||||
subscriptions, err := object.GetSubscriptions(owner)
|
subscriptions, err := object.GetSubscriptions(owner)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
c.ResponseError(err.Error())
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
c.Data["json"] = subscriptions
|
c.ResponseOk(subscriptions)
|
||||||
c.ServeJSON()
|
|
||||||
} else {
|
} else {
|
||||||
limit := util.ParseInt(limit)
|
limit := util.ParseInt(limit)
|
||||||
count, err := object.GetSubscriptionCount(owner, field, value)
|
count, err := object.GetSubscriptionCount(owner, field, value)
|
||||||
@@ -70,18 +70,18 @@ func (c *ApiController) GetSubscriptions() {
|
|||||||
// @Tag Subscription API
|
// @Tag Subscription API
|
||||||
// @Description get subscription
|
// @Description get subscription
|
||||||
// @Param id query string true "The id ( owner/name ) of the subscription"
|
// @Param id query string true "The id ( owner/name ) of the subscription"
|
||||||
// @Success 200 {object} object.subscription The Response object
|
// @Success 200 {object} object.Subscription The Response object
|
||||||
// @router /get-subscription [get]
|
// @router /get-subscription [get]
|
||||||
func (c *ApiController) GetSubscription() {
|
func (c *ApiController) GetSubscription() {
|
||||||
id := c.Input().Get("id")
|
id := c.Input().Get("id")
|
||||||
|
|
||||||
subscription, err := object.GetSubscription(id)
|
subscription, err := object.GetSubscription(id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
c.ResponseError(err.Error())
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
c.Data["json"] = subscription
|
c.ResponseOk(subscription)
|
||||||
c.ServeJSON()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// UpdateSubscription
|
// UpdateSubscription
|
||||||
|
@@ -42,11 +42,11 @@ func (c *ApiController) GetSyncers() {
|
|||||||
if limit == "" || page == "" {
|
if limit == "" || page == "" {
|
||||||
organizationSyncers, err := object.GetOrganizationSyncers(owner, organization)
|
organizationSyncers, err := object.GetOrganizationSyncers(owner, organization)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
c.ResponseError(err.Error())
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
c.Data["json"] = organizationSyncers
|
c.ResponseOk(organizationSyncers)
|
||||||
c.ServeJSON()
|
|
||||||
} else {
|
} else {
|
||||||
limit := util.ParseInt(limit)
|
limit := util.ParseInt(limit)
|
||||||
count, err := object.GetSyncerCount(owner, organization, field, value)
|
count, err := object.GetSyncerCount(owner, organization, field, value)
|
||||||
@@ -78,11 +78,11 @@ func (c *ApiController) GetSyncer() {
|
|||||||
|
|
||||||
syncer, err := object.GetSyncer(id)
|
syncer, err := object.GetSyncer(id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
c.ResponseError(err.Error())
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
c.Data["json"] = syncer
|
c.ResponseOk(syncer)
|
||||||
c.ServeJSON()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// UpdateSyncer
|
// UpdateSyncer
|
||||||
|
@@ -43,11 +43,11 @@ func (c *ApiController) GetTokens() {
|
|||||||
if limit == "" || page == "" {
|
if limit == "" || page == "" {
|
||||||
token, err := object.GetTokens(owner, organization)
|
token, err := object.GetTokens(owner, organization)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
c.ResponseError(err.Error())
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
c.Data["json"] = token
|
c.ResponseOk(token)
|
||||||
c.ServeJSON()
|
|
||||||
} else {
|
} else {
|
||||||
limit := util.ParseInt(limit)
|
limit := util.ParseInt(limit)
|
||||||
count, err := object.GetTokenCount(owner, organization, field, value)
|
count, err := object.GetTokenCount(owner, organization, field, value)
|
||||||
@@ -78,11 +78,11 @@ func (c *ApiController) GetToken() {
|
|||||||
id := c.Input().Get("id")
|
id := c.Input().Get("id")
|
||||||
token, err := object.GetToken(id)
|
token, err := object.GetToken(id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
c.ResponseError(err.Error())
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
c.Data["json"] = token
|
c.ResponseOk(token)
|
||||||
c.ServeJSON()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// UpdateToken
|
// UpdateToken
|
||||||
@@ -193,7 +193,8 @@ func (c *ApiController) GetOAuthToken() {
|
|||||||
host := c.Ctx.Request.Host
|
host := c.Ctx.Request.Host
|
||||||
oAuthtoken, err := object.GetOAuthToken(grantType, clientId, clientSecret, code, verifier, scope, username, password, host, refreshToken, tag, avatar, c.GetAcceptLanguage())
|
oAuthtoken, err := object.GetOAuthToken(grantType, clientId, clientSecret, code, verifier, scope, username, password, host, refreshToken, tag, avatar, c.GetAcceptLanguage())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
c.ResponseError(err.Error())
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
c.Data["json"] = oAuthtoken
|
c.Data["json"] = oAuthtoken
|
||||||
@@ -236,7 +237,8 @@ func (c *ApiController) RefreshToken() {
|
|||||||
|
|
||||||
refreshToken2, err := object.RefreshToken(grantType, refreshToken, scope, clientId, clientSecret, host)
|
refreshToken2, err := object.RefreshToken(grantType, refreshToken, scope, clientId, clientSecret, host)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
c.ResponseError(err.Error())
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
c.Data["json"] = refreshToken2
|
c.Data["json"] = refreshToken2
|
||||||
@@ -276,7 +278,8 @@ func (c *ApiController) IntrospectToken() {
|
|||||||
}
|
}
|
||||||
application, err := object.GetApplicationByClientId(clientId)
|
application, err := object.GetApplicationByClientId(clientId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
c.ResponseError(err.Error())
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if application == nil || application.ClientSecret != clientSecret {
|
if application == nil || application.ClientSecret != clientSecret {
|
||||||
@@ -289,7 +292,8 @@ func (c *ApiController) IntrospectToken() {
|
|||||||
}
|
}
|
||||||
token, err := object.GetTokenByTokenAndApplication(tokenValue, application.Name)
|
token, err := object.GetTokenByTokenAndApplication(tokenValue, application.Name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
c.ResponseError(err.Error())
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if token == nil {
|
if token == nil {
|
||||||
@@ -319,7 +323,7 @@ func (c *ApiController) IntrospectToken() {
|
|||||||
Sub: jwtToken.Subject,
|
Sub: jwtToken.Subject,
|
||||||
Aud: jwtToken.Audience,
|
Aud: jwtToken.Audience,
|
||||||
Iss: jwtToken.Issuer,
|
Iss: jwtToken.Issuer,
|
||||||
Jti: jwtToken.Id,
|
Jti: jwtToken.ID,
|
||||||
}
|
}
|
||||||
c.ServeJSON()
|
c.ServeJSON()
|
||||||
}
|
}
|
||||||
|
@@ -41,11 +41,11 @@ func (c *ApiController) GetGlobalUsers() {
|
|||||||
if limit == "" || page == "" {
|
if limit == "" || page == "" {
|
||||||
maskedUsers, err := object.GetMaskedUsers(object.GetGlobalUsers())
|
maskedUsers, err := object.GetMaskedUsers(object.GetGlobalUsers())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
c.ResponseError(err.Error())
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
c.Data["json"] = maskedUsers
|
c.ResponseOk(maskedUsers)
|
||||||
c.ServeJSON()
|
|
||||||
} else {
|
} else {
|
||||||
limit := util.ParseInt(limit)
|
limit := util.ParseInt(limit)
|
||||||
count, err := object.GetGlobalUserCount(field, value)
|
count, err := object.GetGlobalUserCount(field, value)
|
||||||
@@ -101,11 +101,11 @@ func (c *ApiController) GetUsers() {
|
|||||||
|
|
||||||
maskedUsers, err := object.GetMaskedUsers(object.GetUsers(owner))
|
maskedUsers, err := object.GetMaskedUsers(object.GetUsers(owner))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
c.ResponseError(err.Error())
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
c.Data["json"] = maskedUsers
|
c.ResponseOk(maskedUsers)
|
||||||
c.ServeJSON()
|
|
||||||
} else {
|
} else {
|
||||||
limit := util.ParseInt(limit)
|
limit := util.ParseInt(limit)
|
||||||
count, err := object.GetUserCount(owner, field, value, groupName)
|
count, err := object.GetUserCount(owner, field, value, groupName)
|
||||||
@@ -153,7 +153,8 @@ func (c *ApiController) GetUser() {
|
|||||||
if userId != "" && owner != "" {
|
if userId != "" && owner != "" {
|
||||||
userFromUserId, err = object.GetUserByUserId(owner, userId)
|
userFromUserId, err = object.GetUserByUserId(owner, userId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
c.ResponseError(err.Error())
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
id = util.GetId(userFromUserId.Owner, userFromUserId.Name)
|
id = util.GetId(userFromUserId.Owner, userFromUserId.Name)
|
||||||
@@ -165,7 +166,8 @@ func (c *ApiController) GetUser() {
|
|||||||
|
|
||||||
organization, err := object.GetOrganization(util.GetId("admin", owner))
|
organization, err := object.GetOrganization(util.GetId("admin", owner))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
c.ResponseError(err.Error())
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if !organization.IsProfilePublic {
|
if !organization.IsProfilePublic {
|
||||||
@@ -190,22 +192,28 @@ func (c *ApiController) GetUser() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
c.ResponseError(err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if user != nil {
|
||||||
|
user.MultiFactorAuths = object.GetAllMfaProps(user, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
user.MultiFactorAuths = object.GetAllMfaProps(user, true)
|
|
||||||
err = object.ExtendUserWithRolesAndPermissions(user)
|
err = object.ExtendUserWithRolesAndPermissions(user)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
c.ResponseError(err.Error())
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
maskedUser, err := object.GetMaskedUser(user)
|
isAdminOrSelf := c.IsAdminOrSelf(user)
|
||||||
|
maskedUser, err := object.GetMaskedUser(user, isAdminOrSelf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
c.ResponseError(err.Error())
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
c.Data["json"] = maskedUser
|
c.ResponseOk(maskedUser)
|
||||||
c.ServeJSON()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// UpdateUser
|
// UpdateUser
|
||||||
@@ -498,11 +506,11 @@ func (c *ApiController) GetSortedUsers() {
|
|||||||
|
|
||||||
maskedUsers, err := object.GetMaskedUsers(object.GetSortedUsers(owner, sorter, limit))
|
maskedUsers, err := object.GetMaskedUsers(object.GetSortedUsers(owner, sorter, limit))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
c.ResponseError(err.Error())
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
c.Data["json"] = maskedUsers
|
c.ResponseOk(maskedUsers)
|
||||||
c.ServeJSON()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetUserCount
|
// GetUserCount
|
||||||
@@ -529,8 +537,7 @@ func (c *ApiController) GetUserCount() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
c.Data["json"] = count
|
c.ResponseOk(count)
|
||||||
c.ServeJSON()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// AddUserkeys
|
// AddUserkeys
|
||||||
|
@@ -97,7 +97,8 @@ func (c *ApiController) RequireSignedInUser() (*object.User, bool) {
|
|||||||
|
|
||||||
user, err := object.GetUser(userId)
|
user, err := object.GetUser(userId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
c.ResponseError(err.Error())
|
||||||
|
return nil, false
|
||||||
}
|
}
|
||||||
|
|
||||||
if user == nil {
|
if user == nil {
|
||||||
|
@@ -93,10 +93,9 @@ func (c *ApiController) SendVerificationCode() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// mfaSessionData != nil, means method is MfaAuthVerification
|
// mfaUserSession != "", means method is MfaAuthVerification
|
||||||
if mfaSessionData := c.getMfaSessionData(); mfaSessionData != nil {
|
if mfaUserSession := c.getMfaUserSession(); mfaUserSession != "" {
|
||||||
user, err = object.GetUser(mfaSessionData.UserId)
|
user, err = object.GetUser(mfaUserSession)
|
||||||
c.setMfaSessionData(nil)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.ResponseError(err.Error())
|
c.ResponseError(err.Error())
|
||||||
return
|
return
|
||||||
@@ -134,6 +133,8 @@ func (c *ApiController) SendVerificationCode() {
|
|||||||
if user != nil && util.GetMaskedEmail(mfaProps.Secret) == vform.Dest {
|
if user != nil && util.GetMaskedEmail(mfaProps.Secret) == vform.Dest {
|
||||||
vform.Dest = mfaProps.Secret
|
vform.Dest = mfaProps.Secret
|
||||||
}
|
}
|
||||||
|
} else if vform.Method == MfaSetupVerification {
|
||||||
|
c.SetSession(object.MfaDestSession, vform.Dest)
|
||||||
}
|
}
|
||||||
|
|
||||||
provider, err := application.GetEmailProvider()
|
provider, err := application.GetEmailProvider()
|
||||||
@@ -164,6 +165,11 @@ func (c *ApiController) SendVerificationCode() {
|
|||||||
vform.CountryCode = user.GetCountryCode(vform.CountryCode)
|
vform.CountryCode = user.GetCountryCode(vform.CountryCode)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if vform.Method == MfaSetupVerification {
|
||||||
|
c.SetSession(object.MfaCountryCodeSession, vform.CountryCode)
|
||||||
|
c.SetSession(object.MfaDestSession, vform.Dest)
|
||||||
|
}
|
||||||
} else if vform.Method == MfaAuthVerification {
|
} else if vform.Method == MfaAuthVerification {
|
||||||
mfaProps := user.GetPreferredMfaProps(false)
|
mfaProps := user.GetPreferredMfaProps(false)
|
||||||
if user != nil && util.GetMaskedPhone(mfaProps.Secret) == vform.Dest {
|
if user != nil && util.GetMaskedPhone(mfaProps.Secret) == vform.Dest {
|
||||||
@@ -187,11 +193,6 @@ func (c *ApiController) SendVerificationCode() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if vform.Method == MfaSetupVerification {
|
|
||||||
c.SetSession(object.MfaSmsCountryCodeSession, vform.CountryCode)
|
|
||||||
c.SetSession(object.MfaSmsDestSession, vform.Dest)
|
|
||||||
}
|
|
||||||
|
|
||||||
if sendResp != nil {
|
if sendResp != nil {
|
||||||
c.ResponseError(sendResp.Error())
|
c.ResponseError(sendResp.Error())
|
||||||
} else {
|
} else {
|
||||||
|
@@ -66,7 +66,7 @@ func (c *ApiController) WebAuthnSignupBegin() {
|
|||||||
// @Tag User API
|
// @Tag User API
|
||||||
// @Description WebAuthn Registration Flow 2nd stage
|
// @Description WebAuthn Registration Flow 2nd stage
|
||||||
// @Param body body protocol.CredentialCreationResponse true "authenticator attestation Response"
|
// @Param body body protocol.CredentialCreationResponse true "authenticator attestation Response"
|
||||||
// @Success 200 {object} Response "The Response object"
|
// @Success 200 {object} controllers.Response "The Response object"
|
||||||
// @router /webauthn/signup/finish [post]
|
// @router /webauthn/signup/finish [post]
|
||||||
func (c *ApiController) WebAuthnSignupFinish() {
|
func (c *ApiController) WebAuthnSignupFinish() {
|
||||||
webauthnObj, err := object.GetWebAuthnObject(c.Ctx.Request.Host)
|
webauthnObj, err := object.GetWebAuthnObject(c.Ctx.Request.Host)
|
||||||
@@ -150,7 +150,7 @@ func (c *ApiController) WebAuthnSigninBegin() {
|
|||||||
// @Tag Login API
|
// @Tag Login API
|
||||||
// @Description WebAuthn Login Flow 2nd stage
|
// @Description WebAuthn Login Flow 2nd stage
|
||||||
// @Param body body protocol.CredentialAssertionResponse true "authenticator assertion Response"
|
// @Param body body protocol.CredentialAssertionResponse true "authenticator assertion Response"
|
||||||
// @Success 200 {object} Response "The Response object"
|
// @Success 200 {object} controllers.Response "The Response object"
|
||||||
// @router /webauthn/signin/finish [post]
|
// @router /webauthn/signin/finish [post]
|
||||||
func (c *ApiController) WebAuthnSigninFinish() {
|
func (c *ApiController) WebAuthnSigninFinish() {
|
||||||
responseType := c.Input().Get("responseType")
|
responseType := c.Input().Get("responseType")
|
||||||
|
@@ -42,11 +42,11 @@ func (c *ApiController) GetWebhooks() {
|
|||||||
if limit == "" || page == "" {
|
if limit == "" || page == "" {
|
||||||
webhooks, err := object.GetWebhooks(owner, organization)
|
webhooks, err := object.GetWebhooks(owner, organization)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
c.ResponseError(err.Error())
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
c.Data["json"] = webhooks
|
c.ResponseOk(webhooks)
|
||||||
c.ServeJSON()
|
|
||||||
} else {
|
} else {
|
||||||
limit := util.ParseInt(limit)
|
limit := util.ParseInt(limit)
|
||||||
count, err := object.GetWebhookCount(owner, organization, field, value)
|
count, err := object.GetWebhookCount(owner, organization, field, value)
|
||||||
@@ -79,11 +79,11 @@ func (c *ApiController) GetWebhook() {
|
|||||||
|
|
||||||
webhook, err := object.GetWebhook(id)
|
webhook, err := object.GetWebhook(id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
c.ResponseError(err.Error())
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
c.Data["json"] = webhook
|
c.ResponseOk(webhook)
|
||||||
c.ServeJSON()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// UpdateWebhook
|
// UpdateWebhook
|
||||||
|
@@ -25,6 +25,12 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestDeployStaticFiles(t *testing.T) {
|
func TestDeployStaticFiles(t *testing.T) {
|
||||||
provider := object.GetProvider(util.GetId("admin", "provider_storage_aliyun_oss"))
|
object.InitConfig()
|
||||||
|
|
||||||
|
provider, err := object.GetProvider(util.GetId("admin", "provider_storage_aliyun_oss"))
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
deployStaticFiles(provider)
|
deployStaticFiles(provider)
|
||||||
}
|
}
|
||||||
|
7
go.mod
7
go.mod
@@ -39,17 +39,18 @@ require (
|
|||||||
github.com/lib/pq v1.10.2
|
github.com/lib/pq v1.10.2
|
||||||
github.com/lor00x/goldap v0.0.0-20180618054307-a546dffdd1a3
|
github.com/lor00x/goldap v0.0.0-20180618054307-a546dffdd1a3
|
||||||
github.com/markbates/goth v1.75.2
|
github.com/markbates/goth v1.75.2
|
||||||
|
github.com/mitchellh/mapstructure v1.5.0
|
||||||
github.com/nu7hatch/gouuid v0.0.0-20131221200532-179d4d0c4d8d // indirect
|
github.com/nu7hatch/gouuid v0.0.0-20131221200532-179d4d0c4d8d // indirect
|
||||||
github.com/nyaruka/phonenumbers v1.1.5
|
github.com/nyaruka/phonenumbers v1.1.5
|
||||||
github.com/pkoukk/tiktoken-go v0.1.1
|
github.com/pkoukk/tiktoken-go v0.1.1
|
||||||
github.com/plutov/paypal/v4 v4.7.0
|
github.com/pquerna/otp v1.4.0
|
||||||
github.com/prometheus/client_golang v1.11.1
|
github.com/prometheus/client_golang v1.11.1
|
||||||
github.com/prometheus/client_model v0.2.0
|
github.com/prometheus/client_model v0.2.0
|
||||||
github.com/qiangmzsx/string-adapter/v2 v2.1.0
|
github.com/qiangmzsx/string-adapter/v2 v2.1.0
|
||||||
github.com/robfig/cron/v3 v3.0.1
|
github.com/robfig/cron/v3 v3.0.1
|
||||||
github.com/russellhaering/gosaml2 v0.9.0
|
github.com/russellhaering/gosaml2 v0.9.0
|
||||||
github.com/russellhaering/goxmldsig v1.2.0
|
github.com/russellhaering/goxmldsig v1.2.0
|
||||||
github.com/sashabaranov/go-openai v1.9.1
|
github.com/sashabaranov/go-openai v1.12.0
|
||||||
github.com/satori/go.uuid v1.2.0
|
github.com/satori/go.uuid v1.2.0
|
||||||
github.com/shiena/ansicolor v0.0.0-20200904210342-c7312218db18 // indirect
|
github.com/shiena/ansicolor v0.0.0-20200904210342-c7312218db18 // indirect
|
||||||
github.com/shirou/gopsutil v3.21.11+incompatible
|
github.com/shirou/gopsutil v3.21.11+incompatible
|
||||||
@@ -59,7 +60,7 @@ require (
|
|||||||
github.com/tealeg/xlsx v1.0.5
|
github.com/tealeg/xlsx v1.0.5
|
||||||
github.com/thanhpk/randstr v1.0.4
|
github.com/thanhpk/randstr v1.0.4
|
||||||
github.com/tklauser/go-sysconf v0.3.10 // indirect
|
github.com/tklauser/go-sysconf v0.3.10 // indirect
|
||||||
github.com/xorm-io/builder v0.3.13 // indirect
|
github.com/xorm-io/builder v0.3.13
|
||||||
github.com/xorm-io/core v0.7.4
|
github.com/xorm-io/core v0.7.4
|
||||||
github.com/xorm-io/xorm v1.1.6
|
github.com/xorm-io/xorm v1.1.6
|
||||||
github.com/yusufpapurcu/wmi v1.2.2 // indirect
|
github.com/yusufpapurcu/wmi v1.2.2 // indirect
|
||||||
|
11
go.sum
11
go.sum
@@ -105,6 +105,8 @@ github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24
|
|||||||
github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8=
|
github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8=
|
||||||
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
|
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
|
||||||
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
|
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
|
||||||
|
github.com/boombuler/barcode v1.0.1-0.20190219062509-6c824513bacc h1:biVzkmvwrH8WK8raXaxBx6fRVTlJILwEwQGL1I/ByEI=
|
||||||
|
github.com/boombuler/barcode v1.0.1-0.20190219062509-6c824513bacc/go.mod h1:paBWMcWSl3LHKBqUq+rly7CNSldXjb2rDl3JlRe0mD8=
|
||||||
github.com/bradfitz/gomemcache v0.0.0-20180710155616-bc664df96737/go.mod h1:PmM6Mmwb0LSuEubjR8N7PtNe1KxZLtOUHtbeikc5h60=
|
github.com/bradfitz/gomemcache v0.0.0-20180710155616-bc664df96737/go.mod h1:PmM6Mmwb0LSuEubjR8N7PtNe1KxZLtOUHtbeikc5h60=
|
||||||
github.com/bwesterb/go-ristretto v1.2.0/go.mod h1:fUIoIZaG73pV5biE2Blr2xEzDoMj7NFEuV9ekS419A0=
|
github.com/bwesterb/go-ristretto v1.2.0/go.mod h1:fUIoIZaG73pV5biE2Blr2xEzDoMj7NFEuV9ekS419A0=
|
||||||
github.com/casbin/casbin v1.7.0/go.mod h1:c67qKN6Oum3UF5Q1+BByfFxkwKvhwW57ITjqwtzR1KE=
|
github.com/casbin/casbin v1.7.0/go.mod h1:c67qKN6Oum3UF5Q1+BByfFxkwKvhwW57ITjqwtzR1KE=
|
||||||
@@ -495,10 +497,10 @@ github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
|
|||||||
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||||
github.com/pkoukk/tiktoken-go v0.1.1 h1:jtkYlIECjyM9OW1w4rjPmTohK4arORP9V25y6TM6nXo=
|
github.com/pkoukk/tiktoken-go v0.1.1 h1:jtkYlIECjyM9OW1w4rjPmTohK4arORP9V25y6TM6nXo=
|
||||||
github.com/pkoukk/tiktoken-go v0.1.1/go.mod h1:boMWvk9pQCOTx11pgu0DrIdrAKgQzzJKUP6vLXaz7Rw=
|
github.com/pkoukk/tiktoken-go v0.1.1/go.mod h1:boMWvk9pQCOTx11pgu0DrIdrAKgQzzJKUP6vLXaz7Rw=
|
||||||
github.com/plutov/paypal/v4 v4.7.0 h1:6TRvYD4ny6yQfHaABeStNf43GFM1wpW5jU/XEDGQmq0=
|
|
||||||
github.com/plutov/paypal/v4 v4.7.0/go.mod h1:D56boafCRGcF/fEM0w282kj0fCDKIyrwOPX/Te1jCmw=
|
|
||||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||||
|
github.com/pquerna/otp v1.4.0 h1:wZvl1TIVxKRThZIBiwOOHOGP/1+nZyWBil9Y2XNEDzg=
|
||||||
|
github.com/pquerna/otp v1.4.0/go.mod h1:dkJfzwRKNiegxyNb54X/3fLwhCynbMspSyWKnvi1AEg=
|
||||||
github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw=
|
github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw=
|
||||||
github.com/prometheus/client_golang v0.9.3/go.mod h1:/TN21ttK/J9q6uSwhBd54HahCDft0ttaMvbicHlPoso=
|
github.com/prometheus/client_golang v0.9.3/go.mod h1:/TN21ttK/J9q6uSwhBd54HahCDft0ttaMvbicHlPoso=
|
||||||
github.com/prometheus/client_golang v1.0.0/go.mod h1:db9x61etRT2tGnBNRi70OPL5FsnadC4Ky3P0J6CfImo=
|
github.com/prometheus/client_golang v1.0.0/go.mod h1:db9x61etRT2tGnBNRi70OPL5FsnadC4Ky3P0J6CfImo=
|
||||||
@@ -544,8 +546,8 @@ github.com/russellhaering/goxmldsig v1.2.0 h1:Y6GTTc9Un5hCxSzVz4UIWQ/zuVwDvzJk80
|
|||||||
github.com/russellhaering/goxmldsig v1.2.0/go.mod h1:gM4MDENBQf7M+V824SGfyIUVFWydB7n0KkEubVJl+Tw=
|
github.com/russellhaering/goxmldsig v1.2.0/go.mod h1:gM4MDENBQf7M+V824SGfyIUVFWydB7n0KkEubVJl+Tw=
|
||||||
github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g=
|
github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g=
|
||||||
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
|
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
|
||||||
github.com/sashabaranov/go-openai v1.9.1 h1:3N52HkJKo9Zlo/oe1AVv5ZkCOny0ra58/ACvAxkN3MM=
|
github.com/sashabaranov/go-openai v1.12.0 h1:aRNHH0gtVfrpIaEolD0sWrLLRnYQNK4cH/bIAHwL8Rk=
|
||||||
github.com/sashabaranov/go-openai v1.9.1/go.mod h1:lj5b/K+zjTSFxVLijLSTDZuP7adOgerWeFyZLUhAKRg=
|
github.com/sashabaranov/go-openai v1.12.0/go.mod h1:lj5b/K+zjTSFxVLijLSTDZuP7adOgerWeFyZLUhAKRg=
|
||||||
github.com/satori/go.uuid v1.2.0 h1:0uYX9dsZ2yD7q2RtLRtPSdGDWzjeM3TbMJP9utgA0ww=
|
github.com/satori/go.uuid v1.2.0 h1:0uYX9dsZ2yD7q2RtLRtPSdGDWzjeM3TbMJP9utgA0ww=
|
||||||
github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0=
|
github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0=
|
||||||
github.com/sergi/go-diff v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0=
|
github.com/sergi/go-diff v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0=
|
||||||
@@ -595,7 +597,6 @@ github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXf
|
|||||||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||||
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
|
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
|
||||||
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
|
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
|
||||||
github.com/stretchr/testify v1.6.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
|
||||||
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||||
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||||
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||||
|
@@ -18,7 +18,8 @@
|
|||||||
"The login method: login with password is not enabled for the application": "Die Anmeldeart \"Anmeldung mit Passwort\" ist für die Anwendung nicht aktiviert",
|
"The login method: login with password is not enabled for the application": "Die Anmeldeart \"Anmeldung mit Passwort\" ist für die Anwendung nicht aktiviert",
|
||||||
"The provider: %s is not enabled for the application": "Der Anbieter: %s ist nicht für die Anwendung aktiviert",
|
"The provider: %s is not enabled for the application": "Der Anbieter: %s ist nicht für die Anwendung aktiviert",
|
||||||
"Unauthorized operation": "Nicht autorisierte Operation",
|
"Unauthorized operation": "Nicht autorisierte Operation",
|
||||||
"Unknown authentication type (not password or provider), form = %s": "Unbekannter Authentifizierungstyp (nicht Passwort oder Anbieter), Formular = %s"
|
"Unknown authentication type (not password or provider), form = %s": "Unbekannter Authentifizierungstyp (nicht Passwort oder Anbieter), Formular = %s",
|
||||||
|
"User's tag: %s is not listed in the application's tags": "User's tag: %s is not listed in the application's tags"
|
||||||
},
|
},
|
||||||
"cas": {
|
"cas": {
|
||||||
"Service %s and %s do not match": "Service %s und %s stimmen nicht überein"
|
"Service %s and %s do not match": "Service %s und %s stimmen nicht überein"
|
||||||
|
@@ -18,7 +18,8 @@
|
|||||||
"The login method: login with password is not enabled for the application": "The login method: login with password is not enabled for the application",
|
"The login method: login with password is not enabled for the application": "The login method: login with password is not enabled for the application",
|
||||||
"The provider: %s is not enabled for the application": "The provider: %s is not enabled for the application",
|
"The provider: %s is not enabled for the application": "The provider: %s is not enabled for the application",
|
||||||
"Unauthorized operation": "Unauthorized operation",
|
"Unauthorized operation": "Unauthorized operation",
|
||||||
"Unknown authentication type (not password or provider), form = %s": "Unknown authentication type (not password or provider), form = %s"
|
"Unknown authentication type (not password or provider), form = %s": "Unknown authentication type (not password or provider), form = %s",
|
||||||
|
"User's tag: %s is not listed in the application's tags": "User's tag: %s is not listed in the application's tags"
|
||||||
},
|
},
|
||||||
"cas": {
|
"cas": {
|
||||||
"Service %s and %s do not match": "Service %s and %s do not match"
|
"Service %s and %s do not match": "Service %s and %s do not match"
|
||||||
|
@@ -18,7 +18,8 @@
|
|||||||
"The login method: login with password is not enabled for the application": "El método de inicio de sesión: inicio de sesión con contraseña no está habilitado para la aplicación",
|
"The login method: login with password is not enabled for the application": "El método de inicio de sesión: inicio de sesión con contraseña no está habilitado para la aplicación",
|
||||||
"The provider: %s is not enabled for the application": "El proveedor: %s no está habilitado para la aplicación",
|
"The provider: %s is not enabled for the application": "El proveedor: %s no está habilitado para la aplicación",
|
||||||
"Unauthorized operation": "Operación no autorizada",
|
"Unauthorized operation": "Operación no autorizada",
|
||||||
"Unknown authentication type (not password or provider), form = %s": "Tipo de autenticación desconocido (no es contraseña o proveedor), formulario = %s"
|
"Unknown authentication type (not password or provider), form = %s": "Tipo de autenticación desconocido (no es contraseña o proveedor), formulario = %s",
|
||||||
|
"User's tag: %s is not listed in the application's tags": "User's tag: %s is not listed in the application's tags"
|
||||||
},
|
},
|
||||||
"cas": {
|
"cas": {
|
||||||
"Service %s and %s do not match": "Los servicios %s y %s no coinciden"
|
"Service %s and %s do not match": "Los servicios %s y %s no coinciden"
|
||||||
|
@@ -18,7 +18,8 @@
|
|||||||
"The login method: login with password is not enabled for the application": "La méthode de connexion : connexion avec mot de passe n'est pas activée pour l'application",
|
"The login method: login with password is not enabled for the application": "La méthode de connexion : connexion avec mot de passe n'est pas activée pour l'application",
|
||||||
"The provider: %s is not enabled for the application": "Le fournisseur :%s n'est pas activé pour l'application",
|
"The provider: %s is not enabled for the application": "Le fournisseur :%s n'est pas activé pour l'application",
|
||||||
"Unauthorized operation": "Opération non autorisée",
|
"Unauthorized operation": "Opération non autorisée",
|
||||||
"Unknown authentication type (not password or provider), form = %s": "Type d'authentification inconnu (pas de mot de passe ou de fournisseur), formulaire = %s"
|
"Unknown authentication type (not password or provider), form = %s": "Type d'authentification inconnu (pas de mot de passe ou de fournisseur), formulaire = %s",
|
||||||
|
"User's tag: %s is not listed in the application's tags": "User's tag: %s is not listed in the application's tags"
|
||||||
},
|
},
|
||||||
"cas": {
|
"cas": {
|
||||||
"Service %s and %s do not match": "Les services %s et %s ne correspondent pas"
|
"Service %s and %s do not match": "Les services %s et %s ne correspondent pas"
|
||||||
|
@@ -18,7 +18,8 @@
|
|||||||
"The login method: login with password is not enabled for the application": "Metode login: login dengan kata sandi tidak diaktifkan untuk aplikasi tersebut",
|
"The login method: login with password is not enabled for the application": "Metode login: login dengan kata sandi tidak diaktifkan untuk aplikasi tersebut",
|
||||||
"The provider: %s is not enabled for the application": "Penyedia: %s tidak diaktifkan untuk aplikasi ini",
|
"The provider: %s is not enabled for the application": "Penyedia: %s tidak diaktifkan untuk aplikasi ini",
|
||||||
"Unauthorized operation": "Operasi tidak sah",
|
"Unauthorized operation": "Operasi tidak sah",
|
||||||
"Unknown authentication type (not password or provider), form = %s": "Jenis otentikasi tidak diketahui (bukan kata sandi atau pemberi), formulir = %s"
|
"Unknown authentication type (not password or provider), form = %s": "Jenis otentikasi tidak diketahui (bukan kata sandi atau pemberi), formulir = %s",
|
||||||
|
"User's tag: %s is not listed in the application's tags": "User's tag: %s is not listed in the application's tags"
|
||||||
},
|
},
|
||||||
"cas": {
|
"cas": {
|
||||||
"Service %s and %s do not match": "Layanan %s dan %s tidak cocok"
|
"Service %s and %s do not match": "Layanan %s dan %s tidak cocok"
|
||||||
|
@@ -18,7 +18,8 @@
|
|||||||
"The login method: login with password is not enabled for the application": "ログイン方法:パスワードでのログインはアプリケーションで有効になっていません",
|
"The login method: login with password is not enabled for the application": "ログイン方法:パスワードでのログインはアプリケーションで有効になっていません",
|
||||||
"The provider: %s is not enabled for the application": "プロバイダー:%sはアプリケーションでは有効化されていません",
|
"The provider: %s is not enabled for the application": "プロバイダー:%sはアプリケーションでは有効化されていません",
|
||||||
"Unauthorized operation": "不正操作",
|
"Unauthorized operation": "不正操作",
|
||||||
"Unknown authentication type (not password or provider), form = %s": "不明な認証タイプ(パスワードまたはプロバイダーではない)フォーム=%s"
|
"Unknown authentication type (not password or provider), form = %s": "不明な認証タイプ(パスワードまたはプロバイダーではない)フォーム=%s",
|
||||||
|
"User's tag: %s is not listed in the application's tags": "User's tag: %s is not listed in the application's tags"
|
||||||
},
|
},
|
||||||
"cas": {
|
"cas": {
|
||||||
"Service %s and %s do not match": "サービス%sと%sは一致しません"
|
"Service %s and %s do not match": "サービス%sと%sは一致しません"
|
||||||
|
@@ -18,7 +18,8 @@
|
|||||||
"The login method: login with password is not enabled for the application": "어플리케이션에서는 암호를 사용한 로그인 방법이 활성화되어 있지 않습니다",
|
"The login method: login with password is not enabled for the application": "어플리케이션에서는 암호를 사용한 로그인 방법이 활성화되어 있지 않습니다",
|
||||||
"The provider: %s is not enabled for the application": "제공자 %s은(는) 응용 프로그램에서 활성화되어 있지 않습니다",
|
"The provider: %s is not enabled for the application": "제공자 %s은(는) 응용 프로그램에서 활성화되어 있지 않습니다",
|
||||||
"Unauthorized operation": "무단 조작",
|
"Unauthorized operation": "무단 조작",
|
||||||
"Unknown authentication type (not password or provider), form = %s": "알 수 없는 인증 유형(암호 또는 공급자가 아님), 폼 = %s"
|
"Unknown authentication type (not password or provider), form = %s": "알 수 없는 인증 유형(암호 또는 공급자가 아님), 폼 = %s",
|
||||||
|
"User's tag: %s is not listed in the application's tags": "User's tag: %s is not listed in the application's tags"
|
||||||
},
|
},
|
||||||
"cas": {
|
"cas": {
|
||||||
"Service %s and %s do not match": "서비스 %s와 %s는 일치하지 않습니다"
|
"Service %s and %s do not match": "서비스 %s와 %s는 일치하지 않습니다"
|
||||||
|
@@ -18,7 +18,8 @@
|
|||||||
"The login method: login with password is not enabled for the application": "The login method: login with password is not enabled for the application",
|
"The login method: login with password is not enabled for the application": "The login method: login with password is not enabled for the application",
|
||||||
"The provider: %s is not enabled for the application": "The provider: %s is not enabled for the application",
|
"The provider: %s is not enabled for the application": "The provider: %s is not enabled for the application",
|
||||||
"Unauthorized operation": "Unauthorized operation",
|
"Unauthorized operation": "Unauthorized operation",
|
||||||
"Unknown authentication type (not password or provider), form = %s": "Unknown authentication type (not password or provider), form = %s"
|
"Unknown authentication type (not password or provider), form = %s": "Unknown authentication type (not password or provider), form = %s",
|
||||||
|
"User's tag: %s is not listed in the application's tags": "User's tag: %s is not listed in the application's tags"
|
||||||
},
|
},
|
||||||
"cas": {
|
"cas": {
|
||||||
"Service %s and %s do not match": "Service %s and %s do not match"
|
"Service %s and %s do not match": "Service %s and %s do not match"
|
||||||
|
@@ -18,7 +18,8 @@
|
|||||||
"The login method: login with password is not enabled for the application": "Метод входа: вход с паролем не включен для приложения",
|
"The login method: login with password is not enabled for the application": "Метод входа: вход с паролем не включен для приложения",
|
||||||
"The provider: %s is not enabled for the application": "Провайдер: %s не включен для приложения",
|
"The provider: %s is not enabled for the application": "Провайдер: %s не включен для приложения",
|
||||||
"Unauthorized operation": "Несанкционированная операция",
|
"Unauthorized operation": "Несанкционированная операция",
|
||||||
"Unknown authentication type (not password or provider), form = %s": "Неизвестный тип аутентификации (не пароль и не провайдер), форма = %s"
|
"Unknown authentication type (not password or provider), form = %s": "Неизвестный тип аутентификации (не пароль и не провайдер), форма = %s",
|
||||||
|
"User's tag: %s is not listed in the application's tags": "User's tag: %s is not listed in the application's tags"
|
||||||
},
|
},
|
||||||
"cas": {
|
"cas": {
|
||||||
"Service %s and %s do not match": "Сервисы %s и %s не совпадают"
|
"Service %s and %s do not match": "Сервисы %s и %s не совпадают"
|
||||||
|
@@ -18,7 +18,8 @@
|
|||||||
"The login method: login with password is not enabled for the application": "Phương thức đăng nhập: đăng nhập bằng mật khẩu không được kích hoạt cho ứng dụng",
|
"The login method: login with password is not enabled for the application": "Phương thức đăng nhập: đăng nhập bằng mật khẩu không được kích hoạt cho ứng dụng",
|
||||||
"The provider: %s is not enabled for the application": "Nhà cung cấp: %s không được kích hoạt cho ứng dụng",
|
"The provider: %s is not enabled for the application": "Nhà cung cấp: %s không được kích hoạt cho ứng dụng",
|
||||||
"Unauthorized operation": "Hoạt động không được ủy quyền",
|
"Unauthorized operation": "Hoạt động không được ủy quyền",
|
||||||
"Unknown authentication type (not password or provider), form = %s": "Loại xác thực không xác định (không phải mật khẩu hoặc nhà cung cấp), biểu mẫu = %s"
|
"Unknown authentication type (not password or provider), form = %s": "Loại xác thực không xác định (không phải mật khẩu hoặc nhà cung cấp), biểu mẫu = %s",
|
||||||
|
"User's tag: %s is not listed in the application's tags": "User's tag: %s is not listed in the application's tags"
|
||||||
},
|
},
|
||||||
"cas": {
|
"cas": {
|
||||||
"Service %s and %s do not match": "Dịch sang tiếng Việt: Dịch vụ %s và %s không khớp"
|
"Service %s and %s do not match": "Dịch sang tiếng Việt: Dịch vụ %s và %s không khớp"
|
||||||
|
@@ -18,7 +18,8 @@
|
|||||||
"The login method: login with password is not enabled for the application": "该应用禁止采用密码登录方式",
|
"The login method: login with password is not enabled for the application": "该应用禁止采用密码登录方式",
|
||||||
"The provider: %s is not enabled for the application": "该应用的提供商: %s未被启用",
|
"The provider: %s is not enabled for the application": "该应用的提供商: %s未被启用",
|
||||||
"Unauthorized operation": "未授权的操作",
|
"Unauthorized operation": "未授权的操作",
|
||||||
"Unknown authentication type (not password or provider), form = %s": "未知的认证类型(非密码或第三方提供商):%s"
|
"Unknown authentication type (not password or provider), form = %s": "未知的认证类型(非密码或第三方提供商):%s",
|
||||||
|
"User's tag: %s is not listed in the application's tags": "用户的标签: %s不在该应用的标签列表中"
|
||||||
},
|
},
|
||||||
"cas": {
|
"cas": {
|
||||||
"Service %s and %s do not match": "服务%s与%s不匹配"
|
"Service %s and %s do not match": "服务%s与%s不匹配"
|
||||||
|
@@ -20,32 +20,37 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
_ "net/url"
|
|
||||||
_ "time"
|
|
||||||
|
|
||||||
|
"github.com/casdoor/casdoor/util"
|
||||||
|
"github.com/mitchellh/mapstructure"
|
||||||
"golang.org/x/oauth2"
|
"golang.org/x/oauth2"
|
||||||
)
|
)
|
||||||
|
|
||||||
type CustomIdProvider struct {
|
type CustomIdProvider struct {
|
||||||
Client *http.Client
|
Client *http.Client
|
||||||
Config *oauth2.Config
|
Config *oauth2.Config
|
||||||
UserInfoUrl string
|
|
||||||
|
UserInfoURL string
|
||||||
|
TokenURL string
|
||||||
|
AuthURL string
|
||||||
|
UserMapping map[string]string
|
||||||
|
Scopes []string
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewCustomIdProvider(clientId string, clientSecret string, redirectUrl string, authUrl string, tokenUrl string, userInfoUrl string) *CustomIdProvider {
|
func NewCustomIdProvider(idpInfo *ProviderInfo, redirectUrl string) *CustomIdProvider {
|
||||||
idp := &CustomIdProvider{}
|
idp := &CustomIdProvider{}
|
||||||
idp.UserInfoUrl = userInfoUrl
|
|
||||||
|
|
||||||
config := &oauth2.Config{
|
idp.Config = &oauth2.Config{
|
||||||
ClientID: clientId,
|
ClientID: idpInfo.ClientId,
|
||||||
ClientSecret: clientSecret,
|
ClientSecret: idpInfo.ClientSecret,
|
||||||
RedirectURL: redirectUrl,
|
RedirectURL: redirectUrl,
|
||||||
Endpoint: oauth2.Endpoint{
|
Endpoint: oauth2.Endpoint{
|
||||||
AuthURL: authUrl,
|
AuthURL: idpInfo.AuthURL,
|
||||||
TokenURL: tokenUrl,
|
TokenURL: idpInfo.TokenURL,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
idp.Config = config
|
idp.UserInfoURL = idpInfo.UserInfoURL
|
||||||
|
idp.UserMapping = idpInfo.UserMapping
|
||||||
|
|
||||||
return idp
|
return idp
|
||||||
}
|
}
|
||||||
@@ -60,22 +65,20 @@ func (idp *CustomIdProvider) GetToken(code string) (*oauth2.Token, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type CustomUserInfo struct {
|
type CustomUserInfo struct {
|
||||||
Id string `json:"sub"`
|
Id string `mapstructure:"id"`
|
||||||
Name string `json:"preferred_username,omitempty"`
|
Username string `mapstructure:"username"`
|
||||||
DisplayName string `json:"name"`
|
DisplayName string `mapstructure:"displayName"`
|
||||||
Email string `json:"email"`
|
Email string `mapstructure:"email"`
|
||||||
AvatarUrl string `json:"picture"`
|
AvatarUrl string `mapstructure:"avatarUrl"`
|
||||||
Status string `json:"status"`
|
|
||||||
Msg string `json:"msg"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (idp *CustomIdProvider) GetUserInfo(token *oauth2.Token) (*UserInfo, error) {
|
func (idp *CustomIdProvider) GetUserInfo(token *oauth2.Token) (*UserInfo, error) {
|
||||||
ctUserinfo := &CustomUserInfo{}
|
|
||||||
accessToken := token.AccessToken
|
accessToken := token.AccessToken
|
||||||
request, err := http.NewRequest("GET", idp.UserInfoUrl, nil)
|
request, err := http.NewRequest("GET", idp.UserInfoURL, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// add accessToken to request header
|
// add accessToken to request header
|
||||||
request.Header.Add("Authorization", fmt.Sprintf("Bearer %s", accessToken))
|
request.Header.Add("Authorization", fmt.Sprintf("Bearer %s", accessToken))
|
||||||
resp, err := idp.Client.Do(request)
|
resp, err := idp.Client.Do(request)
|
||||||
@@ -89,21 +92,40 @@ func (idp *CustomIdProvider) GetUserInfo(token *oauth2.Token) (*UserInfo, error)
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
err = json.Unmarshal(data, ctUserinfo)
|
var dataMap map[string]interface{}
|
||||||
|
err = json.Unmarshal(data, &dataMap)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if ctUserinfo.Status != "" {
|
// map user info
|
||||||
return nil, fmt.Errorf("err: %s", ctUserinfo.Msg)
|
for k, v := range idp.UserMapping {
|
||||||
|
_, ok := dataMap[v]
|
||||||
|
if !ok {
|
||||||
|
return nil, fmt.Errorf("cannot find %s in user from castom provider", v)
|
||||||
|
}
|
||||||
|
dataMap[k] = dataMap[v]
|
||||||
|
}
|
||||||
|
|
||||||
|
// try to parse id to string
|
||||||
|
id, err := util.ParseIdToString(dataMap["id"])
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
dataMap["id"] = id
|
||||||
|
|
||||||
|
customUserinfo := &CustomUserInfo{}
|
||||||
|
err = mapstructure.Decode(dataMap, customUserinfo)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
userInfo := &UserInfo{
|
userInfo := &UserInfo{
|
||||||
Id: ctUserinfo.Id,
|
Id: customUserinfo.Id,
|
||||||
Username: ctUserinfo.Name,
|
Username: customUserinfo.Username,
|
||||||
DisplayName: ctUserinfo.DisplayName,
|
DisplayName: customUserinfo.DisplayName,
|
||||||
Email: ctUserinfo.Email,
|
Email: customUserinfo.Email,
|
||||||
AvatarUrl: ctUserinfo.AvatarUrl,
|
AvatarUrl: customUserinfo.AvatarUrl,
|
||||||
}
|
}
|
||||||
return userInfo, nil
|
return userInfo, nil
|
||||||
}
|
}
|
||||||
|
80
idp/metamask.go
Normal file
80
idp/metamask.go
Normal file
@@ -0,0 +1,80 @@
|
|||||||
|
// Copyright 2023 The Casdoor Authors. All Rights Reserved.
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
package idp
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"net/http"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"golang.org/x/oauth2"
|
||||||
|
)
|
||||||
|
|
||||||
|
const Web3AuthTokenKey = "web3AuthToken"
|
||||||
|
|
||||||
|
type MetaMaskIdProvider struct {
|
||||||
|
Client *http.Client
|
||||||
|
}
|
||||||
|
|
||||||
|
type Web3AuthToken struct {
|
||||||
|
Address string `json:"address"`
|
||||||
|
Nonce string `json:"nonce"`
|
||||||
|
CreateAt uint64 `json:"createAt"`
|
||||||
|
TypedData string `json:"typedData"`
|
||||||
|
Signature string `json:"signature"` // signature for typed data
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewMetaMaskIdProvider() *MetaMaskIdProvider {
|
||||||
|
idp := &MetaMaskIdProvider{}
|
||||||
|
return idp
|
||||||
|
}
|
||||||
|
|
||||||
|
func (idp *MetaMaskIdProvider) SetHttpClient(client *http.Client) {
|
||||||
|
idp.Client = client
|
||||||
|
}
|
||||||
|
|
||||||
|
func (idp *MetaMaskIdProvider) GetToken(code string) (*oauth2.Token, error) {
|
||||||
|
web3AuthToken := Web3AuthToken{}
|
||||||
|
if err := json.Unmarshal([]byte(code), &web3AuthToken); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
token := &oauth2.Token{
|
||||||
|
AccessToken: web3AuthToken.Signature,
|
||||||
|
TokenType: "Bearer",
|
||||||
|
Expiry: time.Now().AddDate(0, 1, 0),
|
||||||
|
}
|
||||||
|
|
||||||
|
token = token.WithExtra(map[string]interface{}{
|
||||||
|
Web3AuthTokenKey: web3AuthToken,
|
||||||
|
})
|
||||||
|
return token, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (idp *MetaMaskIdProvider) GetUserInfo(token *oauth2.Token) (*UserInfo, error) {
|
||||||
|
// TODO use "github.com/ethereum/go-ethereum" to check address's eth balance or transaction
|
||||||
|
web3AuthToken, ok := token.Extra(Web3AuthTokenKey).(Web3AuthToken)
|
||||||
|
if !ok {
|
||||||
|
return nil, errors.New("invalid web3AuthToken")
|
||||||
|
}
|
||||||
|
userInfo := &UserInfo{
|
||||||
|
Id: web3AuthToken.Address,
|
||||||
|
Username: web3AuthToken.Address,
|
||||||
|
DisplayName: web3AuthToken.Address,
|
||||||
|
AvatarUrl: fmt.Sprintf("metamask:%v", web3AuthToken.Address),
|
||||||
|
}
|
||||||
|
return userInfo, nil
|
||||||
|
}
|
125
idp/provider.go
125
idp/provider.go
@@ -32,72 +32,91 @@ type UserInfo struct {
|
|||||||
AvatarUrl string
|
AvatarUrl string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type ProviderInfo struct {
|
||||||
|
Type string
|
||||||
|
SubType string
|
||||||
|
ClientId string
|
||||||
|
ClientSecret string
|
||||||
|
AppId string
|
||||||
|
HostUrl string
|
||||||
|
RedirectUrl string
|
||||||
|
|
||||||
|
TokenURL string
|
||||||
|
AuthURL string
|
||||||
|
UserInfoURL string
|
||||||
|
UserMapping map[string]string
|
||||||
|
}
|
||||||
|
|
||||||
type IdProvider interface {
|
type IdProvider interface {
|
||||||
SetHttpClient(client *http.Client)
|
SetHttpClient(client *http.Client)
|
||||||
GetToken(code string) (*oauth2.Token, error)
|
GetToken(code string) (*oauth2.Token, error)
|
||||||
GetUserInfo(token *oauth2.Token) (*UserInfo, error)
|
GetUserInfo(token *oauth2.Token) (*UserInfo, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetIdProvider(typ string, subType string, clientId string, clientSecret string, appId string, redirectUrl string, hostUrl string, authUrl string, tokenUrl string, userInfoUrl string) IdProvider {
|
func GetIdProvider(idpInfo *ProviderInfo, redirectUrl string) IdProvider {
|
||||||
if typ == "GitHub" {
|
switch idpInfo.Type {
|
||||||
return NewGithubIdProvider(clientId, clientSecret, redirectUrl)
|
case "GitHub":
|
||||||
} else if typ == "Google" {
|
return NewGithubIdProvider(idpInfo.ClientId, idpInfo.ClientSecret, redirectUrl)
|
||||||
return NewGoogleIdProvider(clientId, clientSecret, redirectUrl)
|
case "Google":
|
||||||
} else if typ == "QQ" {
|
return NewGoogleIdProvider(idpInfo.ClientId, idpInfo.ClientSecret, redirectUrl)
|
||||||
return NewQqIdProvider(clientId, clientSecret, redirectUrl)
|
case "QQ":
|
||||||
} else if typ == "WeChat" {
|
return NewQqIdProvider(idpInfo.ClientId, idpInfo.ClientSecret, redirectUrl)
|
||||||
return NewWeChatIdProvider(clientId, clientSecret, redirectUrl)
|
case "WeChat":
|
||||||
} else if typ == "Facebook" {
|
return NewWeChatIdProvider(idpInfo.ClientId, idpInfo.ClientSecret, redirectUrl)
|
||||||
return NewFacebookIdProvider(clientId, clientSecret, redirectUrl)
|
case "Facebook":
|
||||||
} else if typ == "DingTalk" {
|
return NewFacebookIdProvider(idpInfo.ClientId, idpInfo.ClientSecret, redirectUrl)
|
||||||
return NewDingTalkIdProvider(clientId, clientSecret, redirectUrl)
|
case "DingTalk":
|
||||||
} else if typ == "Weibo" {
|
return NewDingTalkIdProvider(idpInfo.ClientId, idpInfo.ClientSecret, redirectUrl)
|
||||||
return NewWeiBoIdProvider(clientId, clientSecret, redirectUrl)
|
case "Weibo":
|
||||||
} else if typ == "Gitee" {
|
return NewWeiBoIdProvider(idpInfo.ClientId, idpInfo.ClientSecret, redirectUrl)
|
||||||
return NewGiteeIdProvider(clientId, clientSecret, redirectUrl)
|
case "Gitee":
|
||||||
} else if typ == "LinkedIn" {
|
return NewGiteeIdProvider(idpInfo.ClientId, idpInfo.ClientSecret, redirectUrl)
|
||||||
return NewLinkedInIdProvider(clientId, clientSecret, redirectUrl)
|
case "LinkedIn":
|
||||||
} else if typ == "WeCom" {
|
return NewLinkedInIdProvider(idpInfo.ClientId, idpInfo.ClientSecret, redirectUrl)
|
||||||
if subType == "Internal" {
|
case "WeCom":
|
||||||
return NewWeComInternalIdProvider(clientId, clientSecret, redirectUrl)
|
if idpInfo.SubType == "Internal" {
|
||||||
} else if subType == "Third-party" {
|
return NewWeComInternalIdProvider(idpInfo.ClientId, idpInfo.ClientSecret, redirectUrl)
|
||||||
return NewWeComIdProvider(clientId, clientSecret, redirectUrl)
|
} else if idpInfo.SubType == "Third-party" {
|
||||||
|
return NewWeComIdProvider(idpInfo.ClientId, idpInfo.ClientSecret, redirectUrl)
|
||||||
} else {
|
} else {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
} else if typ == "Lark" {
|
case "Lark":
|
||||||
return NewLarkIdProvider(clientId, clientSecret, redirectUrl)
|
return NewLarkIdProvider(idpInfo.ClientId, idpInfo.ClientSecret, redirectUrl)
|
||||||
} else if typ == "GitLab" {
|
case "GitLab":
|
||||||
return NewGitlabIdProvider(clientId, clientSecret, redirectUrl)
|
return NewGitlabIdProvider(idpInfo.ClientId, idpInfo.ClientSecret, redirectUrl)
|
||||||
} else if typ == "Adfs" {
|
case "Adfs":
|
||||||
return NewAdfsIdProvider(clientId, clientSecret, redirectUrl, hostUrl)
|
return NewAdfsIdProvider(idpInfo.ClientId, idpInfo.ClientSecret, redirectUrl, idpInfo.HostUrl)
|
||||||
} else if typ == "Baidu" {
|
case "Baidu":
|
||||||
return NewBaiduIdProvider(clientId, clientSecret, redirectUrl)
|
return NewBaiduIdProvider(idpInfo.ClientId, idpInfo.ClientSecret, redirectUrl)
|
||||||
} else if typ == "Alipay" {
|
case "Alipay":
|
||||||
return NewAlipayIdProvider(clientId, clientSecret, redirectUrl)
|
return NewAlipayIdProvider(idpInfo.ClientId, idpInfo.ClientSecret, redirectUrl)
|
||||||
} else if typ == "Custom" {
|
case "Custom":
|
||||||
return NewCustomIdProvider(clientId, clientSecret, redirectUrl, authUrl, tokenUrl, userInfoUrl)
|
return NewCustomIdProvider(idpInfo, redirectUrl)
|
||||||
} else if typ == "Infoflow" {
|
case "Infoflow":
|
||||||
if subType == "Internal" {
|
if idpInfo.SubType == "Internal" {
|
||||||
return NewInfoflowInternalIdProvider(clientId, clientSecret, appId, redirectUrl)
|
return NewInfoflowInternalIdProvider(idpInfo.ClientId, idpInfo.ClientSecret, idpInfo.AppId, redirectUrl)
|
||||||
} else if subType == "Third-party" {
|
} else if idpInfo.SubType == "Third-party" {
|
||||||
return NewInfoflowIdProvider(clientId, clientSecret, appId, redirectUrl)
|
return NewInfoflowIdProvider(idpInfo.ClientId, idpInfo.ClientSecret, idpInfo.AppId, redirectUrl)
|
||||||
} else {
|
} else {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
} else if typ == "Casdoor" {
|
case "Casdoor":
|
||||||
return NewCasdoorIdProvider(clientId, clientSecret, redirectUrl, hostUrl)
|
return NewCasdoorIdProvider(idpInfo.ClientId, idpInfo.ClientSecret, redirectUrl, idpInfo.HostUrl)
|
||||||
} else if typ == "Okta" {
|
case "Okta":
|
||||||
return NewOktaIdProvider(clientId, clientSecret, redirectUrl, hostUrl)
|
return NewOktaIdProvider(idpInfo.ClientId, idpInfo.ClientSecret, redirectUrl, idpInfo.HostUrl)
|
||||||
} else if typ == "Douyin" {
|
case "Douyin":
|
||||||
return NewDouyinIdProvider(clientId, clientSecret, redirectUrl)
|
return NewDouyinIdProvider(idpInfo.ClientId, idpInfo.ClientSecret, redirectUrl)
|
||||||
} else if isGothSupport(typ) {
|
case "Bilibili":
|
||||||
return NewGothIdProvider(typ, clientId, clientSecret, redirectUrl, hostUrl)
|
return NewBilibiliIdProvider(idpInfo.ClientId, idpInfo.ClientSecret, redirectUrl)
|
||||||
} else if typ == "Bilibili" {
|
case "MetaMask":
|
||||||
return NewBilibiliIdProvider(clientId, clientSecret, redirectUrl)
|
return NewMetaMaskIdProvider()
|
||||||
|
default:
|
||||||
|
if isGothSupport(idpInfo.Type) {
|
||||||
|
return NewGothIdProvider(idpInfo.Type, idpInfo.ClientId, idpInfo.ClientSecret, redirectUrl, idpInfo.HostUrl)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var gothList = []string{
|
var gothList = []string{
|
||||||
|
@@ -198,12 +198,22 @@ func (idp *WeChatIdProvider) GetUserInfo(token *oauth2.Token) (*UserInfo, error)
|
|||||||
func GetWechatOfficialAccountAccessToken(clientId string, clientSecret string) (string, error) {
|
func GetWechatOfficialAccountAccessToken(clientId string, clientSecret string) (string, error) {
|
||||||
accessTokenUrl := fmt.Sprintf("https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=%s&secret=%s", clientId, clientSecret)
|
accessTokenUrl := fmt.Sprintf("https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=%s&secret=%s", clientId, clientSecret)
|
||||||
request, err := http.NewRequest("GET", accessTokenUrl, nil)
|
request, err := http.NewRequest("GET", accessTokenUrl, nil)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
client := new(http.Client)
|
client := new(http.Client)
|
||||||
resp, err := client.Do(request)
|
resp, err := client.Do(request)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
|
|
||||||
respBytes, err := ioutil.ReadAll(resp.Body)
|
respBytes, err := ioutil.ReadAll(resp.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
var data struct {
|
var data struct {
|
||||||
ExpireIn int `json:"expires_in"`
|
ExpireIn int `json:"expires_in"`
|
||||||
AccessToken string `json:"access_token"`
|
AccessToken string `json:"access_token"`
|
||||||
@@ -212,20 +222,30 @@ func GetWechatOfficialAccountAccessToken(clientId string, clientSecret string) (
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
return data.AccessToken, nil
|
return data.AccessToken, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetWechatOfficialAccountQRCode(clientId string, clientSecret string) (string, error) {
|
func GetWechatOfficialAccountQRCode(clientId string, clientSecret string) (string, error) {
|
||||||
accessToken, err := GetWechatOfficialAccountAccessToken(clientId, clientSecret)
|
accessToken, err := GetWechatOfficialAccountAccessToken(clientId, clientSecret)
|
||||||
client := new(http.Client)
|
client := new(http.Client)
|
||||||
params := "{\"action_name\": \"QR_LIMIT_STR_SCENE\", \"action_info\": {\"scene\": {\"scene_str\": \"test\"}}}"
|
|
||||||
|
weChatEndpoint := "https://api.weixin.qq.com/cgi-bin/qrcode/create"
|
||||||
|
qrCodeUrl := fmt.Sprintf("%s?access_token=%s", weChatEndpoint, accessToken)
|
||||||
|
params := `{"action_name": "QR_LIMIT_STR_SCENE", "action_info": {"scene": {"scene_str": "test"}}}`
|
||||||
|
|
||||||
bodyData := bytes.NewReader([]byte(params))
|
bodyData := bytes.NewReader([]byte(params))
|
||||||
qrCodeUrl := fmt.Sprintf("https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token=%s", accessToken)
|
|
||||||
requeset, err := http.NewRequest("POST", qrCodeUrl, bodyData)
|
requeset, err := http.NewRequest("POST", qrCodeUrl, bodyData)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
resp, err := client.Do(requeset)
|
resp, err := client.Do(requeset)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
|
|
||||||
respBytes, err := ioutil.ReadAll(resp.Body)
|
respBytes, err := ioutil.ReadAll(resp.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
|
@@ -34,7 +34,7 @@ func StartLdapServer() {
|
|||||||
server.Handle(routes)
|
server.Handle(routes)
|
||||||
err := server.ListenAndServe("0.0.0.0:" + conf.GetConfigString("ldapServerPort"))
|
err := server.ListenAndServe("0.0.0.0:" + conf.GetConfigString("ldapServerPort"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
log.Printf("StartLdapServer() failed, ErrMsg = %s", err.Error())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -15,8 +15,10 @@
|
|||||||
package object
|
package object
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"database/sql"
|
||||||
"fmt"
|
"fmt"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/beego/beego"
|
"github.com/beego/beego"
|
||||||
"github.com/casdoor/casdoor/conf"
|
"github.com/casdoor/casdoor/conf"
|
||||||
@@ -46,6 +48,11 @@ func InitConfig() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func InitAdapter() {
|
func InitAdapter() {
|
||||||
|
err := createDatabaseForPostgres(conf.GetConfigString("driverName"), conf.GetConfigDataSourceName(), conf.GetConfigString("dbName"))
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
adapter = NewAdapter(conf.GetConfigString("driverName"), conf.GetConfigDataSourceName(), conf.GetConfigString("dbName"))
|
adapter = NewAdapter(conf.GetConfigString("driverName"), conf.GetConfigDataSourceName(), conf.GetConfigString("dbName"))
|
||||||
|
|
||||||
tableNamePrefix := conf.GetConfigString("tableNamePrefix")
|
tableNamePrefix := conf.GetConfigString("tableNamePrefix")
|
||||||
@@ -96,7 +103,32 @@ func NewAdapter(driverName string, dataSourceName string, dbName string) *Adapte
|
|||||||
return a
|
return a
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func createDatabaseForPostgres(driverName string, dataSourceName string, dbName string) error {
|
||||||
|
if driverName == "postgres" {
|
||||||
|
db, err := sql.Open(driverName, dataSourceName)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer db.Close()
|
||||||
|
|
||||||
|
_, err = db.Exec(fmt.Sprintf("CREATE DATABASE %s;", dbName))
|
||||||
|
if err != nil {
|
||||||
|
if !strings.Contains(err.Error(), "already exists") {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
} else {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (a *Adapter) CreateDatabase() error {
|
func (a *Adapter) CreateDatabase() error {
|
||||||
|
if a.driverName == "postgres" {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
engine, err := xorm.NewEngine(a.driverName, a.dataSourceName)
|
engine, err := xorm.NewEngine(a.driverName, a.dataSourceName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -275,7 +307,7 @@ func GetSession(owner string, offset, limit int, field, value, sortField, sortOr
|
|||||||
session = session.And("owner=?", owner)
|
session = session.And("owner=?", owner)
|
||||||
}
|
}
|
||||||
if field != "" && value != "" {
|
if field != "" && value != "" {
|
||||||
if filterField(field) {
|
if util.FilterField(field) {
|
||||||
session = session.And(fmt.Sprintf("%s like ?", util.SnakeString(field)), fmt.Sprintf("%%%s%%", value))
|
session = session.And(fmt.Sprintf("%s like ?", util.SnakeString(field)), fmt.Sprintf("%%%s%%", value))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -303,7 +335,7 @@ func GetSessionForUser(owner string, offset, limit int, field, value, sortField,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if field != "" && value != "" {
|
if field != "" && value != "" {
|
||||||
if filterField(field) {
|
if util.FilterField(field) {
|
||||||
if offset != -1 {
|
if offset != -1 {
|
||||||
field = fmt.Sprintf("a.%s", field)
|
field = fmt.Sprintf("a.%s", field)
|
||||||
}
|
}
|
||||||
|
@@ -57,6 +57,7 @@ type Application struct {
|
|||||||
SignupItems []*SignupItem `xorm:"varchar(1000)" json:"signupItems"`
|
SignupItems []*SignupItem `xorm:"varchar(1000)" json:"signupItems"`
|
||||||
GrantTypes []string `xorm:"varchar(1000)" json:"grantTypes"`
|
GrantTypes []string `xorm:"varchar(1000)" json:"grantTypes"`
|
||||||
OrganizationObj *Organization `xorm:"-" json:"organizationObj"`
|
OrganizationObj *Organization `xorm:"-" json:"organizationObj"`
|
||||||
|
Tags []string `xorm:"mediumtext" json:"tags"`
|
||||||
|
|
||||||
ClientId string `xorm:"varchar(100)" json:"clientId"`
|
ClientId string `xorm:"varchar(100)" json:"clientId"`
|
||||||
ClientSecret string `xorm:"varchar(100)" json:"clientSecret"`
|
ClientSecret string `xorm:"varchar(100)" json:"clientSecret"`
|
||||||
|
@@ -16,7 +16,6 @@ package object
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"regexp"
|
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
"unicode"
|
"unicode"
|
||||||
@@ -28,21 +27,11 @@ import (
|
|||||||
goldap "github.com/go-ldap/ldap/v3"
|
goldap "github.com/go-ldap/ldap/v3"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
|
||||||
reWhiteSpace *regexp.Regexp
|
|
||||||
reFieldWhiteList *regexp.Regexp
|
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
const (
|
||||||
SigninWrongTimesLimit = 5
|
SigninWrongTimesLimit = 5
|
||||||
LastSignWrongTimeDuration = time.Minute * 15
|
LastSignWrongTimeDuration = time.Minute * 15
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
|
||||||
reWhiteSpace, _ = regexp.Compile(`\s`)
|
|
||||||
reFieldWhiteList, _ = regexp.Compile(`^[A-Za-z0-9]+$`)
|
|
||||||
}
|
|
||||||
|
|
||||||
func CheckUserSignup(application *Application, organization *Organization, form *form.AuthForm, lang string) string {
|
func CheckUserSignup(application *Application, organization *Organization, form *form.AuthForm, lang string) string {
|
||||||
if organization == nil {
|
if organization == nil {
|
||||||
return i18n.Translate(lang, "check:Organization does not exist")
|
return i18n.Translate(lang, "check:Organization does not exist")
|
||||||
@@ -58,7 +47,7 @@ func CheckUserSignup(application *Application, organization *Organization, form
|
|||||||
if util.IsEmailValid(form.Username) {
|
if util.IsEmailValid(form.Username) {
|
||||||
return i18n.Translate(lang, "check:Username cannot be an email address")
|
return i18n.Translate(lang, "check:Username cannot be an email address")
|
||||||
}
|
}
|
||||||
if reWhiteSpace.MatchString(form.Username) {
|
if util.ReWhiteSpace.MatchString(form.Username) {
|
||||||
return i18n.Translate(lang, "check:Username cannot contain white spaces")
|
return i18n.Translate(lang, "check:Username cannot contain white spaces")
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -294,10 +283,6 @@ func CheckUserPassword(organization string, username string, password string, la
|
|||||||
return user, ""
|
return user, ""
|
||||||
}
|
}
|
||||||
|
|
||||||
func filterField(field string) bool {
|
|
||||||
return reFieldWhiteList.MatchString(field)
|
|
||||||
}
|
|
||||||
|
|
||||||
func CheckUserPermission(requestUserId, userId string, strict bool, lang string) (bool, error) {
|
func CheckUserPermission(requestUserId, userId string, strict bool, lang string) (bool, error) {
|
||||||
if requestUserId == "" {
|
if requestUserId == "" {
|
||||||
return false, fmt.Errorf(i18n.Translate(lang, "general:Please login first"))
|
return false, fmt.Errorf(i18n.Translate(lang, "general:Please login first"))
|
||||||
@@ -397,8 +382,8 @@ func CheckUsername(username string, lang string) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// https://stackoverflow.com/questions/58726546/github-username-convention-using-regex
|
// https://stackoverflow.com/questions/58726546/github-username-convention-using-regex
|
||||||
re, _ := regexp.Compile("^[a-zA-Z0-9]+((?:-[a-zA-Z0-9]+)|(?:_[a-zA-Z0-9]+))*$")
|
|
||||||
if !re.MatchString(username) {
|
if !util.ReUserName.MatchString(username) {
|
||||||
return i18n.Translate(lang, "check:The username may only contain alphanumeric characters, underlines or hyphens, cannot have consecutive hyphens or underlines, and cannot begin or end with a hyphen or underline.")
|
return i18n.Translate(lang, "check:The username may only contain alphanumeric characters, underlines or hyphens, cannot have consecutive hyphens or underlines, and cannot begin or end with a hyphen or underline.")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -107,6 +107,11 @@ func UpdateGroup(id string, group *Group) (bool, error) {
|
|||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
err = checkGroupName(group.Name)
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
|
||||||
if name != group.Name {
|
if name != group.Name {
|
||||||
err := GroupChangeTrigger(name, group.Name)
|
err := GroupChangeTrigger(name, group.Name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -123,6 +128,11 @@ func UpdateGroup(id string, group *Group) (bool, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func AddGroup(group *Group) (bool, error) {
|
func AddGroup(group *Group) (bool, error) {
|
||||||
|
err := checkGroupName(group.Name)
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
|
||||||
affected, err := adapter.Engine.Insert(group)
|
affected, err := adapter.Engine.Insert(group)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
@@ -168,6 +178,17 @@ func DeleteGroup(group *Group) (bool, error) {
|
|||||||
return affected != 0, nil
|
return affected != 0, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func checkGroupName(name string) error {
|
||||||
|
exist, err := adapter.Engine.Exist(&Organization{Owner: "admin", Name: name})
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if exist {
|
||||||
|
return errors.New("group name can't be same as the organization name")
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (group *Group) GetId() string {
|
func (group *Group) GetId() string {
|
||||||
return fmt.Sprintf("%s/%s", group.Owner, group.Name)
|
return fmt.Sprintf("%s/%s", group.Owner, group.Name)
|
||||||
}
|
}
|
||||||
@@ -225,7 +246,7 @@ func GetGroupUserCount(groupName string, field, value string) (int64, error) {
|
|||||||
func GetPaginationGroupUsers(groupName string, offset, limit int, field, value, sortField, sortOrder string) ([]*User, error) {
|
func GetPaginationGroupUsers(groupName string, offset, limit int, field, value, sortField, sortOrder string) ([]*User, error) {
|
||||||
users := []*User{}
|
users := []*User{}
|
||||||
session := adapter.Engine.Table("user").
|
session := adapter.Engine.Table("user").
|
||||||
Where(builder.Like{"`groups`", groupName})
|
Where(builder.Like{"`groups`", groupName + "\""})
|
||||||
|
|
||||||
if offset != -1 && limit != -1 {
|
if offset != -1 && limit != -1 {
|
||||||
session.Limit(limit, offset)
|
session.Limit(limit, offset)
|
||||||
@@ -255,7 +276,7 @@ func GetPaginationGroupUsers(groupName string, offset, limit int, field, value,
|
|||||||
func GetGroupUsers(groupName string) ([]*User, error) {
|
func GetGroupUsers(groupName string) ([]*User, error) {
|
||||||
users := []*User{}
|
users := []*User{}
|
||||||
err := adapter.Engine.Table("user").
|
err := adapter.Engine.Table("user").
|
||||||
Where(builder.Like{"`groups`", groupName}).
|
Where(builder.Like{"`groups`", groupName + "\""}).
|
||||||
Find(&users)
|
Find(&users)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@@ -61,7 +61,7 @@ func getBuiltInAccountItems() []*AccountItem {
|
|||||||
{Name: "Signup application", Visible: true, ViewRule: "Public", ModifyRule: "Admin"},
|
{Name: "Signup application", Visible: true, ViewRule: "Public", ModifyRule: "Admin"},
|
||||||
{Name: "Roles", Visible: true, ViewRule: "Public", ModifyRule: "Immutable"},
|
{Name: "Roles", Visible: true, ViewRule: "Public", ModifyRule: "Immutable"},
|
||||||
{Name: "Permissions", Visible: true, ViewRule: "Public", ModifyRule: "Immutable"},
|
{Name: "Permissions", Visible: true, ViewRule: "Public", ModifyRule: "Immutable"},
|
||||||
{Name: "Groups", Visible: true, ViewRule: "Public", ModifyRule: "Immutable"},
|
{Name: "Groups", Visible: true, ViewRule: "Public", ModifyRule: "Admin"},
|
||||||
{Name: "3rd-party logins", Visible: true, ViewRule: "Self", ModifyRule: "Self"},
|
{Name: "3rd-party logins", Visible: true, ViewRule: "Self", ModifyRule: "Self"},
|
||||||
{Name: "Properties", Visible: false, ViewRule: "Admin", ModifyRule: "Admin"},
|
{Name: "Properties", Visible: false, ViewRule: "Admin", ModifyRule: "Admin"},
|
||||||
{Name: "Is admin", Visible: true, ViewRule: "Admin", ModifyRule: "Admin"},
|
{Name: "Is admin", Visible: true, ViewRule: "Admin", ModifyRule: "Admin"},
|
||||||
@@ -93,7 +93,7 @@ func initBuiltInOrganization() bool {
|
|||||||
Favicon: fmt.Sprintf("%s/img/casbin/favicon.ico", conf.GetConfigString("staticBaseUrl")),
|
Favicon: fmt.Sprintf("%s/img/casbin/favicon.ico", conf.GetConfigString("staticBaseUrl")),
|
||||||
PasswordType: "plain",
|
PasswordType: "plain",
|
||||||
PasswordOptions: []string{"AtLeast6"},
|
PasswordOptions: []string{"AtLeast6"},
|
||||||
CountryCodes: []string{"US", "ES", "CN", "FR", "DE", "GB", "JP", "KR", "VN", "ID", "SG", "IN"},
|
CountryCodes: []string{"US", "ES", "FR", "DE", "GB", "CN", "JP", "KR", "VN", "ID", "SG", "IN"},
|
||||||
DefaultAvatar: fmt.Sprintf("%s/img/casbin.svg", conf.GetConfigString("staticBaseUrl")),
|
DefaultAvatar: fmt.Sprintf("%s/img/casbin.svg", conf.GetConfigString("staticBaseUrl")),
|
||||||
Tags: []string{},
|
Tags: []string{},
|
||||||
Languages: []string{"en", "zh", "es", "fr", "de", "id", "ja", "ko", "ru", "vi", "pt"},
|
Languages: []string{"en", "zh", "es", "fr", "de", "id", "ja", "ko", "ru", "vi", "pt"},
|
||||||
@@ -130,7 +130,7 @@ func initBuiltInUser() {
|
|||||||
Avatar: fmt.Sprintf("%s/img/casbin.svg", conf.GetConfigString("staticBaseUrl")),
|
Avatar: fmt.Sprintf("%s/img/casbin.svg", conf.GetConfigString("staticBaseUrl")),
|
||||||
Email: "admin@example.com",
|
Email: "admin@example.com",
|
||||||
Phone: "12345678910",
|
Phone: "12345678910",
|
||||||
CountryCode: "CN",
|
CountryCode: "US",
|
||||||
Address: []string{},
|
Address: []string{},
|
||||||
Affiliation: "Example Inc.",
|
Affiliation: "Example Inc.",
|
||||||
Tag: "staff",
|
Tag: "staff",
|
||||||
@@ -184,6 +184,7 @@ func initBuiltInApplication() {
|
|||||||
{Name: "Phone", Visible: true, Required: true, Prompted: false, Rule: "None"},
|
{Name: "Phone", Visible: true, Required: true, Prompted: false, Rule: "None"},
|
||||||
{Name: "Agreement", Visible: true, Required: true, Prompted: false, Rule: "None"},
|
{Name: "Agreement", Visible: true, Required: true, Prompted: false, Rule: "None"},
|
||||||
},
|
},
|
||||||
|
Tags: []string{},
|
||||||
RedirectUris: []string{},
|
RedirectUris: []string{},
|
||||||
ExpireInHours: 168,
|
ExpireInHours: 168,
|
||||||
FormOffset: 2,
|
FormOffset: 2,
|
||||||
|
@@ -145,6 +145,9 @@ func readInitDataFromFile(filePath string) (*InitData, error) {
|
|||||||
if application.RedirectUris == nil {
|
if application.RedirectUris == nil {
|
||||||
application.RedirectUris = []string{}
|
application.RedirectUris = []string{}
|
||||||
}
|
}
|
||||||
|
if application.Tags == nil {
|
||||||
|
application.Tags = []string{}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
for _, permission := range data.Permissions {
|
for _, permission := range data.Permissions {
|
||||||
if permission.Actions == nil {
|
if permission.Actions == nil {
|
||||||
|
@@ -103,6 +103,37 @@ func GetLdap(id string) (*Ldap, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GetMaskedLdap(ldap *Ldap, errs ...error) (*Ldap, error) {
|
||||||
|
if len(errs) > 0 && errs[0] != nil {
|
||||||
|
return nil, errs[0]
|
||||||
|
}
|
||||||
|
|
||||||
|
if ldap == nil {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
if ldap.Password != "" {
|
||||||
|
ldap.Password = "***"
|
||||||
|
}
|
||||||
|
|
||||||
|
return ldap, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetMaskedLdaps(ldaps []*Ldap, errs ...error) ([]*Ldap, error) {
|
||||||
|
if len(errs) > 0 && errs[0] != nil {
|
||||||
|
return nil, errs[0]
|
||||||
|
}
|
||||||
|
|
||||||
|
var err error
|
||||||
|
for _, ldap := range ldaps {
|
||||||
|
ldap, err = GetMaskedLdap(ldap)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ldaps, nil
|
||||||
|
}
|
||||||
|
|
||||||
func UpdateLdap(ldap *Ldap) (bool, error) {
|
func UpdateLdap(ldap *Ldap) (bool, error) {
|
||||||
if l, err := GetLdap(ldap.Id); err != nil {
|
if l, err := GetLdap(ldap.Id); err != nil {
|
||||||
return false, nil
|
return false, nil
|
||||||
|
@@ -22,9 +22,7 @@ import (
|
|||||||
"github.com/beego/beego/context"
|
"github.com/beego/beego/context"
|
||||||
)
|
)
|
||||||
|
|
||||||
type MfaSessionData struct {
|
const MfaRecoveryCodesSession = "mfa_recovery_codes"
|
||||||
UserId string
|
|
||||||
}
|
|
||||||
|
|
||||||
type MfaProps struct {
|
type MfaProps struct {
|
||||||
Enabled bool `json:"enabled"`
|
Enabled bool `json:"enabled"`
|
||||||
@@ -37,10 +35,10 @@ type MfaProps struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type MfaInterface interface {
|
type MfaInterface interface {
|
||||||
SetupVerify(ctx *context.Context, passCode string) error
|
Initiate(ctx *context.Context, userId string) (*MfaProps, error)
|
||||||
Verify(passCode string) error
|
SetupVerify(ctx *context.Context, passcode string) error
|
||||||
Initiate(ctx *context.Context, name1 string, name2 string) (*MfaProps, error)
|
|
||||||
Enable(ctx *context.Context, user *User) error
|
Enable(ctx *context.Context, user *User) error
|
||||||
|
Verify(passcode string) error
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -58,11 +56,11 @@ const (
|
|||||||
func GetMfaUtil(mfaType string, config *MfaProps) MfaInterface {
|
func GetMfaUtil(mfaType string, config *MfaProps) MfaInterface {
|
||||||
switch mfaType {
|
switch mfaType {
|
||||||
case SmsType:
|
case SmsType:
|
||||||
return NewSmsTwoFactor(config)
|
return NewSmsMfaUtil(config)
|
||||||
case EmailType:
|
case EmailType:
|
||||||
return NewEmailTwoFactor(config)
|
return NewEmailMfaUtil(config)
|
||||||
case TotpType:
|
case TotpType:
|
||||||
return nil
|
return NewTotpMfaUtil(config)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
@@ -97,23 +95,9 @@ func MfaRecover(user *User, recoveryCode string) error {
|
|||||||
func GetAllMfaProps(user *User, masked bool) []*MfaProps {
|
func GetAllMfaProps(user *User, masked bool) []*MfaProps {
|
||||||
mfaProps := []*MfaProps{}
|
mfaProps := []*MfaProps{}
|
||||||
|
|
||||||
if user.MfaPhoneEnabled {
|
for _, mfaType := range []string{SmsType, EmailType, TotpType} {
|
||||||
mfaProps = append(mfaProps, user.GetMfaProps(SmsType, masked))
|
mfaProps = append(mfaProps, user.GetMfaProps(mfaType, masked))
|
||||||
} else {
|
|
||||||
mfaProps = append(mfaProps, &MfaProps{
|
|
||||||
Enabled: false,
|
|
||||||
MfaType: SmsType,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
if user.MfaEmailEnabled {
|
|
||||||
mfaProps = append(mfaProps, user.GetMfaProps(EmailType, masked))
|
|
||||||
} else {
|
|
||||||
mfaProps = append(mfaProps, &MfaProps{
|
|
||||||
Enabled: false,
|
|
||||||
MfaType: EmailType,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
return mfaProps
|
return mfaProps
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -121,6 +105,13 @@ func (user *User) GetMfaProps(mfaType string, masked bool) *MfaProps {
|
|||||||
mfaProps := &MfaProps{}
|
mfaProps := &MfaProps{}
|
||||||
|
|
||||||
if mfaType == SmsType {
|
if mfaType == SmsType {
|
||||||
|
if !user.MfaPhoneEnabled {
|
||||||
|
return &MfaProps{
|
||||||
|
Enabled: false,
|
||||||
|
MfaType: mfaType,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
mfaProps = &MfaProps{
|
mfaProps = &MfaProps{
|
||||||
Enabled: user.MfaPhoneEnabled,
|
Enabled: user.MfaPhoneEnabled,
|
||||||
MfaType: mfaType,
|
MfaType: mfaType,
|
||||||
@@ -132,6 +123,13 @@ func (user *User) GetMfaProps(mfaType string, masked bool) *MfaProps {
|
|||||||
mfaProps.Secret = user.Phone
|
mfaProps.Secret = user.Phone
|
||||||
}
|
}
|
||||||
} else if mfaType == EmailType {
|
} else if mfaType == EmailType {
|
||||||
|
if !user.MfaEmailEnabled {
|
||||||
|
return &MfaProps{
|
||||||
|
Enabled: false,
|
||||||
|
MfaType: mfaType,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
mfaProps = &MfaProps{
|
mfaProps = &MfaProps{
|
||||||
Enabled: user.MfaEmailEnabled,
|
Enabled: user.MfaEmailEnabled,
|
||||||
MfaType: mfaType,
|
MfaType: mfaType,
|
||||||
@@ -142,9 +140,22 @@ func (user *User) GetMfaProps(mfaType string, masked bool) *MfaProps {
|
|||||||
mfaProps.Secret = user.Email
|
mfaProps.Secret = user.Email
|
||||||
}
|
}
|
||||||
} else if mfaType == TotpType {
|
} else if mfaType == TotpType {
|
||||||
|
if user.TotpSecret == "" {
|
||||||
|
return &MfaProps{
|
||||||
|
Enabled: false,
|
||||||
|
MfaType: mfaType,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
mfaProps = &MfaProps{
|
mfaProps = &MfaProps{
|
||||||
|
Enabled: true,
|
||||||
MfaType: mfaType,
|
MfaType: mfaType,
|
||||||
}
|
}
|
||||||
|
if masked {
|
||||||
|
mfaProps.Secret = ""
|
||||||
|
} else {
|
||||||
|
mfaProps.Secret = user.TotpSecret
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if user.PreferredMfaType == mfaType {
|
if user.PreferredMfaType == mfaType {
|
||||||
@@ -158,8 +169,9 @@ func DisabledMultiFactorAuth(user *User) error {
|
|||||||
user.RecoveryCodes = []string{}
|
user.RecoveryCodes = []string{}
|
||||||
user.MfaPhoneEnabled = false
|
user.MfaPhoneEnabled = false
|
||||||
user.MfaEmailEnabled = false
|
user.MfaEmailEnabled = false
|
||||||
|
user.TotpSecret = ""
|
||||||
|
|
||||||
_, err := UpdateUser(user.GetId(), user, []string{"preferred_mfa_type", "recovery_codes", "mfa_phone_enabled", "mfa_email_enabled"}, user.IsAdminUser())
|
_, err := updateUser(user.GetId(), user, []string{"preferred_mfa_type", "recovery_codes", "mfa_phone_enabled", "mfa_email_enabled", "totp_secret"})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@@ -18,26 +18,24 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/casdoor/casdoor/util"
|
|
||||||
|
|
||||||
"github.com/beego/beego/context"
|
"github.com/beego/beego/context"
|
||||||
|
"github.com/casdoor/casdoor/util"
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
MfaSmsCountryCodeSession = "mfa_country_code"
|
MfaCountryCodeSession = "mfa_country_code"
|
||||||
MfaSmsDestSession = "mfa_dest"
|
MfaDestSession = "mfa_dest"
|
||||||
MfaSmsRecoveryCodesSession = "mfa_recovery_codes"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type SmsMfa struct {
|
type SmsMfa struct {
|
||||||
Config *MfaProps
|
Config *MfaProps
|
||||||
}
|
}
|
||||||
|
|
||||||
func (mfa *SmsMfa) Initiate(ctx *context.Context, name string, secret string) (*MfaProps, error) {
|
func (mfa *SmsMfa) Initiate(ctx *context.Context, userId string) (*MfaProps, error) {
|
||||||
recoveryCode := uuid.NewString()
|
recoveryCode := uuid.NewString()
|
||||||
|
|
||||||
err := ctx.Input.CruSession.Set(MfaSmsRecoveryCodesSession, []string{recoveryCode})
|
err := ctx.Input.CruSession.Set(MfaRecoveryCodesSession, []string{recoveryCode})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -50,9 +48,19 @@ func (mfa *SmsMfa) Initiate(ctx *context.Context, name string, secret string) (*
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (mfa *SmsMfa) SetupVerify(ctx *context.Context, passCode string) error {
|
func (mfa *SmsMfa) SetupVerify(ctx *context.Context, passCode string) error {
|
||||||
dest := ctx.Input.CruSession.Get(MfaSmsDestSession).(string)
|
destSession := ctx.Input.CruSession.Get(MfaDestSession)
|
||||||
countryCode := ctx.Input.CruSession.Get(MfaSmsCountryCodeSession).(string)
|
if destSession == nil {
|
||||||
|
return errors.New("dest session is missing")
|
||||||
|
}
|
||||||
|
dest := destSession.(string)
|
||||||
|
|
||||||
if !util.IsEmailValid(dest) {
|
if !util.IsEmailValid(dest) {
|
||||||
|
countryCodeSession := ctx.Input.CruSession.Get(MfaCountryCodeSession)
|
||||||
|
if countryCodeSession == nil {
|
||||||
|
return errors.New("country code is missing")
|
||||||
|
}
|
||||||
|
countryCode := countryCodeSession.(string)
|
||||||
|
|
||||||
dest, _ = util.GetE164Number(dest, countryCode)
|
dest, _ = util.GetE164Number(dest, countryCode)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -63,9 +71,9 @@ func (mfa *SmsMfa) SetupVerify(ctx *context.Context, passCode string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (mfa *SmsMfa) Enable(ctx *context.Context, user *User) error {
|
func (mfa *SmsMfa) Enable(ctx *context.Context, user *User) error {
|
||||||
recoveryCodes := ctx.Input.CruSession.Get(MfaSmsRecoveryCodesSession).([]string)
|
recoveryCodes := ctx.Input.CruSession.Get(MfaRecoveryCodesSession).([]string)
|
||||||
if len(recoveryCodes) == 0 {
|
if len(recoveryCodes) == 0 {
|
||||||
return fmt.Errorf("recovery codes is empty")
|
return fmt.Errorf("recovery codes is missing")
|
||||||
}
|
}
|
||||||
|
|
||||||
columns := []string{"recovery_codes", "preferred_mfa_type"}
|
columns := []string{"recovery_codes", "preferred_mfa_type"}
|
||||||
@@ -80,8 +88,8 @@ func (mfa *SmsMfa) Enable(ctx *context.Context, user *User) error {
|
|||||||
columns = append(columns, "mfa_phone_enabled")
|
columns = append(columns, "mfa_phone_enabled")
|
||||||
|
|
||||||
if user.Phone == "" {
|
if user.Phone == "" {
|
||||||
user.Phone = ctx.Input.CruSession.Get(MfaSmsDestSession).(string)
|
user.Phone = ctx.Input.CruSession.Get(MfaDestSession).(string)
|
||||||
user.CountryCode = ctx.Input.CruSession.Get(MfaSmsCountryCodeSession).(string)
|
user.CountryCode = ctx.Input.CruSession.Get(MfaCountryCodeSession).(string)
|
||||||
columns = append(columns, "phone", "country_code")
|
columns = append(columns, "phone", "country_code")
|
||||||
}
|
}
|
||||||
} else if mfa.Config.MfaType == EmailType {
|
} else if mfa.Config.MfaType == EmailType {
|
||||||
@@ -89,7 +97,7 @@ func (mfa *SmsMfa) Enable(ctx *context.Context, user *User) error {
|
|||||||
columns = append(columns, "mfa_email_enabled")
|
columns = append(columns, "mfa_email_enabled")
|
||||||
|
|
||||||
if user.Email == "" {
|
if user.Email == "" {
|
||||||
user.Email = ctx.Input.CruSession.Get(MfaSmsDestSession).(string)
|
user.Email = ctx.Input.CruSession.Get(MfaDestSession).(string)
|
||||||
columns = append(columns, "email")
|
columns = append(columns, "email")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -98,6 +106,11 @@ func (mfa *SmsMfa) Enable(ctx *context.Context, user *User) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ctx.Input.CruSession.Delete(MfaRecoveryCodesSession)
|
||||||
|
ctx.Input.CruSession.Delete(MfaDestSession)
|
||||||
|
ctx.Input.CruSession.Delete(MfaCountryCodeSession)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -111,7 +124,7 @@ func (mfa *SmsMfa) Verify(passCode string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewSmsTwoFactor(config *MfaProps) *SmsMfa {
|
func NewSmsMfaUtil(config *MfaProps) *SmsMfa {
|
||||||
if config == nil {
|
if config == nil {
|
||||||
config = &MfaProps{
|
config = &MfaProps{
|
||||||
MfaType: SmsType,
|
MfaType: SmsType,
|
||||||
@@ -122,7 +135,7 @@ func NewSmsTwoFactor(config *MfaProps) *SmsMfa {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewEmailTwoFactor(config *MfaProps) *SmsMfa {
|
func NewEmailMfaUtil(config *MfaProps) *SmsMfa {
|
||||||
if config == nil {
|
if config == nil {
|
||||||
config = &MfaProps{
|
config = &MfaProps{
|
||||||
MfaType: EmailType,
|
MfaType: EmailType,
|
||||||
|
140
object/mfa_totp.go
Normal file
140
object/mfa_totp.go
Normal file
@@ -0,0 +1,140 @@
|
|||||||
|
// Copyright 2023 The Casdoor Authors. All Rights Reserved.
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
package object
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/beego/beego"
|
||||||
|
"github.com/beego/beego/context"
|
||||||
|
"github.com/google/uuid"
|
||||||
|
"github.com/pquerna/otp"
|
||||||
|
"github.com/pquerna/otp/totp"
|
||||||
|
)
|
||||||
|
|
||||||
|
const MfaTotpSecretSession = "mfa_totp_secret"
|
||||||
|
|
||||||
|
type TotpMfa struct {
|
||||||
|
Config *MfaProps
|
||||||
|
period uint
|
||||||
|
secretSize uint
|
||||||
|
digits otp.Digits
|
||||||
|
}
|
||||||
|
|
||||||
|
func (mfa *TotpMfa) Initiate(ctx *context.Context, userId string) (*MfaProps, error) {
|
||||||
|
issuer := beego.AppConfig.String("appname")
|
||||||
|
if issuer == "" {
|
||||||
|
issuer = "casdoor"
|
||||||
|
}
|
||||||
|
|
||||||
|
key, err := totp.Generate(totp.GenerateOpts{
|
||||||
|
Issuer: issuer,
|
||||||
|
AccountName: userId,
|
||||||
|
Period: mfa.period,
|
||||||
|
SecretSize: mfa.secretSize,
|
||||||
|
Digits: mfa.digits,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
err = ctx.Input.CruSession.Set(MfaTotpSecretSession, key.Secret())
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
recoveryCode := uuid.NewString()
|
||||||
|
err = ctx.Input.CruSession.Set(MfaRecoveryCodesSession, []string{recoveryCode})
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
mfaProps := MfaProps{
|
||||||
|
MfaType: mfa.Config.MfaType,
|
||||||
|
RecoveryCodes: []string{recoveryCode},
|
||||||
|
Secret: key.Secret(),
|
||||||
|
URL: key.URL(),
|
||||||
|
}
|
||||||
|
return &mfaProps, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (mfa *TotpMfa) SetupVerify(ctx *context.Context, passcode string) error {
|
||||||
|
secret := ctx.Input.CruSession.Get(MfaTotpSecretSession)
|
||||||
|
if secret == nil {
|
||||||
|
return errors.New("totp secret is missing")
|
||||||
|
}
|
||||||
|
result := totp.Validate(passcode, secret.(string))
|
||||||
|
|
||||||
|
if result {
|
||||||
|
return nil
|
||||||
|
} else {
|
||||||
|
return errors.New("totp passcode error")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (mfa *TotpMfa) Enable(ctx *context.Context, user *User) error {
|
||||||
|
recoveryCodes := ctx.Input.CruSession.Get(MfaRecoveryCodesSession).([]string)
|
||||||
|
if len(recoveryCodes) == 0 {
|
||||||
|
return fmt.Errorf("recovery codes is missing")
|
||||||
|
}
|
||||||
|
secret := ctx.Input.CruSession.Get(MfaTotpSecretSession).(string)
|
||||||
|
if secret == "" {
|
||||||
|
return fmt.Errorf("totp secret is missing")
|
||||||
|
}
|
||||||
|
|
||||||
|
columns := []string{"recovery_codes", "preferred_mfa_type", "totp_secret"}
|
||||||
|
|
||||||
|
user.RecoveryCodes = append(user.RecoveryCodes, recoveryCodes...)
|
||||||
|
user.TotpSecret = secret
|
||||||
|
if user.PreferredMfaType == "" {
|
||||||
|
user.PreferredMfaType = mfa.Config.MfaType
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err := updateUser(user.GetId(), user, columns)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx.Input.CruSession.Delete(MfaRecoveryCodesSession)
|
||||||
|
ctx.Input.CruSession.Delete(MfaTotpSecretSession)
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (mfa *TotpMfa) Verify(passcode string) error {
|
||||||
|
result := totp.Validate(passcode, mfa.Config.Secret)
|
||||||
|
|
||||||
|
if result {
|
||||||
|
return nil
|
||||||
|
} else {
|
||||||
|
return errors.New("totp passcode error")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewTotpMfaUtil(config *MfaProps) *TotpMfa {
|
||||||
|
if config == nil {
|
||||||
|
config = &MfaProps{
|
||||||
|
MfaType: TotpType,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return &TotpMfa{
|
||||||
|
Config: config,
|
||||||
|
period: 30,
|
||||||
|
secretSize: 20,
|
||||||
|
digits: otp.DigitsSix,
|
||||||
|
}
|
||||||
|
}
|
@@ -161,5 +161,8 @@ func modelChangeTrigger(oldName string, newName string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func HasRoleDefinition(m model.Model) bool {
|
func HasRoleDefinition(m model.Model) bool {
|
||||||
|
if m == nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
return m["g"] != nil
|
return m["g"] != nil
|
||||||
}
|
}
|
||||||
|
@@ -65,10 +65,13 @@ func getOriginFromHost(host string) (string, string) {
|
|||||||
return origin, origin
|
return origin, origin
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// "door.casdoor.com"
|
||||||
protocol := "https://"
|
protocol := "https://"
|
||||||
if strings.HasPrefix(host, "localhost") {
|
if !strings.Contains(host, ".") {
|
||||||
|
// "localhost:8000" or "computer-name:80"
|
||||||
protocol = "http://"
|
protocol = "http://"
|
||||||
} else if isIpAddress(host) {
|
} else if isIpAddress(host) {
|
||||||
|
// "192.168.0.10"
|
||||||
protocol = "http://"
|
protocol = "http://"
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -120,6 +123,10 @@ func GetJsonWebKeySet() (jose.JSONWebKeySet, error) {
|
|||||||
// link here: https://self-issued.info/docs/draft-ietf-jose-json-web-key.html
|
// link here: https://self-issued.info/docs/draft-ietf-jose-json-web-key.html
|
||||||
// or https://datatracker.ietf.org/doc/html/draft-ietf-jose-json-web-key
|
// or https://datatracker.ietf.org/doc/html/draft-ietf-jose-json-web-key
|
||||||
for _, cert := range certs {
|
for _, cert := range certs {
|
||||||
|
if cert.Type != "x509" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
certPemBlock := []byte(cert.Certificate)
|
certPemBlock := []byte(cert.Certificate)
|
||||||
certDerBlock, _ := pem.Decode(certPemBlock)
|
certDerBlock, _ := pem.Decode(certPemBlock)
|
||||||
x509Cert, _ := x509.ParseCertificate(certDerBlock.Bytes)
|
x509Cert, _ := x509.ParseCertificate(certDerBlock.Bytes)
|
||||||
|
@@ -69,7 +69,7 @@ type Organization struct {
|
|||||||
IsProfilePublic bool `json:"isProfilePublic"`
|
IsProfilePublic bool `json:"isProfilePublic"`
|
||||||
|
|
||||||
MfaItems []*MfaItem `xorm:"varchar(300)" json:"mfaItems"`
|
MfaItems []*MfaItem `xorm:"varchar(300)" json:"mfaItems"`
|
||||||
AccountItems []*AccountItem `xorm:"varchar(3000)" json:"accountItems"`
|
AccountItems []*AccountItem `xorm:"varchar(5000)" json:"accountItems"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetOrganizationCount(owner, field, value string) (int64, error) {
|
func GetOrganizationCount(owner, field, value string) (int64, error) {
|
||||||
@@ -104,10 +104,15 @@ func GetOrganizationsByFields(owner string, fields ...string) ([]*Organization,
|
|||||||
return organizations, nil
|
return organizations, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetPaginationOrganizations(owner string, offset, limit int, field, value, sortField, sortOrder string) ([]*Organization, error) {
|
func GetPaginationOrganizations(owner string, name string, offset, limit int, field, value, sortField, sortOrder string) ([]*Organization, error) {
|
||||||
organizations := []*Organization{}
|
organizations := []*Organization{}
|
||||||
session := GetSession(owner, offset, limit, field, value, sortField, sortOrder)
|
session := GetSession(owner, offset, limit, field, value, sortField, sortOrder)
|
||||||
err := session.Find(&organizations)
|
var err error
|
||||||
|
if name != "" {
|
||||||
|
err = session.Find(&organizations, &Organization{Name: name})
|
||||||
|
} else {
|
||||||
|
err = session.Find(&organizations)
|
||||||
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -231,6 +236,10 @@ func DeleteOrganization(organization *Organization) (bool, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func GetOrganizationByUser(user *User) (*Organization, error) {
|
func GetOrganizationByUser(user *User) (*Organization, error) {
|
||||||
|
if user == nil {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
return getOrganization("admin", user.Owner)
|
return getOrganization("admin", user.Owner)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -467,10 +476,21 @@ func organizationChangeTrigger(oldName string, newName string) error {
|
|||||||
return session.Commit()
|
return session.Commit()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (org *Organization) HasRequiredMfa() bool {
|
func IsNeedPromptMfa(org *Organization, user *User) bool {
|
||||||
|
if org == nil || user == nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
for _, item := range org.MfaItems {
|
for _, item := range org.MfaItems {
|
||||||
if item.Rule == "Required" {
|
if item.Rule == "Required" {
|
||||||
return true
|
if item.Name == EmailType && !user.MfaEmailEnabled {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
if item.Name == SmsType && !user.MfaPhoneEnabled {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
if item.Name == TotpType && user.TotpSecret == "" {
|
||||||
|
return true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
|
@@ -26,42 +26,7 @@ import (
|
|||||||
xormadapter "github.com/casdoor/xorm-adapter/v3"
|
xormadapter "github.com/casdoor/xorm-adapter/v3"
|
||||||
)
|
)
|
||||||
|
|
||||||
func getEnforcer(permission *Permission, permissionIDs ...string) *casbin.Enforcer {
|
func getEnforcer(p *Permission, permissionIDs ...string) *casbin.Enforcer {
|
||||||
tableName := "permission_rule"
|
|
||||||
if len(permission.Adapter) != 0 {
|
|
||||||
adapterObj, err := getCasbinAdapter(permission.Owner, permission.Adapter)
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if adapterObj != nil && adapterObj.Table != "" {
|
|
||||||
tableName = adapterObj.Table
|
|
||||||
}
|
|
||||||
}
|
|
||||||
tableNamePrefix := conf.GetConfigString("tableNamePrefix")
|
|
||||||
driverName := conf.GetConfigString("driverName")
|
|
||||||
dataSourceName := conf.GetConfigRealDataSourceName(driverName)
|
|
||||||
adapter, err := xormadapter.NewAdapterWithTableName(driverName, dataSourceName, tableName, tableNamePrefix, true)
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
permissionModel, err := getModel(permission.Owner, permission.Model)
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
m := model.Model{}
|
|
||||||
if permissionModel != nil {
|
|
||||||
m, err = GetBuiltInModel(permissionModel.ModelText)
|
|
||||||
} else {
|
|
||||||
m, err = GetBuiltInModel("")
|
|
||||||
}
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Init an enforcer instance without specifying a model or adapter.
|
// Init an enforcer instance without specifying a model or adapter.
|
||||||
// If you specify an adapter, it will load all policies, which is a
|
// If you specify an adapter, it will load all policies, which is a
|
||||||
// heavy process that can slow down the application.
|
// heavy process that can slow down the application.
|
||||||
@@ -70,14 +35,17 @@ func getEnforcer(permission *Permission, permissionIDs ...string) *casbin.Enforc
|
|||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = enforcer.InitWithModelAndAdapter(m, nil)
|
err = p.setEnforcerModel(enforcer)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
enforcer.SetAdapter(adapter)
|
err = p.setEnforcerAdapter(enforcer)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
policyFilterV5 := []string{permission.GetId()}
|
policyFilterV5 := []string{p.GetId()}
|
||||||
if len(permissionIDs) != 0 {
|
if len(permissionIDs) != 0 {
|
||||||
policyFilterV5 = permissionIDs
|
policyFilterV5 = permissionIDs
|
||||||
}
|
}
|
||||||
@@ -86,7 +54,7 @@ func getEnforcer(permission *Permission, permissionIDs ...string) *casbin.Enforc
|
|||||||
V5: policyFilterV5,
|
V5: policyFilterV5,
|
||||||
}
|
}
|
||||||
|
|
||||||
if !HasRoleDefinition(m) {
|
if !HasRoleDefinition(enforcer.GetModel()) {
|
||||||
policyFilter.Ptype = []string{"p"}
|
policyFilter.Ptype = []string{"p"}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -98,35 +66,70 @@ func getEnforcer(permission *Permission, permissionIDs ...string) *casbin.Enforc
|
|||||||
return enforcer
|
return enforcer
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (p *Permission) setEnforcerAdapter(enforcer *casbin.Enforcer) error {
|
||||||
|
tableName := "permission_rule"
|
||||||
|
if len(p.Adapter) != 0 {
|
||||||
|
adapterObj, err := getCasbinAdapter(p.Owner, p.Adapter)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if adapterObj != nil && adapterObj.Table != "" {
|
||||||
|
tableName = adapterObj.Table
|
||||||
|
}
|
||||||
|
}
|
||||||
|
tableNamePrefix := conf.GetConfigString("tableNamePrefix")
|
||||||
|
driverName := conf.GetConfigString("driverName")
|
||||||
|
dataSourceName := conf.GetConfigRealDataSourceName(driverName)
|
||||||
|
casbinAdapter, err := xormadapter.NewAdapterWithTableName(driverName, dataSourceName, tableName, tableNamePrefix, true)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
enforcer.SetAdapter(casbinAdapter)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Permission) setEnforcerModel(enforcer *casbin.Enforcer) error {
|
||||||
|
permissionModel, err := getModel(p.Owner, p.Model)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: return error if permissionModel is nil.
|
||||||
|
m := model.Model{}
|
||||||
|
if permissionModel != nil {
|
||||||
|
m, err = GetBuiltInModel(permissionModel.ModelText)
|
||||||
|
} else {
|
||||||
|
m, err = GetBuiltInModel("")
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
err = enforcer.InitWithModelAndAdapter(m, nil)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func getPolicies(permission *Permission) [][]string {
|
func getPolicies(permission *Permission) [][]string {
|
||||||
var policies [][]string
|
var policies [][]string
|
||||||
|
|
||||||
permissionId := permission.GetId()
|
permissionId := permission.GetId()
|
||||||
domainExist := len(permission.Domains) > 0
|
domainExist := len(permission.Domains) > 0
|
||||||
|
|
||||||
for _, user := range permission.Users {
|
usersAndRoles := append(permission.Users, permission.Roles...)
|
||||||
|
for _, userOrRole := range usersAndRoles {
|
||||||
for _, resource := range permission.Resources {
|
for _, resource := range permission.Resources {
|
||||||
for _, action := range permission.Actions {
|
for _, action := range permission.Actions {
|
||||||
if domainExist {
|
if domainExist {
|
||||||
for _, domain := range permission.Domains {
|
for _, domain := range permission.Domains {
|
||||||
policies = append(policies, []string{user, domain, resource, strings.ToLower(action), "", permissionId})
|
policies = append(policies, []string{userOrRole, domain, resource, strings.ToLower(action), strings.ToLower(permission.Effect), permissionId})
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
policies = append(policies, []string{user, resource, strings.ToLower(action), "", "", permissionId})
|
policies = append(policies, []string{userOrRole, resource, strings.ToLower(action), strings.ToLower(permission.Effect), "", permissionId})
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, role := range permission.Roles {
|
|
||||||
for _, resource := range permission.Resources {
|
|
||||||
for _, action := range permission.Actions {
|
|
||||||
if domainExist {
|
|
||||||
for _, domain := range permission.Domains {
|
|
||||||
policies = append(policies, []string{role, domain, resource, strings.ToLower(action), "", permissionId})
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
policies = append(policies, []string{role, resource, strings.ToLower(action), "", "", permissionId})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -16,8 +16,11 @@ package object
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/beego/beego/context"
|
||||||
"github.com/casdoor/casdoor/i18n"
|
"github.com/casdoor/casdoor/i18n"
|
||||||
|
"github.com/casdoor/casdoor/idp"
|
||||||
"github.com/casdoor/casdoor/pp"
|
"github.com/casdoor/casdoor/pp"
|
||||||
"github.com/casdoor/casdoor/util"
|
"github.com/casdoor/casdoor/util"
|
||||||
"github.com/xorm-io/core"
|
"github.com/xorm-io/core"
|
||||||
@@ -28,21 +31,22 @@ type Provider struct {
|
|||||||
Name string `xorm:"varchar(100) notnull pk unique" json:"name"`
|
Name string `xorm:"varchar(100) notnull pk unique" json:"name"`
|
||||||
CreatedTime string `xorm:"varchar(100)" json:"createdTime"`
|
CreatedTime string `xorm:"varchar(100)" json:"createdTime"`
|
||||||
|
|
||||||
DisplayName string `xorm:"varchar(100)" json:"displayName"`
|
DisplayName string `xorm:"varchar(100)" json:"displayName"`
|
||||||
Category string `xorm:"varchar(100)" json:"category"`
|
Category string `xorm:"varchar(100)" json:"category"`
|
||||||
Type string `xorm:"varchar(100)" json:"type"`
|
Type string `xorm:"varchar(100)" json:"type"`
|
||||||
SubType string `xorm:"varchar(100)" json:"subType"`
|
SubType string `xorm:"varchar(100)" json:"subType"`
|
||||||
Method string `xorm:"varchar(100)" json:"method"`
|
Method string `xorm:"varchar(100)" json:"method"`
|
||||||
ClientId string `xorm:"varchar(100)" json:"clientId"`
|
ClientId string `xorm:"varchar(100)" json:"clientId"`
|
||||||
ClientSecret string `xorm:"varchar(2000)" json:"clientSecret"`
|
ClientSecret string `xorm:"varchar(2000)" json:"clientSecret"`
|
||||||
ClientId2 string `xorm:"varchar(100)" json:"clientId2"`
|
ClientId2 string `xorm:"varchar(100)" json:"clientId2"`
|
||||||
ClientSecret2 string `xorm:"varchar(100)" json:"clientSecret2"`
|
ClientSecret2 string `xorm:"varchar(100)" json:"clientSecret2"`
|
||||||
Cert string `xorm:"varchar(100)" json:"cert"`
|
Cert string `xorm:"varchar(100)" json:"cert"`
|
||||||
CustomAuthUrl string `xorm:"varchar(200)" json:"customAuthUrl"`
|
CustomAuthUrl string `xorm:"varchar(200)" json:"customAuthUrl"`
|
||||||
CustomScope string `xorm:"varchar(200)" json:"customScope"`
|
CustomTokenUrl string `xorm:"varchar(200)" json:"customTokenUrl"`
|
||||||
CustomTokenUrl string `xorm:"varchar(200)" json:"customTokenUrl"`
|
CustomUserInfoUrl string `xorm:"varchar(200)" json:"customUserInfoUrl"`
|
||||||
CustomUserInfoUrl string `xorm:"varchar(200)" json:"customUserInfoUrl"`
|
CustomLogo string `xorm:"varchar(200)" json:"customLogo"`
|
||||||
CustomLogo string `xorm:"varchar(200)" json:"customLogo"`
|
Scopes string `xorm:"varchar(100)" json:"scopes"`
|
||||||
|
UserMapping map[string]string `xorm:"varchar(500)" json:"userMapping"`
|
||||||
|
|
||||||
Host string `xorm:"varchar(100)" json:"host"`
|
Host string `xorm:"varchar(100)" json:"host"`
|
||||||
Port int `json:"port"`
|
Port int `json:"port"`
|
||||||
@@ -225,7 +229,7 @@ func UpdateProvider(id string, provider *Provider) (bool, error) {
|
|||||||
session = session.Omit("client_secret2")
|
session = session.Omit("client_secret2")
|
||||||
}
|
}
|
||||||
|
|
||||||
if provider.Type != "Keycloak" {
|
if provider.Type == "Tencent Cloud COS" {
|
||||||
provider.Endpoint = util.GetEndPoint(provider.Endpoint)
|
provider.Endpoint = util.GetEndPoint(provider.Endpoint)
|
||||||
provider.IntranetEndpoint = util.GetEndPoint(provider.IntranetEndpoint)
|
provider.IntranetEndpoint = util.GetEndPoint(provider.IntranetEndpoint)
|
||||||
}
|
}
|
||||||
@@ -239,7 +243,7 @@ func UpdateProvider(id string, provider *Provider) (bool, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func AddProvider(provider *Provider) (bool, error) {
|
func AddProvider(provider *Provider) (bool, error) {
|
||||||
if provider.Type != "Keycloak" {
|
if provider.Type == "Tencent Cloud COS" {
|
||||||
provider.Endpoint = util.GetEndPoint(provider.Endpoint)
|
provider.Endpoint = util.GetEndPoint(provider.Endpoint)
|
||||||
provider.IntranetEndpoint = util.GetEndPoint(provider.IntranetEndpoint)
|
provider.IntranetEndpoint = util.GetEndPoint(provider.IntranetEndpoint)
|
||||||
}
|
}
|
||||||
@@ -365,3 +369,27 @@ func providerChangeTrigger(oldName string, newName string) error {
|
|||||||
|
|
||||||
return session.Commit()
|
return session.Commit()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func FromProviderToIdpInfo(ctx *context.Context, provider *Provider) *idp.ProviderInfo {
|
||||||
|
providerInfo := &idp.ProviderInfo{
|
||||||
|
Type: provider.Type,
|
||||||
|
SubType: provider.SubType,
|
||||||
|
ClientId: provider.ClientId,
|
||||||
|
ClientSecret: provider.ClientSecret,
|
||||||
|
AppId: provider.AppId,
|
||||||
|
HostUrl: provider.Host,
|
||||||
|
TokenURL: provider.CustomTokenUrl,
|
||||||
|
AuthURL: provider.CustomAuthUrl,
|
||||||
|
UserInfoURL: provider.CustomUserInfoUrl,
|
||||||
|
UserMapping: provider.UserMapping,
|
||||||
|
}
|
||||||
|
|
||||||
|
if provider.Type == "WeChat" {
|
||||||
|
if ctx != nil && strings.Contains(ctx.Request.UserAgent(), "MicroMessenger") {
|
||||||
|
providerInfo.ClientId = provider.ClientId2
|
||||||
|
providerInfo.ClientSecret = provider.ClientSecret2
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return providerInfo
|
||||||
|
}
|
||||||
|
@@ -49,7 +49,7 @@ func (pi *ProviderItem) IsProviderVisible() bool {
|
|||||||
if pi.Provider == nil {
|
if pi.Provider == nil {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
return pi.Provider.Category == "OAuth" || pi.Provider.Category == "SAML"
|
return pi.Provider.Category == "OAuth" || pi.Provider.Category == "SAML" || pi.Provider.Category == "Web3"
|
||||||
}
|
}
|
||||||
|
|
||||||
func (pi *ProviderItem) isProviderPrompted() bool {
|
func (pi *ProviderItem) isProviderPrompted() bool {
|
||||||
|
@@ -161,7 +161,8 @@ func SendWebhooks(record *Record) error {
|
|||||||
|
|
||||||
if matched {
|
if matched {
|
||||||
if webhook.IsUserExtended {
|
if webhook.IsUserExtended {
|
||||||
user, err := GetMaskedUser(getUser(record.Organization, record.User))
|
user, err := getUser(record.Organization, record.User)
|
||||||
|
user, err = GetMaskedUser(user, false, err)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@@ -16,6 +16,7 @@ package object
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/casdoor/casdoor/util"
|
"github.com/casdoor/casdoor/util"
|
||||||
"github.com/xorm-io/core"
|
"github.com/xorm-io/core"
|
||||||
@@ -76,6 +77,10 @@ func GetPaginationResources(owner, user string, offset, limit int, field, value,
|
|||||||
}
|
}
|
||||||
|
|
||||||
func getResource(owner string, name string) (*Resource, error) {
|
func getResource(owner string, name string) (*Resource, error) {
|
||||||
|
if !strings.HasPrefix(name, "/") {
|
||||||
|
name = "/" + name
|
||||||
|
}
|
||||||
|
|
||||||
resource := Resource{Owner: owner, Name: name}
|
resource := Resource{Owner: owner, Name: name}
|
||||||
existed, err := adapter.Engine.Get(&resource)
|
existed, err := adapter.Engine.Get(&resource)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@@ -42,7 +42,11 @@ func SendSms(provider *Provider, content string, phoneNumbers ...string) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if provider.Type == sender.Aliyun {
|
if provider.Type == sender.Twilio {
|
||||||
|
if provider.AppId != "" {
|
||||||
|
phoneNumbers = append([]string{provider.AppId}, phoneNumbers...)
|
||||||
|
}
|
||||||
|
} else if provider.Type == sender.Aliyun {
|
||||||
for i, number := range phoneNumbers {
|
for i, number := range phoneNumbers {
|
||||||
phoneNumbers[i] = strings.TrimPrefix(number, "+86")
|
phoneNumbers[i] = strings.TrimPrefix(number, "+86")
|
||||||
}
|
}
|
||||||
|
@@ -25,6 +25,7 @@ import (
|
|||||||
"github.com/casdoor/casdoor/i18n"
|
"github.com/casdoor/casdoor/i18n"
|
||||||
"github.com/casdoor/casdoor/storage"
|
"github.com/casdoor/casdoor/storage"
|
||||||
"github.com/casdoor/casdoor/util"
|
"github.com/casdoor/casdoor/util"
|
||||||
|
"github.com/casdoor/oss"
|
||||||
)
|
)
|
||||||
|
|
||||||
var isCloudIntranet bool
|
var isCloudIntranet bool
|
||||||
@@ -102,11 +103,11 @@ func GetUploadFileUrl(provider *Provider, fullFilePath string, hasTimestamp bool
|
|||||||
return fileUrl, objectKey
|
return fileUrl, objectKey
|
||||||
}
|
}
|
||||||
|
|
||||||
func uploadFile(provider *Provider, fullFilePath string, fileBuffer *bytes.Buffer, lang string) (string, string, error) {
|
func getStorageProvider(provider *Provider, lang string) (oss.StorageInterface, error) {
|
||||||
endpoint := getProviderEndpoint(provider)
|
endpoint := getProviderEndpoint(provider)
|
||||||
storageProvider := storage.GetStorageProvider(provider.Type, provider.ClientId, provider.ClientSecret, provider.RegionId, provider.Bucket, endpoint)
|
storageProvider := storage.GetStorageProvider(provider.Type, provider.ClientId, provider.ClientSecret, provider.RegionId, provider.Bucket, endpoint)
|
||||||
if storageProvider == nil {
|
if storageProvider == nil {
|
||||||
return "", "", fmt.Errorf(i18n.Translate(lang, "storage:The provider type: %s is not supported"), provider.Type)
|
return nil, fmt.Errorf(i18n.Translate(lang, "storage:The provider type: %s is not supported"), provider.Type)
|
||||||
}
|
}
|
||||||
|
|
||||||
if provider.Domain == "" {
|
if provider.Domain == "" {
|
||||||
@@ -114,9 +115,18 @@ func uploadFile(provider *Provider, fullFilePath string, fileBuffer *bytes.Buffe
|
|||||||
UpdateProvider(provider.GetId(), provider)
|
UpdateProvider(provider.GetId(), provider)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return storageProvider, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func uploadFile(provider *Provider, fullFilePath string, fileBuffer *bytes.Buffer, lang string) (string, string, error) {
|
||||||
|
storageProvider, err := getStorageProvider(provider, lang)
|
||||||
|
if err != nil {
|
||||||
|
return "", "", err
|
||||||
|
}
|
||||||
|
|
||||||
fileUrl, objectKey := GetUploadFileUrl(provider, fullFilePath, true)
|
fileUrl, objectKey := GetUploadFileUrl(provider, fullFilePath, true)
|
||||||
|
|
||||||
_, err := storageProvider.Put(objectKey, fileBuffer)
|
_, err = storageProvider.Put(objectKey, fileBuffer)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", "", err
|
return "", "", err
|
||||||
}
|
}
|
||||||
@@ -154,15 +164,9 @@ func DeleteFile(provider *Provider, objectKey string, lang string) error {
|
|||||||
return fmt.Errorf(i18n.Translate(lang, "storage:The objectKey: %s is not allowed"), objectKey)
|
return fmt.Errorf(i18n.Translate(lang, "storage:The objectKey: %s is not allowed"), objectKey)
|
||||||
}
|
}
|
||||||
|
|
||||||
endpoint := getProviderEndpoint(provider)
|
storageProvider, err := getStorageProvider(provider, lang)
|
||||||
storageProvider := storage.GetStorageProvider(provider.Type, provider.ClientId, provider.ClientSecret, provider.RegionId, provider.Bucket, endpoint)
|
if err != nil {
|
||||||
if storageProvider == nil {
|
return err
|
||||||
return fmt.Errorf(i18n.Translate(lang, "storage:The provider type: %s is not supported"), provider.Type)
|
|
||||||
}
|
|
||||||
|
|
||||||
if provider.Domain == "" {
|
|
||||||
provider.Domain = storageProvider.GetEndpoint()
|
|
||||||
UpdateProvider(provider.GetId(), provider)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return storageProvider.Delete(objectKey)
|
return storageProvider.Delete(objectKey)
|
||||||
|
@@ -50,6 +50,7 @@ type Syncer struct {
|
|||||||
AvatarBaseUrl string `xorm:"varchar(100)" json:"avatarBaseUrl"`
|
AvatarBaseUrl string `xorm:"varchar(100)" json:"avatarBaseUrl"`
|
||||||
ErrorText string `xorm:"mediumtext" json:"errorText"`
|
ErrorText string `xorm:"mediumtext" json:"errorText"`
|
||||||
SyncInterval int `json:"syncInterval"`
|
SyncInterval int `json:"syncInterval"`
|
||||||
|
IsReadOnly bool `json:"isReadOnly"`
|
||||||
IsEnabled bool `json:"isEnabled"`
|
IsEnabled bool `json:"isEnabled"`
|
||||||
|
|
||||||
Adapter *Adapter `xorm:"-" json:"-"`
|
Adapter *Adapter `xorm:"-" json:"-"`
|
||||||
|
@@ -63,9 +63,11 @@ func (syncer *Syncer) syncUsers() {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if user.PreHash == oHash {
|
if user.PreHash == oHash {
|
||||||
updatedOUser := syncer.createOriginalUserFromUser(user)
|
if !syncer.IsReadOnly {
|
||||||
syncer.updateUser(updatedOUser)
|
updatedOUser := syncer.createOriginalUserFromUser(user)
|
||||||
fmt.Printf("Update from user to oUser: %v\n", updatedOUser)
|
syncer.updateUser(updatedOUser)
|
||||||
|
fmt.Printf("Update from user to oUser: %v\n", updatedOUser)
|
||||||
|
}
|
||||||
|
|
||||||
// update preHash
|
// update preHash
|
||||||
user.PreHash = user.Hash
|
user.PreHash = user.Hash
|
||||||
@@ -91,15 +93,17 @@ func (syncer *Syncer) syncUsers() {
|
|||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, user := range users {
|
if !syncer.IsReadOnly {
|
||||||
id := user.Id
|
for _, user := range users {
|
||||||
if _, ok := oUserMap[id]; !ok {
|
id := user.Id
|
||||||
newOUser := syncer.createOriginalUserFromUser(user)
|
if _, ok := oUserMap[id]; !ok {
|
||||||
_, err = syncer.addUser(newOUser)
|
newOUser := syncer.createOriginalUserFromUser(user)
|
||||||
if err != nil {
|
_, err = syncer.addUser(newOUser)
|
||||||
panic(err)
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
fmt.Printf("New oUser: %v\n", newOUser)
|
||||||
}
|
}
|
||||||
fmt.Printf("New oUser: %v\n", newOUser)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -170,6 +170,7 @@ func (syncer *Syncer) getOriginalUsersFromMap(results []map[string]string) []*Or
|
|||||||
originalUser := &OriginalUser{
|
originalUser := &OriginalUser{
|
||||||
Address: []string{},
|
Address: []string{},
|
||||||
Properties: map[string]string{},
|
Properties: map[string]string{},
|
||||||
|
Groups: []string{},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, tableColumn := range syncer.TableColumns {
|
for _, tableColumn := range syncer.TableColumns {
|
||||||
|
@@ -26,6 +26,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/beevik/etree"
|
"github.com/beevik/etree"
|
||||||
|
"github.com/casdoor/casdoor/i18n"
|
||||||
"github.com/casdoor/casdoor/util"
|
"github.com/casdoor/casdoor/util"
|
||||||
dsig "github.com/russellhaering/goxmldsig"
|
dsig "github.com/russellhaering/goxmldsig"
|
||||||
)
|
)
|
||||||
@@ -122,6 +123,13 @@ var stToServiceResponse sync.Map
|
|||||||
// pgt is short for proxy granting ticket
|
// pgt is short for proxy granting ticket
|
||||||
var pgtToServiceResponse sync.Map
|
var pgtToServiceResponse sync.Map
|
||||||
|
|
||||||
|
func CheckCasRestrict(application *Application, lang string, service string) error {
|
||||||
|
if len(application.RedirectUris) > 0 && !application.IsRedirectUriValid(service) {
|
||||||
|
return fmt.Errorf(i18n.Translate(lang, "token:Redirect URI: %s doesn't exist in the allowed Redirect URI list"), service)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func StoreCasTokenForPgt(token *CasAuthenticationSuccess, service, userId string) string {
|
func StoreCasTokenForPgt(token *CasAuthenticationSuccess, service, userId string) string {
|
||||||
pgt := fmt.Sprintf("PGT-%s", util.GenerateId())
|
pgt := fmt.Sprintf("PGT-%s", util.GenerateId())
|
||||||
pgtToServiceResponse.Store(pgt, &CasAuthenticationSuccessWrapper{
|
pgtToServiceResponse.Store(pgt, &CasAuthenticationSuccessWrapper{
|
||||||
|
@@ -281,6 +281,14 @@ func generateJwtToken(application *Application, user *User, nonce string, scope
|
|||||||
return "", "", "", err
|
return "", "", "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if cert == nil {
|
||||||
|
if application.Cert == "" {
|
||||||
|
return "", "", "", fmt.Errorf("The cert field of the application \"%s\" should not be empty", application.GetId())
|
||||||
|
} else {
|
||||||
|
return "", "", "", fmt.Errorf("The cert \"%s\" does not exist", application.Cert)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// RSA private key
|
// RSA private key
|
||||||
key, err := jwt.ParseRSAPrivateKeyFromPEM([]byte(cert.PrivateKey))
|
key, err := jwt.ParseRSAPrivateKeyFromPEM([]byte(cert.PrivateKey))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@@ -156,11 +156,13 @@ type User struct {
|
|||||||
Yammer string `xorm:"yammer varchar(100)" json:"yammer"`
|
Yammer string `xorm:"yammer varchar(100)" json:"yammer"`
|
||||||
Yandex string `xorm:"yandex varchar(100)" json:"yandex"`
|
Yandex string `xorm:"yandex varchar(100)" json:"yandex"`
|
||||||
Zoom string `xorm:"zoom varchar(100)" json:"zoom"`
|
Zoom string `xorm:"zoom varchar(100)" json:"zoom"`
|
||||||
|
MetaMask string `xorm:"metamask varchar(100)" json:"metamask"`
|
||||||
Custom string `xorm:"custom varchar(100)" json:"custom"`
|
Custom string `xorm:"custom varchar(100)" json:"custom"`
|
||||||
|
|
||||||
WebauthnCredentials []webauthn.Credential `xorm:"webauthnCredentials blob" json:"webauthnCredentials"`
|
WebauthnCredentials []webauthn.Credential `xorm:"webauthnCredentials blob" json:"webauthnCredentials"`
|
||||||
PreferredMfaType string `xorm:"varchar(100)" json:"preferredMfaType"`
|
PreferredMfaType string `xorm:"varchar(100)" json:"preferredMfaType"`
|
||||||
RecoveryCodes []string `xorm:"varchar(1000)" json:"recoveryCodes,omitempty"`
|
RecoveryCodes []string `xorm:"varchar(1000)" json:"recoveryCodes"`
|
||||||
|
TotpSecret string `xorm:"varchar(100)" json:"totpSecret"`
|
||||||
MfaPhoneEnabled bool `json:"mfaPhoneEnabled"`
|
MfaPhoneEnabled bool `json:"mfaPhoneEnabled"`
|
||||||
MfaEmailEnabled bool `json:"mfaEmailEnabled"`
|
MfaEmailEnabled bool `json:"mfaEmailEnabled"`
|
||||||
MultiFactorAuths []*MfaProps `xorm:"-" json:"multiFactorAuths,omitempty"`
|
MultiFactorAuths []*MfaProps `xorm:"-" json:"multiFactorAuths,omitempty"`
|
||||||
@@ -417,7 +419,7 @@ func GetUserNoCheck(id string) (*User, error) {
|
|||||||
return getUser(owner, name)
|
return getUser(owner, name)
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetMaskedUser(user *User, errs ...error) (*User, error) {
|
func GetMaskedUser(user *User, isAdminOrSelf bool, errs ...error) (*User, error) {
|
||||||
if len(errs) > 0 && errs[0] != nil {
|
if len(errs) > 0 && errs[0] != nil {
|
||||||
return nil, errs[0]
|
return nil, errs[0]
|
||||||
}
|
}
|
||||||
@@ -429,11 +431,11 @@ func GetMaskedUser(user *User, errs ...error) (*User, error) {
|
|||||||
if user.Password != "" {
|
if user.Password != "" {
|
||||||
user.Password = "***"
|
user.Password = "***"
|
||||||
}
|
}
|
||||||
if user.AccessSecret != "" {
|
|
||||||
user.AccessSecret = "***"
|
if !isAdminOrSelf {
|
||||||
}
|
if user.AccessSecret != "" {
|
||||||
if user.RecoveryCodes != nil {
|
user.AccessSecret = "***"
|
||||||
user.RecoveryCodes = nil
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if user.ManagedAccounts != nil {
|
if user.ManagedAccounts != nil {
|
||||||
@@ -442,6 +444,13 @@ func GetMaskedUser(user *User, errs ...error) (*User, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if user.TotpSecret != "" {
|
||||||
|
user.TotpSecret = ""
|
||||||
|
}
|
||||||
|
if user.RecoveryCodes != nil {
|
||||||
|
user.RecoveryCodes = nil
|
||||||
|
}
|
||||||
|
|
||||||
return user, nil
|
return user, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -452,7 +461,7 @@ func GetMaskedUsers(users []*User, errs ...error) ([]*User, error) {
|
|||||||
|
|
||||||
var err error
|
var err error
|
||||||
for _, user := range users {
|
for _, user := range users {
|
||||||
user, err = GetMaskedUser(user)
|
user, err = GetMaskedUser(user, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -828,11 +837,14 @@ func userChangeTrigger(oldName string, newName string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (user *User) IsMfaEnabled() bool {
|
func (user *User) IsMfaEnabled() bool {
|
||||||
|
if user == nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
return user.PreferredMfaType != ""
|
return user.PreferredMfaType != ""
|
||||||
}
|
}
|
||||||
|
|
||||||
func (user *User) GetPreferredMfaProps(masked bool) *MfaProps {
|
func (user *User) GetPreferredMfaProps(masked bool) *MfaProps {
|
||||||
if user.PreferredMfaType == "" {
|
if user == nil || user.PreferredMfaType == "" {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return user.GetMfaProps(user.PreferredMfaType, masked)
|
return user.GetMfaProps(user.PreferredMfaType, masked)
|
||||||
|
@@ -293,7 +293,13 @@ func CheckPermissionForUpdateUser(oldUser, newUser *User, isAdmin bool, lang str
|
|||||||
itemsChanged = append(itemsChanged, item)
|
itemsChanged = append(itemsChanged, item)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if oldUser.Groups == nil {
|
||||||
|
oldUser.Groups = []string{}
|
||||||
|
}
|
||||||
oldUserGroupsJson, _ := json.Marshal(oldUser.Groups)
|
oldUserGroupsJson, _ := json.Marshal(oldUser.Groups)
|
||||||
|
if newUser.Groups == nil {
|
||||||
|
newUser.Groups = []string{}
|
||||||
|
}
|
||||||
newUserGroupsJson, _ := json.Marshal(newUser.Groups)
|
newUserGroupsJson, _ := json.Marshal(newUser.Groups)
|
||||||
if string(oldUserGroupsJson) != string(newUserGroupsJson) {
|
if string(oldUserGroupsJson) != string(newUserGroupsJson) {
|
||||||
item := GetAccountItemByName("Groups", organization)
|
item := GetAccountItemByName("Groups", organization)
|
||||||
|
@@ -156,7 +156,7 @@ func AuthzFilter(ctx *context.Context) {
|
|||||||
urlPath := getUrlPath(ctx.Request.URL.Path)
|
urlPath := getUrlPath(ctx.Request.URL.Path)
|
||||||
|
|
||||||
objOwner, objName := "", ""
|
objOwner, objName := "", ""
|
||||||
if urlPath != "/api/get-app-login" {
|
if urlPath != "/api/get-app-login" && urlPath != "/api/get-resource" {
|
||||||
objOwner, objName = getObject(ctx)
|
objOwner, objName = getObject(ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -33,6 +33,13 @@ func CorsFilter(ctx *context.Context) {
|
|||||||
origin := ctx.Input.Header(headerOrigin)
|
origin := ctx.Input.Header(headerOrigin)
|
||||||
originConf := conf.GetConfigString("origin")
|
originConf := conf.GetConfigString("origin")
|
||||||
|
|
||||||
|
if ctx.Request.Method == "POST" && ctx.Request.RequestURI == "/api/login/oauth/access_token" {
|
||||||
|
ctx.Output.Header(headerAllowOrigin, origin)
|
||||||
|
ctx.Output.Header(headerAllowMethods, "POST, GET, OPTIONS, DELETE")
|
||||||
|
ctx.Output.Header(headerAllowHeaders, "Content-Type, Authorization")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
if origin != "" && originConf != "" && origin != originConf {
|
if origin != "" && originConf != "" && origin != originConf {
|
||||||
ok, err := object.IsOriginAllowed(origin)
|
ok, err := object.IsOriginAllowed(origin)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@@ -55,7 +55,7 @@ func StaticFilter(ctx *context.Context) {
|
|||||||
path += urlPath
|
path += urlPath
|
||||||
}
|
}
|
||||||
|
|
||||||
path2 := strings.TrimLeft(path, "web/build/images/")
|
path2 := strings.TrimPrefix(path, "web/build/images/")
|
||||||
if util.FileExist(path2) {
|
if util.FileExist(path2) {
|
||||||
makeGzipResponse(ctx.ResponseWriter, ctx.Request, path2)
|
makeGzipResponse(ctx.ResponseWriter, ctx.Request, path2)
|
||||||
return
|
return
|
||||||
|
@@ -23,7 +23,7 @@ func GetStorageProvider(providerType string, clientId string, clientSecret strin
|
|||||||
case "AWS S3":
|
case "AWS S3":
|
||||||
return NewAwsS3StorageProvider(clientId, clientSecret, region, bucket, endpoint)
|
return NewAwsS3StorageProvider(clientId, clientSecret, region, bucket, endpoint)
|
||||||
case "MinIO":
|
case "MinIO":
|
||||||
return NewMinIOS3StorageProvider(clientId, clientSecret, region, bucket, endpoint)
|
return NewMinIOS3StorageProvider(clientId, clientSecret, "_", bucket, endpoint)
|
||||||
case "Aliyun OSS":
|
case "Aliyun OSS":
|
||||||
return NewAliyunOssStorageProvider(clientId, clientSecret, region, bucket, endpoint)
|
return NewAliyunOssStorageProvider(clientId, clientSecret, region, bucket, endpoint)
|
||||||
case "Tencent Cloud COS":
|
case "Tencent Cloud COS":
|
||||||
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -72,6 +72,9 @@ func UrlJoin(base string, path string) string {
|
|||||||
|
|
||||||
func GetUrlPath(urlString string) string {
|
func GetUrlPath(urlString string) string {
|
||||||
u, _ := url.Parse(urlString)
|
u, _ := url.Parse(urlString)
|
||||||
|
if u == nil {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
return u.Path
|
return u.Path
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -43,6 +43,15 @@ func ContainsString(values []string, val string) bool {
|
|||||||
return sort.SearchStrings(values, val) != len(values)
|
return sort.SearchStrings(values, val) != len(values)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func InSlice(slice []string, elem string) bool {
|
||||||
|
for _, val := range slice {
|
||||||
|
if val == elem {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
func ReturnAnyNotEmpty(strs ...string) string {
|
func ReturnAnyNotEmpty(strs ...string) string {
|
||||||
for _, str := range strs {
|
for _, str := range strs {
|
||||||
if str != "" {
|
if str != "" {
|
||||||
|
@@ -289,3 +289,18 @@ func HasString(strs []string, str string) bool {
|
|||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func ParseIdToString(input interface{}) (string, error) {
|
||||||
|
switch v := input.(type) {
|
||||||
|
case string:
|
||||||
|
return v, nil
|
||||||
|
case int:
|
||||||
|
return strconv.Itoa(v), nil
|
||||||
|
case int64:
|
||||||
|
return strconv.FormatInt(v, 10), nil
|
||||||
|
case float64:
|
||||||
|
return strconv.FormatFloat(v, 'f', -1, 64), nil
|
||||||
|
default:
|
||||||
|
return "", fmt.Errorf("unsupported id type: %T", input)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@@ -246,3 +246,23 @@ func TestSnakeString(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestParseId(t *testing.T) {
|
||||||
|
scenarios := []struct {
|
||||||
|
description string
|
||||||
|
input interface{}
|
||||||
|
expected interface{}
|
||||||
|
}{
|
||||||
|
{"Should be return 123456", "123456", "123456"},
|
||||||
|
{"Should be return 123456", 123456, "123456"},
|
||||||
|
{"Should be return 123456", int64(123456), "123456"},
|
||||||
|
{"Should be return 123456", float64(123456), "123456"},
|
||||||
|
}
|
||||||
|
for _, scenery := range scenarios {
|
||||||
|
t.Run(scenery.description, func(t *testing.T) {
|
||||||
|
actual, err := ParseIdToString(scenery.input)
|
||||||
|
assert.Nil(t, err, "The returned value not is expected")
|
||||||
|
assert.Equal(t, scenery.expected, actual, "The returned value not is expected")
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@@ -22,10 +22,18 @@ import (
|
|||||||
"github.com/nyaruka/phonenumbers"
|
"github.com/nyaruka/phonenumbers"
|
||||||
)
|
)
|
||||||
|
|
||||||
var rePhone *regexp.Regexp
|
var (
|
||||||
|
rePhone *regexp.Regexp
|
||||||
|
ReWhiteSpace *regexp.Regexp
|
||||||
|
ReFieldWhiteList *regexp.Regexp
|
||||||
|
ReUserName *regexp.Regexp
|
||||||
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
rePhone, _ = regexp.Compile(`(\d{3})\d*(\d{4})`)
|
rePhone, _ = regexp.Compile(`(\d{3})\d*(\d{4})`)
|
||||||
|
ReWhiteSpace, _ = regexp.Compile(`\s`)
|
||||||
|
ReFieldWhiteList, _ = regexp.Compile(`^[A-Za-z0-9]+$`)
|
||||||
|
ReUserName, _ = regexp.Compile("^[a-zA-Z0-9]+((?:-[a-zA-Z0-9]+)|(?:_[a-zA-Z0-9]+))*$")
|
||||||
}
|
}
|
||||||
|
|
||||||
func IsEmailValid(email string) bool {
|
func IsEmailValid(email string) bool {
|
||||||
@@ -70,3 +78,7 @@ func GetCountryCode(prefix string, phone string) (string, error) {
|
|||||||
|
|
||||||
return countryCode, nil
|
return countryCode, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func FilterField(field string) bool {
|
||||||
|
return ReFieldWhiteList.MatchString(field)
|
||||||
|
}
|
||||||
|
@@ -50,4 +50,32 @@ module.exports = {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
webpack: {
|
||||||
|
// use polyfill Buffer with Webpack 5
|
||||||
|
// https://viglucci.io/articles/how-to-polyfill-buffer-with-webpack-5
|
||||||
|
// https://craco.js.org/docs/configuration/webpack/
|
||||||
|
configure: (webpackConfig, { env, paths }) => {
|
||||||
|
webpackConfig.resolve.fallback = {
|
||||||
|
// "process": require.resolve('process/browser'),
|
||||||
|
// "util": require.resolve("util/"),
|
||||||
|
// "url": require.resolve("url/"),
|
||||||
|
// "zlib": require.resolve("browserify-zlib"),
|
||||||
|
// "stream": require.resolve("stream-browserify"),
|
||||||
|
// "http": require.resolve("stream-http"),
|
||||||
|
// "https": require.resolve("https-browserify"),
|
||||||
|
// "assert": require.resolve("assert/"),
|
||||||
|
"buffer": require.resolve('buffer/'),
|
||||||
|
"process": false,
|
||||||
|
"util": false,
|
||||||
|
"url": false,
|
||||||
|
"zlib": false,
|
||||||
|
"stream": false,
|
||||||
|
"http": false,
|
||||||
|
"https": false,
|
||||||
|
"assert": false,
|
||||||
|
"buffer": false,
|
||||||
|
};
|
||||||
|
return webpackConfig;
|
||||||
|
},
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
@@ -9,11 +9,13 @@
|
|||||||
"@crowdin/cli": "^3.7.10",
|
"@crowdin/cli": "^3.7.10",
|
||||||
"@ctrl/tinycolor": "^3.5.0",
|
"@ctrl/tinycolor": "^3.5.0",
|
||||||
"@emotion/react": "^11.10.5",
|
"@emotion/react": "^11.10.5",
|
||||||
|
"@metamask/eth-sig-util": "^6.0.0",
|
||||||
"@testing-library/jest-dom": "^4.2.4",
|
"@testing-library/jest-dom": "^4.2.4",
|
||||||
"@testing-library/react": "^9.3.2",
|
"@testing-library/react": "^9.3.2",
|
||||||
"@testing-library/user-event": "^7.1.2",
|
"@testing-library/user-event": "^7.1.2",
|
||||||
"antd": "5.2.3",
|
"antd": "5.2.3",
|
||||||
"antd-token-previewer": "^1.1.0-22",
|
"antd-token-previewer": "^1.1.0-22",
|
||||||
|
"buffer": "^6.0.3",
|
||||||
"codemirror": "^5.61.1",
|
"codemirror": "^5.61.1",
|
||||||
"copy-to-clipboard": "^3.3.1",
|
"copy-to-clipboard": "^3.3.1",
|
||||||
"core-js": "^3.25.0",
|
"core-js": "^3.25.0",
|
||||||
@@ -24,8 +26,6 @@
|
|||||||
"i18next": "^19.8.9",
|
"i18next": "^19.8.9",
|
||||||
"libphonenumber-js": "^1.10.19",
|
"libphonenumber-js": "^1.10.19",
|
||||||
"moment": "^2.29.1",
|
"moment": "^2.29.1",
|
||||||
"qrcode.react": "^3.1.0",
|
|
||||||
"qs": "^6.10.2",
|
|
||||||
"react": "^18.2.0",
|
"react": "^18.2.0",
|
||||||
"react-app-polyfill": "^3.0.0",
|
"react-app-polyfill": "^3.0.0",
|
||||||
"react-codemirror2": "^7.2.1",
|
"react-codemirror2": "^7.2.1",
|
||||||
@@ -36,6 +36,7 @@
|
|||||||
"react-helmet": "^6.1.0",
|
"react-helmet": "^6.1.0",
|
||||||
"react-highlight-words": "^0.18.0",
|
"react-highlight-words": "^0.18.0",
|
||||||
"react-i18next": "^11.8.7",
|
"react-i18next": "^11.8.7",
|
||||||
|
"react-metamask-avatar": "^1.2.1",
|
||||||
"react-router-dom": "^5.3.3",
|
"react-router-dom": "^5.3.3",
|
||||||
"react-scripts": "5.0.1",
|
"react-scripts": "5.0.1",
|
||||||
"react-social-login-buttons": "^3.4.0"
|
"react-social-login-buttons": "^3.4.0"
|
||||||
|
@@ -68,7 +68,7 @@ class AdapterEditPage extends React.Component {
|
|||||||
OrganizationBackend.getOrganizations("admin")
|
OrganizationBackend.getOrganizations("admin")
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
this.setState({
|
this.setState({
|
||||||
organizations: (res.msg === undefined) ? res : [],
|
organizations: res.data || [],
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -76,8 +76,13 @@ class AdapterEditPage extends React.Component {
|
|||||||
getModels(organizationName) {
|
getModels(organizationName) {
|
||||||
ModelBackend.getModels(organizationName)
|
ModelBackend.getModels(organizationName)
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
|
if (res.status === "error") {
|
||||||
|
Setting.showMessage("error", res.msg);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
this.setState({
|
this.setState({
|
||||||
models: res,
|
models: res.data,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@@ -25,8 +25,9 @@ import PopconfirmModal from "./common/modal/PopconfirmModal";
|
|||||||
class AdapterListPage extends BaseListPage {
|
class AdapterListPage extends BaseListPage {
|
||||||
newAdapter() {
|
newAdapter() {
|
||||||
const randomName = Setting.getRandomName();
|
const randomName = Setting.getRandomName();
|
||||||
|
const owner = Setting.getRequestOrganization(this.props.account);
|
||||||
return {
|
return {
|
||||||
owner: this.props.account.owner,
|
owner: owner,
|
||||||
name: `adapter_${randomName}`,
|
name: `adapter_${randomName}`,
|
||||||
createdTime: moment().format(),
|
createdTime: moment().format(),
|
||||||
type: "Database",
|
type: "Database",
|
||||||
@@ -87,7 +88,7 @@ class AdapterListPage extends BaseListPage {
|
|||||||
...this.getColumnSearchProps("name"),
|
...this.getColumnSearchProps("name"),
|
||||||
render: (text, record, index) => {
|
render: (text, record, index) => {
|
||||||
return (
|
return (
|
||||||
<Link to={`/adapters/${record.organization}/${text}`}>
|
<Link to={`/adapters/${record.owner}/${text}`}>
|
||||||
{text}
|
{text}
|
||||||
</Link>
|
</Link>
|
||||||
);
|
);
|
||||||
@@ -246,7 +247,7 @@ class AdapterListPage extends BaseListPage {
|
|||||||
value = params.type;
|
value = params.type;
|
||||||
}
|
}
|
||||||
this.setState({loading: true});
|
this.setState({loading: true});
|
||||||
AdapterBackend.getAdapters(Setting.isAdminUser(this.props.account) ? "" : this.props.account.owner, params.pagination.current, params.pagination.pageSize, field, value, sortField, sortOrder)
|
AdapterBackend.getAdapters(Setting.isDefaultOrganizationSelected(this.props.account) ? "" : Setting.getRequestOrganization(this.props.account), params.pagination.current, params.pagination.pageSize, field, value, sortField, sortOrder)
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
this.setState({
|
this.setState({
|
||||||
loading: false,
|
loading: false,
|
||||||
|
117
web/src/App.js
117
web/src/App.js
@@ -15,9 +15,11 @@
|
|||||||
import React, {Component} from "react";
|
import React, {Component} from "react";
|
||||||
import "./App.less";
|
import "./App.less";
|
||||||
import {Helmet} from "react-helmet";
|
import {Helmet} from "react-helmet";
|
||||||
|
import EnableMfaNotification from "./common/notifaction/EnableMfaNotification";
|
||||||
import GroupTreePage from "./GroupTreePage";
|
import GroupTreePage from "./GroupTreePage";
|
||||||
import GroupEditPage from "./GroupEdit";
|
import GroupEditPage from "./GroupEdit";
|
||||||
import GroupListPage from "./GroupList";
|
import GroupListPage from "./GroupList";
|
||||||
|
import {MfaRuleRequired} from "./Setting";
|
||||||
import * as Setting from "./Setting";
|
import * as Setting from "./Setting";
|
||||||
import {StyleProvider, legacyLogicalPropertiesTransformer} from "@ant-design/cssinjs";
|
import {StyleProvider, legacyLogicalPropertiesTransformer} from "@ant-design/cssinjs";
|
||||||
import {BarsOutlined, CommentOutlined, DownOutlined, InfoCircleFilled, LogoutOutlined, SettingOutlined} from "@ant-design/icons";
|
import {BarsOutlined, CommentOutlined, DownOutlined, InfoCircleFilled, LogoutOutlined, SettingOutlined} from "@ant-design/icons";
|
||||||
@@ -64,6 +66,13 @@ import ProductBuyPage from "./ProductBuyPage";
|
|||||||
import PaymentListPage from "./PaymentListPage";
|
import PaymentListPage from "./PaymentListPage";
|
||||||
import PaymentEditPage from "./PaymentEditPage";
|
import PaymentEditPage from "./PaymentEditPage";
|
||||||
import PaymentResultPage from "./PaymentResultPage";
|
import PaymentResultPage from "./PaymentResultPage";
|
||||||
|
import ModelListPage from "./ModelListPage";
|
||||||
|
import ModelEditPage from "./ModelEditPage";
|
||||||
|
import AdapterListPage from "./AdapterListPage";
|
||||||
|
import AdapterEditPage from "./AdapterEditPage";
|
||||||
|
import SessionListPage from "./SessionListPage";
|
||||||
|
import MfaSetupPage from "./auth/MfaSetupPage";
|
||||||
|
import SystemInfo from "./SystemInfo";
|
||||||
import AccountPage from "./account/AccountPage";
|
import AccountPage from "./account/AccountPage";
|
||||||
import HomePage from "./basic/HomePage";
|
import HomePage from "./basic/HomePage";
|
||||||
import CustomGithubCorner from "./common/CustomGithubCorner";
|
import CustomGithubCorner from "./common/CustomGithubCorner";
|
||||||
@@ -73,19 +82,15 @@ import * as Auth from "./auth/Auth";
|
|||||||
import EntryPage from "./EntryPage";
|
import EntryPage from "./EntryPage";
|
||||||
import * as AuthBackend from "./auth/AuthBackend";
|
import * as AuthBackend from "./auth/AuthBackend";
|
||||||
import AuthCallback from "./auth/AuthCallback";
|
import AuthCallback from "./auth/AuthCallback";
|
||||||
import LanguageSelect from "./common/select/LanguageSelect";
|
|
||||||
import i18next from "i18next";
|
|
||||||
import OdicDiscoveryPage from "./auth/OidcDiscoveryPage";
|
import OdicDiscoveryPage from "./auth/OidcDiscoveryPage";
|
||||||
import SamlCallback from "./auth/SamlCallback";
|
import SamlCallback from "./auth/SamlCallback";
|
||||||
import ModelListPage from "./ModelListPage";
|
import i18next from "i18next";
|
||||||
import ModelEditPage from "./ModelEditPage";
|
|
||||||
import SystemInfo from "./SystemInfo";
|
|
||||||
import AdapterListPage from "./AdapterListPage";
|
|
||||||
import AdapterEditPage from "./AdapterEditPage";
|
|
||||||
import {withTranslation} from "react-i18next";
|
import {withTranslation} from "react-i18next";
|
||||||
|
import LanguageSelect from "./common/select/LanguageSelect";
|
||||||
import ThemeSelect from "./common/select/ThemeSelect";
|
import ThemeSelect from "./common/select/ThemeSelect";
|
||||||
import SessionListPage from "./SessionListPage";
|
import OrganizationSelect from "./common/select/OrganizationSelect";
|
||||||
import MfaSetupPage from "./auth/MfaSetupPage";
|
import {clearWeb3AuthToken} from "./auth/Web3Auth";
|
||||||
|
import AccountAvatar from "./account/AccountAvatar";
|
||||||
|
|
||||||
const {Header, Footer, Content} = Layout;
|
const {Header, Footer, Content} = Layout;
|
||||||
|
|
||||||
@@ -101,12 +106,13 @@ class App extends Component {
|
|||||||
themeAlgorithm: ["default"],
|
themeAlgorithm: ["default"],
|
||||||
themeData: Conf.ThemeDefault,
|
themeData: Conf.ThemeDefault,
|
||||||
logo: this.getLogo(Setting.getAlgorithmNames(Conf.ThemeDefault)),
|
logo: this.getLogo(Setting.getAlgorithmNames(Conf.ThemeDefault)),
|
||||||
|
requiredEnableMfa: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
Setting.initServerUrl();
|
Setting.initServerUrl();
|
||||||
Auth.initAuthWithConfig({
|
Auth.initAuthWithConfig({
|
||||||
serverUrl: Setting.ServerUrl,
|
serverUrl: Setting.ServerUrl,
|
||||||
appName: "app-built-in", // the application name of Casdoor itself, do not change it
|
appName: Conf.DefaultApplication, // the application used in Casdoor root path: "/"
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -115,16 +121,29 @@ class App extends Component {
|
|||||||
this.getAccount();
|
this.getAccount();
|
||||||
}
|
}
|
||||||
|
|
||||||
componentDidUpdate() {
|
componentDidUpdate(prevProps, prevState, snapshot) {
|
||||||
// eslint-disable-next-line no-restricted-globals
|
|
||||||
const uri = location.pathname;
|
const uri = location.pathname;
|
||||||
if (this.state.uri !== uri) {
|
if (this.state.uri !== uri) {
|
||||||
this.updateMenuKey();
|
this.updateMenuKey();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (this.state.account !== prevState.account) {
|
||||||
|
const requiredEnableMfa = Setting.isRequiredEnableMfa(this.state.account, this.state.account?.organization);
|
||||||
|
this.setState({
|
||||||
|
requiredEnableMfa: requiredEnableMfa,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (requiredEnableMfa === true) {
|
||||||
|
const mfaType = Setting.getMfaItemsByRules(this.state.account, this.state.account?.organization, [MfaRuleRequired])
|
||||||
|
.find((item) => item.rule === MfaRuleRequired)?.name;
|
||||||
|
if (mfaType !== undefined) {
|
||||||
|
this.props.history.push(`/mfa/setup?mfaType=${mfaType}`, {from: "/login"});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
updateMenuKey() {
|
updateMenuKey() {
|
||||||
// eslint-disable-next-line no-restricted-globals
|
|
||||||
const uri = location.pathname;
|
const uri = location.pathname;
|
||||||
this.setState({
|
this.setState({
|
||||||
uri: uri,
|
uri: uri,
|
||||||
@@ -295,12 +314,11 @@ class App extends Component {
|
|||||||
.then((res) => {
|
.then((res) => {
|
||||||
if (res.status === "ok") {
|
if (res.status === "ok") {
|
||||||
const owner = this.state.account.owner;
|
const owner = this.state.account.owner;
|
||||||
|
|
||||||
this.setState({
|
this.setState({
|
||||||
account: null,
|
account: null,
|
||||||
themeAlgorithm: ["default"],
|
themeAlgorithm: ["default"],
|
||||||
});
|
});
|
||||||
|
clearWeb3AuthToken();
|
||||||
Setting.showMessage("success", i18next.t("application:Logged out successfully"));
|
Setting.showMessage("success", i18next.t("application:Logged out successfully"));
|
||||||
const redirectUri = res.data2;
|
const redirectUri = res.data2;
|
||||||
if (redirectUri !== null && redirectUri !== undefined && redirectUri !== "") {
|
if (redirectUri !== null && redirectUri !== undefined && redirectUri !== "") {
|
||||||
@@ -331,7 +349,9 @@ class App extends Component {
|
|||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
return (
|
return (
|
||||||
<Avatar src={this.state.account.avatar} style={{verticalAlign: "middle"}} size="large">
|
<Avatar src={this.state.account.avatar} style={{verticalAlign: "middle"}} size="large"
|
||||||
|
icon={<AccountAvatar src={this.state.account.avatar} style={{verticalAlign: "middle"}} size={40} />}
|
||||||
|
>
|
||||||
{Setting.getShortName(this.state.account.name)}
|
{Setting.getShortName(this.state.account.name)}
|
||||||
</Avatar>
|
</Avatar>
|
||||||
);
|
);
|
||||||
@@ -340,13 +360,15 @@ class App extends Component {
|
|||||||
|
|
||||||
renderRightDropdown() {
|
renderRightDropdown() {
|
||||||
const items = [];
|
const items = [];
|
||||||
items.push(Setting.getItem(<><SettingOutlined /> {i18next.t("account:My Account")}</>,
|
if (this.state.requiredEnableMfa === false) {
|
||||||
"/account"
|
items.push(Setting.getItem(<><SettingOutlined /> {i18next.t("account:My Account")}</>,
|
||||||
));
|
"/account"
|
||||||
if (Conf.EnableChatPages) {
|
|
||||||
items.push(Setting.getItem(<><CommentOutlined /> {i18next.t("account:Chats & Messages")}</>,
|
|
||||||
"/chat"
|
|
||||||
));
|
));
|
||||||
|
if (Conf.EnableChatPages) {
|
||||||
|
items.push(Setting.getItem(<><CommentOutlined /> {i18next.t("account:Chats & Messages")}</>,
|
||||||
|
"/chat"
|
||||||
|
));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
items.push(Setting.getItem(<><LogoutOutlined /> {i18next.t("account:Logout")}</>,
|
items.push(Setting.getItem(<><LogoutOutlined /> {i18next.t("account:Logout")}</>,
|
||||||
"/logout"));
|
"/logout"));
|
||||||
@@ -398,6 +420,17 @@ class App extends Component {
|
|||||||
});
|
});
|
||||||
}} />
|
}} />
|
||||||
<LanguageSelect languages={this.state.account.organization.languages} />
|
<LanguageSelect languages={this.state.account.organization.languages} />
|
||||||
|
{Setting.isAdminUser(this.state.account) && !Setting.isMobile() &&
|
||||||
|
<OrganizationSelect
|
||||||
|
initValue={Setting.getOrganization()}
|
||||||
|
withAll={true}
|
||||||
|
style={{marginRight: "20px", width: "180px", display: "flex"}}
|
||||||
|
onChange={(value) => {
|
||||||
|
Setting.setOrganization(value);
|
||||||
|
}}
|
||||||
|
className="select-box"
|
||||||
|
/>
|
||||||
|
}
|
||||||
</React.Fragment>
|
</React.Fragment>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -535,14 +568,6 @@ class App extends Component {
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
renderHomeIfLoggedIn(component) {
|
|
||||||
if (this.state.account !== null && this.state.account !== undefined) {
|
|
||||||
return <Redirect to="/" />;
|
|
||||||
} else {
|
|
||||||
return component;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
renderLoginIfNotLoggedIn(component) {
|
renderLoginIfNotLoggedIn(component) {
|
||||||
if (this.state.account === null) {
|
if (this.state.account === null) {
|
||||||
sessionStorage.setItem("from", window.location.pathname);
|
sessionStorage.setItem("from", window.location.pathname);
|
||||||
@@ -554,12 +579,6 @@ class App extends Component {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
isStartPages() {
|
|
||||||
return window.location.pathname.startsWith("/login") ||
|
|
||||||
window.location.pathname.startsWith("/signup") ||
|
|
||||||
window.location.pathname === "/";
|
|
||||||
}
|
|
||||||
|
|
||||||
renderRouter() {
|
renderRouter() {
|
||||||
return (
|
return (
|
||||||
<Switch>
|
<Switch>
|
||||||
@@ -611,13 +630,13 @@ class App extends Component {
|
|||||||
<Route exact path="/subscriptions" render={(props) => this.renderLoginIfNotLoggedIn(<SubscriptionListPage account={this.state.account} {...props} />)} />
|
<Route exact path="/subscriptions" render={(props) => this.renderLoginIfNotLoggedIn(<SubscriptionListPage account={this.state.account} {...props} />)} />
|
||||||
<Route exact path="/subscriptions/:organizationName/:subscriptionName" render={(props) => this.renderLoginIfNotLoggedIn(<SubscriptionEditPage account={this.state.account} {...props} />)} />
|
<Route exact path="/subscriptions/:organizationName/:subscriptionName" render={(props) => this.renderLoginIfNotLoggedIn(<SubscriptionEditPage account={this.state.account} {...props} />)} />
|
||||||
<Route exact path="/products" render={(props) => this.renderLoginIfNotLoggedIn(<ProductListPage account={this.state.account} {...props} />)} />
|
<Route exact path="/products" render={(props) => this.renderLoginIfNotLoggedIn(<ProductListPage account={this.state.account} {...props} />)} />
|
||||||
<Route exact path="/products/:productName" render={(props) => this.renderLoginIfNotLoggedIn(<ProductEditPage account={this.state.account} {...props} />)} />
|
<Route exact path="/products/:organizationName/:productName" render={(props) => this.renderLoginIfNotLoggedIn(<ProductEditPage account={this.state.account} {...props} />)} />
|
||||||
<Route exact path="/products/:productName/buy" render={(props) => this.renderLoginIfNotLoggedIn(<ProductBuyPage account={this.state.account} {...props} />)} />
|
<Route exact path="/products/:productName/buy" render={(props) => this.renderLoginIfNotLoggedIn(<ProductBuyPage account={this.state.account} {...props} />)} />
|
||||||
<Route exact path="/payments" render={(props) => this.renderLoginIfNotLoggedIn(<PaymentListPage account={this.state.account} {...props} />)} />
|
<Route exact path="/payments" render={(props) => this.renderLoginIfNotLoggedIn(<PaymentListPage account={this.state.account} {...props} />)} />
|
||||||
<Route exact path="/payments/:paymentName" render={(props) => this.renderLoginIfNotLoggedIn(<PaymentEditPage account={this.state.account} {...props} />)} />
|
<Route exact path="/payments/:paymentName" render={(props) => this.renderLoginIfNotLoggedIn(<PaymentEditPage account={this.state.account} {...props} />)} />
|
||||||
<Route exact path="/payments/:paymentName/result" render={(props) => this.renderLoginIfNotLoggedIn(<PaymentResultPage account={this.state.account} {...props} />)} />
|
<Route exact path="/payments/:paymentName/result" render={(props) => this.renderLoginIfNotLoggedIn(<PaymentResultPage account={this.state.account} {...props} />)} />
|
||||||
<Route exact path="/records" render={(props) => this.renderLoginIfNotLoggedIn(<RecordListPage account={this.state.account} {...props} />)} />
|
<Route exact path="/records" render={(props) => this.renderLoginIfNotLoggedIn(<RecordListPage account={this.state.account} {...props} />)} />
|
||||||
<Route exact path="/mfa-authentication/setup" render={(props) => this.renderLoginIfNotLoggedIn(<MfaSetupPage account={this.state.account} {...props} />)} />
|
<Route exact path="/mfa/setup" render={(props) => this.renderLoginIfNotLoggedIn(<MfaSetupPage account={this.state.account} onfinish={() => this.setState({requiredEnableMfa: false})} {...props} />)} />
|
||||||
<Route exact path="/.well-known/openid-configuration" render={(props) => <OdicDiscoveryPage />} />
|
<Route exact path="/.well-known/openid-configuration" render={(props) => <OdicDiscoveryPage />} />
|
||||||
<Route exact path="/sysinfo" render={(props) => this.renderLoginIfNotLoggedIn(<SystemInfo account={this.state.account} {...props} />)} />
|
<Route exact path="/sysinfo" render={(props) => this.renderLoginIfNotLoggedIn(<SystemInfo account={this.state.account} {...props} />)} />
|
||||||
<Route path="" render={() => <Result status="404" title="404 NOT FOUND" subTitle={i18next.t("general:Sorry, the page you visited does not exist.")}
|
<Route path="" render={() => <Result status="404" title="404 NOT FOUND" subTitle={i18next.t("general:Sorry, the page you visited does not exist.")}
|
||||||
@@ -648,18 +667,24 @@ class App extends Component {
|
|||||||
if (key === "/swagger") {
|
if (key === "/swagger") {
|
||||||
window.open(Setting.isLocalhost() ? `${Setting.ServerUrl}/swagger` : "/swagger", "_blank");
|
window.open(Setting.isLocalhost() ? `${Setting.ServerUrl}/swagger` : "/swagger", "_blank");
|
||||||
} else {
|
} else {
|
||||||
this.props.history.push(key);
|
if (this.state.requiredEnableMfa) {
|
||||||
|
Setting.showMessage("info", "Please enable MFA first!");
|
||||||
|
} else {
|
||||||
|
this.props.history.push(key);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
const menuStyleRight = Setting.isAdminUser(this.state.account) && !Setting.isMobile() ? "calc(180px + 260px)" : "260px";
|
||||||
return (
|
return (
|
||||||
<Layout id="parent-area">
|
<Layout id="parent-area">
|
||||||
<Header style={{padding: "0", marginBottom: "3px", backgroundColor: this.state.themeAlgorithm.includes("dark") ? "black" : "white"}}>
|
<EnableMfaNotification account={this.state.account} />
|
||||||
|
<Header style={{padding: "0", marginBottom: "3px", backgroundColor: this.state.themeAlgorithm.includes("dark") ? "black" : "white"}} >
|
||||||
{Setting.isMobile() ? null : (
|
{Setting.isMobile() ? null : (
|
||||||
<Link to={"/"}>
|
<Link to={"/"}>
|
||||||
<div className="logo" style={{background: `url(${this.state.logo})`}} />
|
<div className="logo" style={{background: `url(${this.state.logo})`}} />
|
||||||
</Link>
|
</Link>
|
||||||
)}
|
)}
|
||||||
{Setting.isMobile() ?
|
{this.state.requiredEnableMfa || (Setting.isMobile() ?
|
||||||
<React.Fragment>
|
<React.Fragment>
|
||||||
<Drawer title={i18next.t("general:Close")} placement="left" visible={this.state.menuVisible} onClose={this.onClose}>
|
<Drawer title={i18next.t("general:Close")} placement="left" visible={this.state.menuVisible} onClose={this.onClose}>
|
||||||
<Menu
|
<Menu
|
||||||
@@ -680,9 +705,9 @@ class App extends Component {
|
|||||||
items={this.getMenuItems()}
|
items={this.getMenuItems()}
|
||||||
mode={"horizontal"}
|
mode={"horizontal"}
|
||||||
selectedKeys={[this.state.selectedMenuKey]}
|
selectedKeys={[this.state.selectedMenuKey]}
|
||||||
style={{position: "absolute", left: "145px", right: "260px"}}
|
style={{position: "absolute", left: "145px", right: menuStyleRight}}
|
||||||
/>
|
/>
|
||||||
}
|
)}
|
||||||
{
|
{
|
||||||
this.renderAccountMenu()
|
this.renderAccountMenu()
|
||||||
}
|
}
|
||||||
@@ -746,9 +771,11 @@ class App extends Component {
|
|||||||
<EntryPage
|
<EntryPage
|
||||||
account={this.state.account}
|
account={this.state.account}
|
||||||
theme={this.state.themeData}
|
theme={this.state.themeData}
|
||||||
onUpdateAccount={(account) => {
|
onLoginSuccess={(redirectUrl) => {
|
||||||
this.onUpdateAccount(account);
|
localStorage.setItem("mfaRedirectUrl", redirectUrl);
|
||||||
|
this.getAccount();
|
||||||
}}
|
}}
|
||||||
|
onUpdateAccount={(account) => this.onUpdateAccount(account)}
|
||||||
updataThemeData={this.setTheme}
|
updataThemeData={this.setTheme}
|
||||||
/> :
|
/> :
|
||||||
<Switch>
|
<Switch>
|
||||||
|
@@ -118,15 +118,26 @@ class ApplicationEditPage extends React.Component {
|
|||||||
|
|
||||||
getApplication() {
|
getApplication() {
|
||||||
ApplicationBackend.getApplication("admin", this.state.applicationName)
|
ApplicationBackend.getApplication("admin", this.state.applicationName)
|
||||||
.then((application) => {
|
.then((res) => {
|
||||||
if (application === null) {
|
if (res.data === null) {
|
||||||
this.props.history.push("/404");
|
this.props.history.push("/404");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (res.status === "error") {
|
||||||
|
Setting.showMessage("error", res.msg);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const application = res.data;
|
||||||
if (application.grantTypes === null || application.grantTypes === undefined || application.grantTypes.length === 0) {
|
if (application.grantTypes === null || application.grantTypes === undefined || application.grantTypes.length === 0) {
|
||||||
application.grantTypes = ["authorization_code"];
|
application.grantTypes = ["authorization_code"];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (application.tags === null || application.tags === undefined) {
|
||||||
|
application.tags = [];
|
||||||
|
}
|
||||||
|
|
||||||
this.setState({
|
this.setState({
|
||||||
application: application,
|
application: application,
|
||||||
});
|
});
|
||||||
@@ -138,13 +149,13 @@ class ApplicationEditPage extends React.Component {
|
|||||||
getOrganizations() {
|
getOrganizations() {
|
||||||
OrganizationBackend.getOrganizations("admin")
|
OrganizationBackend.getOrganizations("admin")
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
if (res?.status === "error") {
|
if (res.status === "error") {
|
||||||
this.setState({
|
this.setState({
|
||||||
isAuthorized: false,
|
isAuthorized: false,
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
this.setState({
|
this.setState({
|
||||||
organizations: (res.msg === undefined) ? res : [],
|
organizations: res.data || [],
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -154,7 +165,7 @@ class ApplicationEditPage extends React.Component {
|
|||||||
CertBackend.getCerts(owner)
|
CertBackend.getCerts(owner)
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
this.setState({
|
this.setState({
|
||||||
certs: (res.msg === undefined) ? res : [],
|
certs: res.data || [],
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -174,9 +185,9 @@ class ApplicationEditPage extends React.Component {
|
|||||||
|
|
||||||
getSamlMetadata() {
|
getSamlMetadata() {
|
||||||
ApplicationBackend.getSamlMetadata("admin", this.state.applicationName)
|
ApplicationBackend.getSamlMetadata("admin", this.state.applicationName)
|
||||||
.then((res) => {
|
.then((data) => {
|
||||||
this.setState({
|
this.setState({
|
||||||
samlMetadata: res,
|
samlMetadata: data,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -307,6 +318,18 @@ class ApplicationEditPage extends React.Component {
|
|||||||
</Select>
|
</Select>
|
||||||
</Col>
|
</Col>
|
||||||
</Row>
|
</Row>
|
||||||
|
<Row style={{marginTop: "20px"}} >
|
||||||
|
<Col style={{marginTop: "5px"}} span={(Setting.isMobile()) ? 22 : 2}>
|
||||||
|
{Setting.getLabel(i18next.t("organization:Tags"), i18next.t("application:Tags - Tooltip"))} :
|
||||||
|
</Col>
|
||||||
|
<Col span={22} >
|
||||||
|
<Select virtual={false} mode="tags" style={{width: "100%"}} value={this.state.application.tags} onChange={(value => {this.updateApplicationField("tags", value);})}>
|
||||||
|
{
|
||||||
|
this.state.application.tags?.map((item, index) => <Option key={index} value={item}>{item}</Option>)
|
||||||
|
}
|
||||||
|
</Select>
|
||||||
|
</Col>
|
||||||
|
</Row>
|
||||||
<Row style={{marginTop: "20px"}} >
|
<Row style={{marginTop: "20px"}} >
|
||||||
<Col style={{marginTop: "5px"}} span={(Setting.isMobile()) ? 22 : 2}>
|
<Col style={{marginTop: "5px"}} span={(Setting.isMobile()) ? 22 : 2}>
|
||||||
{Setting.getLabel(i18next.t("provider:Client ID"), i18next.t("provider:Client ID - Tooltip"))} :
|
{Setting.getLabel(i18next.t("provider:Client ID"), i18next.t("provider:Client ID - Tooltip"))} :
|
||||||
|
@@ -28,18 +28,13 @@ class ApplicationListPage extends BaseListPage {
|
|||||||
super(props);
|
super(props);
|
||||||
}
|
}
|
||||||
|
|
||||||
componentDidMount() {
|
|
||||||
this.setState({
|
|
||||||
organizationName: this.props.account.owner,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
newApplication() {
|
newApplication() {
|
||||||
const randomName = Setting.getRandomName();
|
const randomName = Setting.getRandomName();
|
||||||
|
const organizationName = Setting.getRequestOrganization(this.props.account);
|
||||||
return {
|
return {
|
||||||
owner: "admin", // this.props.account.applicationName,
|
owner: "admin", // this.props.account.applicationName,
|
||||||
name: `application_${randomName}`,
|
name: `application_${randomName}`,
|
||||||
organization: this.state.organizationName,
|
organization: organizationName,
|
||||||
createdTime: moment().format(),
|
createdTime: moment().format(),
|
||||||
displayName: `New Application - ${randomName}`,
|
displayName: `New Application - ${randomName}`,
|
||||||
logo: `${Setting.StaticBaseUrl}/img/casdoor-logo_1185x256.png`,
|
logo: `${Setting.StaticBaseUrl}/img/casdoor-logo_1185x256.png`,
|
||||||
@@ -273,8 +268,8 @@ class ApplicationListPage extends BaseListPage {
|
|||||||
const field = params.searchedColumn, value = params.searchText;
|
const field = params.searchedColumn, value = params.searchText;
|
||||||
const sortField = params.sortField, sortOrder = params.sortOrder;
|
const sortField = params.sortField, sortOrder = params.sortOrder;
|
||||||
this.setState({loading: true});
|
this.setState({loading: true});
|
||||||
(Setting.isAdminUser(this.props.account) ? ApplicationBackend.getApplications("admin", params.pagination.current, params.pagination.pageSize, field, value, sortField, sortOrder) :
|
(Setting.isDefaultOrganizationSelected(this.props.account) ? ApplicationBackend.getApplications("admin", params.pagination.current, params.pagination.pageSize, field, value, sortField, sortOrder) :
|
||||||
ApplicationBackend.getApplicationsByOrganization("admin", this.props.account.organization.name, params.pagination.current, params.pagination.pageSize, field, value, sortField, sortOrder))
|
ApplicationBackend.getApplicationsByOrganization("admin", Setting.getRequestOrganization(this.props.account), params.pagination.current, params.pagination.pageSize, field, value, sortField, sortOrder))
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
this.setState({
|
this.setState({
|
||||||
loading: false,
|
loading: false,
|
||||||
|
@@ -17,6 +17,7 @@ import {Button, Input, Result, Space} from "antd";
|
|||||||
import {SearchOutlined} from "@ant-design/icons";
|
import {SearchOutlined} from "@ant-design/icons";
|
||||||
import Highlighter from "react-highlight-words";
|
import Highlighter from "react-highlight-words";
|
||||||
import i18next from "i18next";
|
import i18next from "i18next";
|
||||||
|
import * as Setting from "./Setting";
|
||||||
|
|
||||||
class BaseListPage extends React.Component {
|
class BaseListPage extends React.Component {
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
@@ -35,6 +36,22 @@ class BaseListPage extends React.Component {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
handleOrganizationChange = () => {
|
||||||
|
const {pagination} = this.state;
|
||||||
|
this.fetch({pagination});
|
||||||
|
};
|
||||||
|
|
||||||
|
componentDidMount() {
|
||||||
|
window.addEventListener("storageOrganizationChanged", this.handleOrganizationChange);
|
||||||
|
if (!Setting.isAdminUser(this.props.account)) {
|
||||||
|
Setting.setOrganization("All");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
componentWillUnmount() {
|
||||||
|
window.removeEventListener("storageOrganizationChanged", this.handleOrganizationChange);
|
||||||
|
}
|
||||||
|
|
||||||
UNSAFE_componentWillMount() {
|
UNSAFE_componentWillMount() {
|
||||||
const {pagination} = this.state;
|
const {pagination} = this.state;
|
||||||
this.fetch({pagination});
|
this.fetch({pagination});
|
||||||
|
@@ -44,14 +44,19 @@ class CertEditPage extends React.Component {
|
|||||||
|
|
||||||
getCert() {
|
getCert() {
|
||||||
CertBackend.getCert(this.state.owner, this.state.certName)
|
CertBackend.getCert(this.state.owner, this.state.certName)
|
||||||
.then((cert) => {
|
.then((res) => {
|
||||||
if (cert === null) {
|
if (res.data === null) {
|
||||||
this.props.history.push("/404");
|
this.props.history.push("/404");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (res.status === "error") {
|
||||||
|
Setting.showMessage("error", res.msg);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
this.setState({
|
this.setState({
|
||||||
cert: cert,
|
cert: res.data,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -60,7 +65,7 @@ class CertEditPage extends React.Component {
|
|||||||
OrganizationBackend.getOrganizations("admin")
|
OrganizationBackend.getOrganizations("admin")
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
this.setState({
|
this.setState({
|
||||||
organizations: (res.msg === undefined) ? res : [],
|
organizations: res.data || [],
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -153,6 +158,7 @@ class CertEditPage extends React.Component {
|
|||||||
{
|
{
|
||||||
[
|
[
|
||||||
{id: "x509", name: "x509"},
|
{id: "x509", name: "x509"},
|
||||||
|
{id: "Payment", name: "Payment"},
|
||||||
].map((item, index) => <Option key={index} value={item.id}>{item.name}</Option>)
|
].map((item, index) => <Option key={index} value={item.id}>{item.name}</Option>)
|
||||||
}
|
}
|
||||||
</Select>
|
</Select>
|
||||||
|
@@ -28,6 +28,7 @@ class CertListPage extends BaseListPage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
|
super.componentDidMount();
|
||||||
this.setState({
|
this.setState({
|
||||||
owner: Setting.isAdminUser(this.props.account) ? "admin" : this.props.account.owner,
|
owner: Setting.isAdminUser(this.props.account) ? "admin" : this.props.account.owner,
|
||||||
});
|
});
|
||||||
@@ -35,8 +36,9 @@ class CertListPage extends BaseListPage {
|
|||||||
|
|
||||||
newCert() {
|
newCert() {
|
||||||
const randomName = Setting.getRandomName();
|
const randomName = Setting.getRandomName();
|
||||||
|
const owner = Setting.isDefaultOrganizationSelected(this.props.account) ? this.state.owner : Setting.getRequestOrganization(this.props.account);
|
||||||
return {
|
return {
|
||||||
owner: this.state.owner,
|
owner: owner,
|
||||||
name: `cert_${randomName}`,
|
name: `cert_${randomName}`,
|
||||||
createdTime: moment().format(),
|
createdTime: moment().format(),
|
||||||
displayName: `New Cert - ${randomName}`,
|
displayName: `New Cert - ${randomName}`,
|
||||||
@@ -149,6 +151,7 @@ class CertListPage extends BaseListPage {
|
|||||||
filterMultiple: false,
|
filterMultiple: false,
|
||||||
filters: [
|
filters: [
|
||||||
{text: "x509", value: "x509"},
|
{text: "x509", value: "x509"},
|
||||||
|
{text: "Payment", value: "Payment"},
|
||||||
],
|
],
|
||||||
width: "110px",
|
width: "110px",
|
||||||
sorter: true,
|
sorter: true,
|
||||||
@@ -211,7 +214,7 @@ class CertListPage extends BaseListPage {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<Table scroll={{x: "max-content"}} columns={columns} dataSource={certs} rowKey="name" size="middle" bordered pagination={paginationProps}
|
<Table scroll={{x: "max-content"}} columns={columns} dataSource={certs} rowKey={(record) => `${record.owner}/${record.name}`} size="middle" bordered pagination={paginationProps}
|
||||||
title={() => (
|
title={() => (
|
||||||
<div>
|
<div>
|
||||||
{i18next.t("general:Certs")}
|
{i18next.t("general:Certs")}
|
||||||
@@ -236,8 +239,8 @@ class CertListPage extends BaseListPage {
|
|||||||
value = params.type;
|
value = params.type;
|
||||||
}
|
}
|
||||||
this.setState({loading: true});
|
this.setState({loading: true});
|
||||||
(Setting.isAdminUser(this.props.account) ? CertBackend.getGlobleCerts(params.pagination.current, params.pagination.pageSize, field, value, sortField, sortOrder)
|
(Setting.isDefaultOrganizationSelected(this.props.account) ? CertBackend.getGlobleCerts(params.pagination.current, params.pagination.pageSize, field, value, sortField, sortOrder)
|
||||||
: CertBackend.getCerts(this.props.account.owner, params.pagination.current, params.pagination.pageSize, field, value, sortField, sortOrder))
|
: CertBackend.getCerts(Setting.getRequestOrganization(this.props.account), params.pagination.current, params.pagination.pageSize, field, value, sortField, sortOrder))
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
this.setState({
|
this.setState({
|
||||||
loading: false,
|
loading: false,
|
||||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user