mirror of
https://github.com/casdoor/casdoor.git
synced 2025-07-09 09:23:40 +08:00
Compare commits
71 Commits
Author | SHA1 | Date | |
---|---|---|---|
e207fd243b | |||
30b7fd963f | |||
ca314bbfb5 | |||
812c44e070 | |||
78e45d07cf | |||
0856977b92 | |||
a44a4b0300 | |||
4b29dd8c41 | |||
165e2e33e3 | |||
d13a307ad5 | |||
27bd771fed | |||
9f3ee275a8 | |||
fcda64ad7d | |||
d815bf92bd | |||
7867060b71 | |||
8890d1d7c7 | |||
6e6a0a074a | |||
cff3007992 | |||
fe448cbcf4 | |||
2ab25df950 | |||
b895926754 | |||
5bb7a4153f | |||
b7cd598ee8 | |||
b10fb97c92 | |||
b337b908ea | |||
ba9d1e2388 | |||
29ec1d2d9c | |||
84a03f6c8e | |||
56ff06bbea | |||
7e756b8ee2 | |||
19ba37e0c2 | |||
b98ce19211 | |||
37d1a73c0c | |||
727877cf54 | |||
939b416717 | |||
f115843fbb | |||
aa6a4dc74f | |||
462a82a3d5 | |||
262aeba7e2 | |||
61c2fd5412 | |||
d542208eb8 | |||
f818200c95 | |||
5bc2e91344 | |||
295f732b18 | |||
770ae47471 | |||
2ce4f96355 | |||
07ed834b27 | |||
8d686411ee | |||
ce722897f1 | |||
a8381e875b | |||
4c81fd7d16 | |||
25ee4226d3 | |||
9d5b019243 | |||
6bb7b545b4 | |||
25d56ee8d5 | |||
7e5952c804 | |||
80bf29d79a | |||
971e53dfd8 | |||
654b903d7a | |||
2f72e6971b | |||
d4b587b93e | |||
ac7a510949 | |||
d86f3c88c7 | |||
7c77519069 | |||
2bdf467e3a | |||
52b692c8ad | |||
304643736b | |||
b0f572c51a | |||
19d351d157 | |||
d0751bf2fa | |||
290cc60f00 |
18
.github/workflows/build.yml
vendored
18
.github/workflows/build.yml
vendored
@ -125,26 +125,36 @@ jobs:
|
|||||||
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
- name: Set up QEMU
|
||||||
|
uses: docker/setup-qemu-action@v2
|
||||||
|
|
||||||
|
- name: Set up buildx
|
||||||
|
id: buildx
|
||||||
|
uses: docker/setup-buildx-action@v2
|
||||||
|
with:
|
||||||
|
version: latest
|
||||||
|
|
||||||
- name: Log in to Docker Hub
|
- name: Log in to Docker Hub
|
||||||
uses: docker/login-action@v1
|
uses: docker/login-action@v1
|
||||||
if: github.repository == 'casdoor/casdoor' && github.event_name == 'push' &&steps.should_push.outputs.push=='true'
|
if: github.repository == 'casdoor/casdoor' && github.event_name == 'push' && steps.should_push.outputs.push=='true'
|
||||||
with:
|
with:
|
||||||
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
||||||
password: ${{ secrets.DOCKERHUB_PASSWORD }}
|
password: ${{ secrets.DOCKERHUB_PASSWORD }}
|
||||||
|
|
||||||
|
|
||||||
- name: Push to Docker Hub
|
- name: Push to Docker Hub
|
||||||
uses: docker/build-push-action@v2
|
uses: docker/build-push-action@v3
|
||||||
if: github.repository == 'casdoor/casdoor' && github.event_name == 'push' && steps.should_push.outputs.push=='true'
|
if: github.repository == 'casdoor/casdoor' && github.event_name == 'push' && steps.should_push.outputs.push=='true'
|
||||||
with:
|
with:
|
||||||
target: STANDARD
|
target: STANDARD
|
||||||
|
platforms: linux/amd64,linux/arm64
|
||||||
push: true
|
push: true
|
||||||
tags: casbin/casdoor:${{steps.get-current-tag.outputs.tag }},casbin/casdoor:latest
|
tags: casbin/casdoor:${{steps.get-current-tag.outputs.tag }},casbin/casdoor:latest
|
||||||
|
|
||||||
- name: Push All In One Version to Docker Hub
|
- name: Push All In One Version to Docker Hub
|
||||||
uses: docker/build-push-action@v2
|
uses: docker/build-push-action@v3
|
||||||
if: github.repository == 'casdoor/casdoor' && github.event_name == 'push' && steps.should_push.outputs.push=='true'
|
if: github.repository == 'casdoor/casdoor' && github.event_name == 'push' && steps.should_push.outputs.push=='true'
|
||||||
with:
|
with:
|
||||||
target: ALLINONE
|
target: ALLINONE
|
||||||
|
platforms: linux/amd64,linux/arm64
|
||||||
push: true
|
push: true
|
||||||
tags: casbin/casdoor-all-in-one:${{steps.get-current-tag.outputs.tag }},casbin/casdoor-all-in-one:latest
|
tags: casbin/casdoor-all-in-one:${{steps.get-current-tag.outputs.tag }},casbin/casdoor-all-in-one:latest
|
||||||
|
28
Dockerfile
28
Dockerfile
@ -2,7 +2,7 @@ FROM node:16.13.0 AS FRONT
|
|||||||
WORKDIR /web
|
WORKDIR /web
|
||||||
COPY ./web .
|
COPY ./web .
|
||||||
RUN yarn config set registry https://registry.npmmirror.com
|
RUN yarn config set registry https://registry.npmmirror.com
|
||||||
RUN yarn install && yarn run build
|
RUN yarn install --frozen-lockfile --network-timeout 1000000 && yarn run build
|
||||||
|
|
||||||
|
|
||||||
FROM golang:1.17.5 AS BACK
|
FROM golang:1.17.5 AS BACK
|
||||||
@ -13,16 +13,29 @@ RUN ./build.sh
|
|||||||
|
|
||||||
FROM alpine:latest AS STANDARD
|
FROM alpine:latest AS STANDARD
|
||||||
LABEL MAINTAINER="https://casdoor.org/"
|
LABEL MAINTAINER="https://casdoor.org/"
|
||||||
|
ARG USER=casdoor
|
||||||
|
ARG TARGETOS
|
||||||
|
ARG TARGETARCH
|
||||||
|
ENV BUILDX_ARCH="${TARGETOS:-linux}_${TARGETARCH:-amd64}"
|
||||||
|
|
||||||
RUN sed -i 's/https/http/' /etc/apk/repositories
|
RUN sed -i 's/https/http/' /etc/apk/repositories
|
||||||
|
RUN apk add --update sudo
|
||||||
RUN apk add curl
|
RUN apk add curl
|
||||||
RUN apk add ca-certificates && update-ca-certificates
|
RUN apk add ca-certificates && update-ca-certificates
|
||||||
|
|
||||||
|
RUN adduser -D $USER -u 1000 \
|
||||||
|
&& echo "$USER ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers.d/$USER \
|
||||||
|
&& chmod 0440 /etc/sudoers.d/$USER \
|
||||||
|
&& mkdir logs \
|
||||||
|
&& chown -R $USER:$USER logs
|
||||||
|
|
||||||
|
USER 1000
|
||||||
WORKDIR /
|
WORKDIR /
|
||||||
COPY --from=BACK /go/src/casdoor/server ./server
|
COPY --from=BACK --chown=$USER:$USER /go/src/casdoor/server_${BUILDX_ARCH} ./server
|
||||||
COPY --from=BACK /go/src/casdoor/swagger ./swagger
|
COPY --from=BACK --chown=$USER:$USER /go/src/casdoor/swagger ./swagger
|
||||||
COPY --from=BACK /go/src/casdoor/conf/app.conf ./conf/app.conf
|
COPY --from=BACK --chown=$USER:$USER /go/src/casdoor/conf/app.conf ./conf/app.conf
|
||||||
COPY --from=FRONT /web/build ./web/build
|
COPY --from=FRONT --chown=$USER:$USER /web/build ./web/build
|
||||||
|
|
||||||
ENTRYPOINT ["/server"]
|
ENTRYPOINT ["/server"]
|
||||||
|
|
||||||
|
|
||||||
@ -36,12 +49,15 @@ RUN apt update \
|
|||||||
|
|
||||||
FROM db AS ALLINONE
|
FROM db AS ALLINONE
|
||||||
LABEL MAINTAINER="https://casdoor.org/"
|
LABEL MAINTAINER="https://casdoor.org/"
|
||||||
|
ARG TARGETOS
|
||||||
|
ARG TARGETARCH
|
||||||
|
ENV BUILDX_ARCH="${TARGETOS:-linux}_${TARGETARCH:-amd64}"
|
||||||
|
|
||||||
RUN apt update
|
RUN apt update
|
||||||
RUN apt install -y ca-certificates && update-ca-certificates
|
RUN apt install -y ca-certificates && update-ca-certificates
|
||||||
|
|
||||||
WORKDIR /
|
WORKDIR /
|
||||||
COPY --from=BACK /go/src/casdoor/server ./server
|
COPY --from=BACK /go/src/casdoor/server_${BUILDX_ARCH} ./server
|
||||||
COPY --from=BACK /go/src/casdoor/swagger ./swagger
|
COPY --from=BACK /go/src/casdoor/swagger ./swagger
|
||||||
COPY --from=BACK /go/src/casdoor/docker-entrypoint.sh /docker-entrypoint.sh
|
COPY --from=BACK /go/src/casdoor/docker-entrypoint.sh /docker-entrypoint.sh
|
||||||
COPY --from=BACK /go/src/casdoor/conf/app.conf ./conf/app.conf
|
COPY --from=BACK /go/src/casdoor/conf/app.conf ./conf/app.conf
|
||||||
|
@ -32,7 +32,9 @@ func InitAuthz() {
|
|||||||
var err error
|
var err error
|
||||||
|
|
||||||
tableNamePrefix := conf.GetConfigString("tableNamePrefix")
|
tableNamePrefix := conf.GetConfigString("tableNamePrefix")
|
||||||
a, err := xormadapter.NewAdapterWithTableName(conf.GetConfigString("driverName"), conf.GetConfigDataSourceName()+conf.GetConfigString("dbName"), "casbin_rule", tableNamePrefix, true)
|
driverName := conf.GetConfigString("driverName")
|
||||||
|
dataSourceName := conf.GetConfigRealDataSourceName(driverName)
|
||||||
|
a, err := xormadapter.NewAdapterWithTableName(driverName, dataSourceName, "casbin_rule", tableNamePrefix, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
@ -85,6 +87,8 @@ p, *, *, POST, /api/logout, *, *
|
|||||||
p, *, *, GET, /api/logout, *, *
|
p, *, *, GET, /api/logout, *, *
|
||||||
p, *, *, GET, /api/get-account, *, *
|
p, *, *, GET, /api/get-account, *, *
|
||||||
p, *, *, GET, /api/userinfo, *, *
|
p, *, *, GET, /api/userinfo, *, *
|
||||||
|
p, *, *, POST, /api/webhook, *, *
|
||||||
|
p, *, *, GET, /api/get-webhook-event, *, *
|
||||||
p, *, *, *, /api/login/oauth, *, *
|
p, *, *, *, /api/login/oauth, *, *
|
||||||
p, *, *, GET, /api/get-application, *, *
|
p, *, *, GET, /api/get-application, *, *
|
||||||
p, *, *, GET, /api/get-organization-applications, *, *
|
p, *, *, GET, /api/get-organization-applications, *, *
|
||||||
@ -142,7 +146,7 @@ func IsAllowed(subOwner string, subName string, method string, urlPath string, o
|
|||||||
|
|
||||||
userId := fmt.Sprintf("%s/%s", subOwner, subName)
|
userId := fmt.Sprintf("%s/%s", subOwner, subName)
|
||||||
user := object.GetUser(userId)
|
user := object.GetUser(userId)
|
||||||
if user != nil && user.IsAdmin && subOwner == objOwner {
|
if user != nil && user.IsAdmin && (subOwner == objOwner || (objOwner == "admin" && subOwner == objName)) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
3
build.sh
3
build.sh
@ -8,4 +8,5 @@ else
|
|||||||
echo "Google is blocked, Go proxy is enabled: GOPROXY=https://goproxy.cn,direct"
|
echo "Google is blocked, Go proxy is enabled: GOPROXY=https://goproxy.cn,direct"
|
||||||
export GOPROXY="https://goproxy.cn,direct"
|
export GOPROXY="https://goproxy.cn,direct"
|
||||||
fi
|
fi
|
||||||
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="-w -s" -o server .
|
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="-w -s" -o server_linux_amd64 .
|
||||||
|
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -ldflags="-w -s" -o server_linux_arm64 .
|
||||||
|
@ -14,6 +14,8 @@
|
|||||||
|
|
||||||
package captcha
|
package captcha
|
||||||
|
|
||||||
|
import "fmt"
|
||||||
|
|
||||||
type CaptchaProvider interface {
|
type CaptchaProvider interface {
|
||||||
VerifyCaptcha(token, clientSecret string) (bool, error)
|
VerifyCaptcha(token, clientSecret string) (bool, error)
|
||||||
}
|
}
|
||||||
@ -29,6 +31,17 @@ func GetCaptchaProvider(captchaType string) CaptchaProvider {
|
|||||||
return NewAliyunCaptchaProvider()
|
return NewAliyunCaptchaProvider()
|
||||||
} else if captchaType == "GEETEST" {
|
} else if captchaType == "GEETEST" {
|
||||||
return NewGEETESTCaptchaProvider()
|
return NewGEETESTCaptchaProvider()
|
||||||
|
} else if captchaType == "Cloudflare Turnstile" {
|
||||||
|
return NewCloudflareTurnstileProvider()
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func VerifyCaptchaByCaptchaType(captchaType, token, clientSecret string) (bool, error) {
|
||||||
|
provider := GetCaptchaProvider(captchaType)
|
||||||
|
if provider == nil {
|
||||||
|
return false, fmt.Errorf("invalid captcha provider: %s", captchaType)
|
||||||
|
}
|
||||||
|
|
||||||
|
return provider.VerifyCaptcha(token, clientSecret)
|
||||||
|
}
|
||||||
|
66
captcha/turnstile.go
Normal file
66
captcha/turnstile.go
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
// Copyright 2022 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 captcha
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
|
"io"
|
||||||
|
"net/http"
|
||||||
|
"net/url"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
const CloudflareTurnstileVerifyUrl = "https://challenges.cloudflare.com/turnstile/v0/siteverify"
|
||||||
|
|
||||||
|
type CloudflareTurnstileProvider struct{}
|
||||||
|
|
||||||
|
func NewCloudflareTurnstileProvider() *CloudflareTurnstileProvider {
|
||||||
|
captcha := &CloudflareTurnstileProvider{}
|
||||||
|
return captcha
|
||||||
|
}
|
||||||
|
|
||||||
|
func (captcha *CloudflareTurnstileProvider) VerifyCaptcha(token, clientSecret string) (bool, error) {
|
||||||
|
reqData := url.Values{
|
||||||
|
"secret": {clientSecret},
|
||||||
|
"response": {token},
|
||||||
|
}
|
||||||
|
resp, err := http.PostForm(CloudflareTurnstileVerifyUrl, reqData)
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
|
||||||
|
defer resp.Body.Close()
|
||||||
|
body, err := io.ReadAll(resp.Body)
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
|
||||||
|
type captchaResponse struct {
|
||||||
|
Success bool `json:"success"`
|
||||||
|
ErrorCodes []string `json:"error-codes"`
|
||||||
|
}
|
||||||
|
captchaResp := &captchaResponse{}
|
||||||
|
err = json.Unmarshal(body, captchaResp)
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(captchaResp.ErrorCodes) > 0 {
|
||||||
|
return false, errors.New(strings.Join(captchaResp.ErrorCodes, ","))
|
||||||
|
}
|
||||||
|
|
||||||
|
return captchaResp.Success, nil
|
||||||
|
}
|
@ -20,3 +20,5 @@ staticBaseUrl = "https://cdn.casbin.org"
|
|||||||
isDemoMode = false
|
isDemoMode = false
|
||||||
batchSize = 100
|
batchSize = 100
|
||||||
ldapServerPort = 389
|
ldapServerPort = 389
|
||||||
|
languages = en,zh,es,fr,de,ja,ko,ru
|
||||||
|
quota = {"organization": -1, "user": -1, "application": -1, "provider": -1}
|
||||||
|
35
conf/conf.go
35
conf/conf.go
@ -15,6 +15,7 @@
|
|||||||
package conf
|
package conf
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"runtime"
|
"runtime"
|
||||||
@ -24,6 +25,15 @@ import (
|
|||||||
"github.com/beego/beego"
|
"github.com/beego/beego"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type Quota struct {
|
||||||
|
Organization int `json:"organization"`
|
||||||
|
User int `json:"user"`
|
||||||
|
Application int `json:"application"`
|
||||||
|
Provider int `json:"provider"`
|
||||||
|
}
|
||||||
|
|
||||||
|
var quota = &Quota{-1, -1, -1, -1}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
// this array contains the beego configuration items that may be modified via env
|
// this array contains the beego configuration items that may be modified via env
|
||||||
presetConfigItems := []string{"httpport", "appname"}
|
presetConfigItems := []string{"httpport", "appname"}
|
||||||
@ -35,6 +45,17 @@ func init() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
initQuota()
|
||||||
|
}
|
||||||
|
|
||||||
|
func initQuota() {
|
||||||
|
res := beego.AppConfig.String("quota")
|
||||||
|
if res != "" {
|
||||||
|
err := json.Unmarshal([]byte(res), quota)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetConfigString(key string) string {
|
func GetConfigString(key string) string {
|
||||||
@ -95,3 +116,17 @@ func GetConfigBatchSize() int {
|
|||||||
}
|
}
|
||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GetConfigQuota() *Quota {
|
||||||
|
return quota
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetConfigRealDataSourceName(driverName string) string {
|
||||||
|
var dataSourceName string
|
||||||
|
if driverName != "mysql" {
|
||||||
|
dataSourceName = GetConfigDataSourceName()
|
||||||
|
} else {
|
||||||
|
dataSourceName = GetConfigDataSourceName() + GetConfigString("dbName")
|
||||||
|
}
|
||||||
|
return dataSourceName
|
||||||
|
}
|
||||||
|
@ -93,3 +93,19 @@ func TestGetConfBool(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestGetConfigQuota(t *testing.T) {
|
||||||
|
scenarios := []struct {
|
||||||
|
description string
|
||||||
|
expected *Quota
|
||||||
|
}{
|
||||||
|
{"default", &Quota{-1, -1, -1, -1}},
|
||||||
|
}
|
||||||
|
|
||||||
|
err := beego.LoadAppConfig("ini", "app.conf")
|
||||||
|
assert.Nil(t, err)
|
||||||
|
for _, scenery := range scenarios {
|
||||||
|
quota := GetConfigQuota()
|
||||||
|
assert.Equal(t, scenery.expected, quota)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -64,6 +64,10 @@ type RequestForm struct {
|
|||||||
RelayState string `json:"relayState"`
|
RelayState string `json:"relayState"`
|
||||||
SamlRequest string `json:"samlRequest"`
|
SamlRequest string `json:"samlRequest"`
|
||||||
SamlResponse string `json:"samlResponse"`
|
SamlResponse string `json:"samlResponse"`
|
||||||
|
|
||||||
|
CaptchaType string `json:"captchaType"`
|
||||||
|
CaptchaToken string `json:"captchaToken"`
|
||||||
|
ClientSecret string `json:"clientSecret"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Response struct {
|
type Response struct {
|
||||||
@ -98,7 +102,7 @@ type Captcha struct {
|
|||||||
// @router /signup [post]
|
// @router /signup [post]
|
||||||
func (c *ApiController) Signup() {
|
func (c *ApiController) Signup() {
|
||||||
if c.GetSessionUsername() != "" {
|
if c.GetSessionUsername() != "" {
|
||||||
c.ResponseError("Please sign out first before signing up", c.GetSessionUsername())
|
c.ResponseError(c.T("SignUpErr.SignOutFirst"), c.GetSessionUsername())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -111,21 +115,21 @@ func (c *ApiController) Signup() {
|
|||||||
|
|
||||||
application := object.GetApplication(fmt.Sprintf("admin/%s", form.Application))
|
application := object.GetApplication(fmt.Sprintf("admin/%s", form.Application))
|
||||||
if !application.EnableSignUp {
|
if !application.EnableSignUp {
|
||||||
c.ResponseError("The application does not allow to sign up new account")
|
c.ResponseError(c.T("SignUpErr.DoNotAllowSignUp"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
organization := object.GetOrganization(fmt.Sprintf("%s/%s", "admin", form.Organization))
|
organization := object.GetOrganization(fmt.Sprintf("%s/%s", "admin", form.Organization))
|
||||||
msg := object.CheckUserSignup(application, organization, form.Username, form.Password, form.Name, form.FirstName, form.LastName, form.Email, form.Phone, form.Affiliation)
|
msg := object.CheckUserSignup(application, organization, form.Username, form.Password, form.Name, form.FirstName, form.LastName, form.Email, form.Phone, form.Affiliation, c.GetAcceptLanguage())
|
||||||
if msg != "" {
|
if msg != "" {
|
||||||
c.ResponseError(msg)
|
c.ResponseError(msg)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if application.IsSignupItemVisible("Email") && application.GetSignupItemRule("Email") != "No verification" && form.Email != "" {
|
if application.IsSignupItemVisible("Email") && application.GetSignupItemRule("Email") != "No verification" && form.Email != "" {
|
||||||
checkResult := object.CheckVerificationCode(form.Email, form.EmailCode)
|
checkResult := object.CheckVerificationCode(form.Email, form.EmailCode, c.GetAcceptLanguage())
|
||||||
if len(checkResult) != 0 {
|
if len(checkResult) != 0 {
|
||||||
c.ResponseError(fmt.Sprintf("Email: %s", checkResult))
|
c.ResponseError(c.T("EmailErr.EmailCheckResult"), checkResult)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -133,9 +137,9 @@ func (c *ApiController) Signup() {
|
|||||||
var checkPhone string
|
var checkPhone string
|
||||||
if application.IsSignupItemVisible("Phone") && form.Phone != "" {
|
if application.IsSignupItemVisible("Phone") && form.Phone != "" {
|
||||||
checkPhone = fmt.Sprintf("+%s%s", form.PhonePrefix, form.Phone)
|
checkPhone = fmt.Sprintf("+%s%s", form.PhonePrefix, form.Phone)
|
||||||
checkResult := object.CheckVerificationCode(checkPhone, form.PhoneCode)
|
checkResult := object.CheckVerificationCode(checkPhone, form.PhoneCode, c.GetAcceptLanguage())
|
||||||
if len(checkResult) != 0 {
|
if len(checkResult) != 0 {
|
||||||
c.ResponseError(fmt.Sprintf("Phone: %s", checkResult))
|
c.ResponseError(c.T("PhoneErr.PhoneCheckResult"), checkResult)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -159,7 +163,7 @@ func (c *ApiController) Signup() {
|
|||||||
|
|
||||||
initScore, err := getInitScore()
|
initScore, err := getInitScore()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.ResponseError(fmt.Errorf("get init score failed, error: %w", err).Error())
|
c.ResponseError(fmt.Errorf(c.T("InitErr.InitScoreFailed"), err).Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -205,7 +209,7 @@ func (c *ApiController) Signup() {
|
|||||||
|
|
||||||
affected := object.AddUser(user)
|
affected := object.AddUser(user)
|
||||||
if !affected {
|
if !affected {
|
||||||
c.ResponseError(fmt.Sprintf("Failed to create user, user information is invalid: %s", util.StructToJson(user)))
|
c.ResponseError(c.T("UserErr.InvalidInformation"), util.StructToJson(user))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -241,8 +245,7 @@ func (c *ApiController) Logout() {
|
|||||||
util.LogInfo(c.Ctx, "API: [%s] logged out", user)
|
util.LogInfo(c.Ctx, "API: [%s] logged out", user)
|
||||||
|
|
||||||
application := c.GetSessionApplication()
|
application := c.GetSessionApplication()
|
||||||
c.SetSessionUsername("")
|
c.ClearUserSession()
|
||||||
c.SetSessionData(nil)
|
|
||||||
|
|
||||||
if application == nil || application.Name == "app-built-in" || application.HomepageUrl == "" {
|
if application == nil || application.Name == "app-built-in" || application.HomepageUrl == "" {
|
||||||
c.ResponseOk(user)
|
c.ResponseOk(user)
|
||||||
@ -309,7 +312,7 @@ func (c *ApiController) GetCaptcha() {
|
|||||||
applicationId := c.Input().Get("applicationId")
|
applicationId := c.Input().Get("applicationId")
|
||||||
isCurrentProvider := c.Input().Get("isCurrentProvider")
|
isCurrentProvider := c.Input().Get("isCurrentProvider")
|
||||||
|
|
||||||
captchaProvider, err := object.GetCaptchaProviderByApplication(applicationId, isCurrentProvider)
|
captchaProvider, err := object.GetCaptchaProviderByApplication(applicationId, isCurrentProvider, c.GetAcceptLanguage())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.ResponseError(err.Error())
|
c.ResponseError(err.Error())
|
||||||
return
|
return
|
||||||
|
@ -46,7 +46,7 @@ func (c *ApiController) GetApplications() {
|
|||||||
if organization == "" {
|
if organization == "" {
|
||||||
applications = object.GetApplications(owner)
|
applications = object.GetApplications(owner)
|
||||||
} else {
|
} else {
|
||||||
applications = object.GetApplicationsByOrganizationName(owner, organization)
|
applications = object.GetOrganizationApplications(owner, organization)
|
||||||
}
|
}
|
||||||
|
|
||||||
c.Data["json"] = object.GetMaskedApplications(applications, userId)
|
c.Data["json"] = object.GetMaskedApplications(applications, userId)
|
||||||
@ -86,7 +86,7 @@ func (c *ApiController) GetUserApplication() {
|
|||||||
id := c.Input().Get("id")
|
id := c.Input().Get("id")
|
||||||
user := object.GetUser(id)
|
user := object.GetUser(id)
|
||||||
if user == nil {
|
if user == nil {
|
||||||
c.ResponseError(fmt.Sprintf("The user: %s doesn't exist", id))
|
c.ResponseError(fmt.Sprintf(c.T("UserErr.DoNotExist"), id))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -103,17 +103,31 @@ func (c *ApiController) GetUserApplication() {
|
|||||||
// @router /get-organization-applications [get]
|
// @router /get-organization-applications [get]
|
||||||
func (c *ApiController) GetOrganizationApplications() {
|
func (c *ApiController) GetOrganizationApplications() {
|
||||||
userId := c.GetSessionUsername()
|
userId := c.GetSessionUsername()
|
||||||
owner := c.Input().Get("owner")
|
|
||||||
organization := c.Input().Get("organization")
|
organization := c.Input().Get("organization")
|
||||||
|
owner := c.Input().Get("owner")
|
||||||
|
limit := c.Input().Get("pageSize")
|
||||||
|
page := c.Input().Get("p")
|
||||||
|
field := c.Input().Get("field")
|
||||||
|
value := c.Input().Get("value")
|
||||||
|
sortField := c.Input().Get("sortField")
|
||||||
|
sortOrder := c.Input().Get("sortOrder")
|
||||||
|
|
||||||
if organization == "" {
|
if organization == "" {
|
||||||
c.ResponseError("Parameter organization is missing")
|
c.ResponseError(c.T("ParameterErr.OrgMissingErr"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
applications := object.GetApplicationsByOrganizationName(owner, organization)
|
if limit == "" || page == "" {
|
||||||
c.Data["json"] = object.GetMaskedApplications(applications, userId)
|
var applications []*object.Application
|
||||||
c.ServeJSON()
|
applications = object.GetOrganizationApplications(owner, organization)
|
||||||
|
c.Data["json"] = object.GetMaskedApplications(applications, userId)
|
||||||
|
c.ServeJSON()
|
||||||
|
} else {
|
||||||
|
limit := util.ParseInt(limit)
|
||||||
|
paginator := pagination.SetPaginator(c.Ctx, limit, int64(object.GetOrganizationApplicationCount(owner, organization, field, value)))
|
||||||
|
applications := object.GetMaskedApplications(object.GetPaginationOrganizationApplications(owner, organization, paginator.Offset(), limit, field, value, sortField, sortOrder), userId)
|
||||||
|
c.ResponseOk(applications, paginator.Nums())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// UpdateApplication
|
// UpdateApplication
|
||||||
@ -153,6 +167,12 @@ func (c *ApiController) AddApplication() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
count := object.GetApplicationCount("", "", "")
|
||||||
|
if err := checkQuotaForApplication(count); err != nil {
|
||||||
|
c.ResponseError(err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
c.Data["json"] = wrapActionResponse(object.AddApplication(&application))
|
c.Data["json"] = wrapActionResponse(object.AddApplication(&application))
|
||||||
c.ServeJSON()
|
c.ServeJSON()
|
||||||
}
|
}
|
||||||
|
@ -17,12 +17,16 @@ package controllers
|
|||||||
import (
|
import (
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"encoding/xml"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io/ioutil"
|
||||||
"net/url"
|
"net/url"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/casdoor/casdoor/captcha"
|
||||||
"github.com/casdoor/casdoor/conf"
|
"github.com/casdoor/casdoor/conf"
|
||||||
"github.com/casdoor/casdoor/idp"
|
"github.com/casdoor/casdoor/idp"
|
||||||
"github.com/casdoor/casdoor/object"
|
"github.com/casdoor/casdoor/object"
|
||||||
@ -31,6 +35,11 @@ import (
|
|||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
wechatScanType string
|
||||||
|
lock sync.RWMutex
|
||||||
|
)
|
||||||
|
|
||||||
func codeToResponse(code *object.Code) *Response {
|
func codeToResponse(code *object.Code) *Response {
|
||||||
if code.Code == "" {
|
if code.Code == "" {
|
||||||
return &Response{Status: "error", Msg: code.Message, Data: code.Code}
|
return &Response{Status: "error", Msg: code.Message, Data: code.Code}
|
||||||
@ -56,7 +65,7 @@ func (c *ApiController) HandleLoggedIn(application *object.Application, user *ob
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
if !allowed {
|
if !allowed {
|
||||||
c.ResponseError("Unauthorized operation")
|
c.ResponseError(c.T("AuthErr.Unauthorized"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -75,10 +84,10 @@ func (c *ApiController) HandleLoggedIn(application *object.Application, user *ob
|
|||||||
codeChallenge := c.Input().Get("code_challenge")
|
codeChallenge := c.Input().Get("code_challenge")
|
||||||
|
|
||||||
if challengeMethod != "S256" && challengeMethod != "null" && challengeMethod != "" {
|
if challengeMethod != "S256" && challengeMethod != "null" && challengeMethod != "" {
|
||||||
c.ResponseError("Challenge method should be S256")
|
c.ResponseError(c.T("AuthErr.ChallengeMethodErr"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
code := object.GetOAuthCode(userId, clientId, responseType, redirectUri, scope, state, nonce, codeChallenge, c.Ctx.Request.Host)
|
code := object.GetOAuthCode(userId, clientId, responseType, redirectUri, scope, state, nonce, codeChallenge, c.Ctx.Request.Host, c.GetAcceptLanguage())
|
||||||
resp = codeToResponse(code)
|
resp = codeToResponse(code)
|
||||||
|
|
||||||
if application.EnableSigninSession || application.HasPromptPage() {
|
if application.EnableSigninSession || application.HasPromptPage() {
|
||||||
@ -151,7 +160,7 @@ func (c *ApiController) GetApplicationLogin() {
|
|||||||
scope := c.Input().Get("scope")
|
scope := c.Input().Get("scope")
|
||||||
state := c.Input().Get("state")
|
state := c.Input().Get("state")
|
||||||
|
|
||||||
msg, application := object.CheckOAuthLogin(clientId, responseType, redirectUri, scope, state)
|
msg, application := object.CheckOAuthLogin(clientId, responseType, redirectUri, scope, state, c.GetAcceptLanguage())
|
||||||
application = object.GetMaskedApplication(application, "")
|
application = object.GetMaskedApplication(application, "")
|
||||||
if msg != "" {
|
if msg != "" {
|
||||||
c.ResponseError(msg, application)
|
c.ResponseError(msg, application)
|
||||||
@ -196,7 +205,7 @@ func (c *ApiController) Login() {
|
|||||||
if form.Username != "" {
|
if form.Username != "" {
|
||||||
if form.Type == ResponseTypeLogin {
|
if form.Type == ResponseTypeLogin {
|
||||||
if c.GetSessionUsername() != "" {
|
if c.GetSessionUsername() != "" {
|
||||||
c.ResponseError("Please sign out first before signing in", c.GetSessionUsername())
|
c.ResponseError(c.T("LoginErr.SignOutFirst"), c.GetSessionUsername())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -218,11 +227,11 @@ func (c *ApiController) Login() {
|
|||||||
if user != nil && util.GetMaskedEmail(user.Email) == form.Username {
|
if user != nil && util.GetMaskedEmail(user.Email) == form.Username {
|
||||||
form.Username = user.Email
|
form.Username = user.Email
|
||||||
}
|
}
|
||||||
checkResult = object.CheckVerificationCode(form.Username, form.Code)
|
checkResult = object.CheckVerificationCode(form.Username, form.Code, c.GetAcceptLanguage())
|
||||||
} else {
|
} else {
|
||||||
verificationCodeType = "phone"
|
verificationCodeType = "phone"
|
||||||
if len(form.PhonePrefix) == 0 {
|
if len(form.PhonePrefix) == 0 {
|
||||||
responseText := fmt.Sprintf("%s%s", verificationCodeType, "No phone prefix")
|
responseText := fmt.Sprintf(c.T("PhoneErr.NoPrefix"), verificationCodeType)
|
||||||
c.ResponseError(responseText)
|
c.ResponseError(responseText)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -230,7 +239,7 @@ func (c *ApiController) Login() {
|
|||||||
form.Username = user.Phone
|
form.Username = user.Phone
|
||||||
}
|
}
|
||||||
checkPhone := fmt.Sprintf("+%s%s", form.PhonePrefix, form.Username)
|
checkPhone := fmt.Sprintf("+%s%s", form.PhonePrefix, form.Username)
|
||||||
checkResult = object.CheckVerificationCode(checkPhone, form.Code)
|
checkResult = object.CheckVerificationCode(checkPhone, form.Code, c.GetAcceptLanguage())
|
||||||
}
|
}
|
||||||
if len(checkResult) != 0 {
|
if len(checkResult) != 0 {
|
||||||
responseText := fmt.Sprintf("%s%s", verificationCodeType, checkResult)
|
responseText := fmt.Sprintf("%s%s", verificationCodeType, checkResult)
|
||||||
@ -247,12 +256,31 @@ func (c *ApiController) Login() {
|
|||||||
|
|
||||||
user = object.GetUserByFields(form.Organization, form.Username)
|
user = object.GetUserByFields(form.Organization, form.Username)
|
||||||
if user == nil {
|
if user == nil {
|
||||||
c.ResponseError(fmt.Sprintf("The user: %s/%s doesn't exist", form.Organization, form.Username))
|
c.ResponseError(fmt.Sprintf(c.T("LoginErr.UserDoNotExist"), form.Organization, form.Username))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
application := object.GetApplication(fmt.Sprintf("admin/%s", form.Application))
|
||||||
|
if application == nil {
|
||||||
|
c.ResponseError(fmt.Sprintf("The application: %s does not exist", form.Application))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if object.CheckToEnableCaptcha(application) {
|
||||||
|
isHuman, err := captcha.VerifyCaptchaByCaptchaType(form.CaptchaType, form.CaptchaToken, form.ClientSecret)
|
||||||
|
if err != nil {
|
||||||
|
c.ResponseError(err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if !isHuman {
|
||||||
|
c.ResponseError("Turing test failed.")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
password := form.Password
|
password := form.Password
|
||||||
user, msg = object.CheckUserPassword(form.Organization, form.Username, password)
|
user, msg = object.CheckUserPassword(form.Organization, form.Username, password, c.GetAcceptLanguage())
|
||||||
}
|
}
|
||||||
|
|
||||||
if msg != "" {
|
if msg != "" {
|
||||||
@ -260,7 +288,7 @@ func (c *ApiController) Login() {
|
|||||||
} else {
|
} else {
|
||||||
application := object.GetApplication(fmt.Sprintf("admin/%s", form.Application))
|
application := object.GetApplication(fmt.Sprintf("admin/%s", form.Application))
|
||||||
if application == nil {
|
if application == nil {
|
||||||
c.ResponseError(fmt.Sprintf("The application: %s does not exist", form.Application))
|
c.ResponseError(fmt.Sprintf(c.T("LoginErr.AppDoNotExist"), form.Application))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -274,15 +302,15 @@ func (c *ApiController) Login() {
|
|||||||
} else if form.Provider != "" {
|
} else if form.Provider != "" {
|
||||||
application := object.GetApplication(fmt.Sprintf("admin/%s", form.Application))
|
application := object.GetApplication(fmt.Sprintf("admin/%s", form.Application))
|
||||||
if application == nil {
|
if application == nil {
|
||||||
c.ResponseError(fmt.Sprintf("The application: %s does not exist", form.Application))
|
c.ResponseError(fmt.Sprintf(c.T("LoginErr.AppDoNotExist"), form.Application))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
organization := object.GetOrganization(fmt.Sprintf("%s/%s", "admin", application.Organization))
|
organization := object.GetOrganization(fmt.Sprintf("%s/%s", "admin", application.Organization))
|
||||||
provider := object.GetProvider(fmt.Sprintf("admin/%s", form.Provider))
|
provider := object.GetProvider(util.GetId("admin", form.Provider))
|
||||||
providerItem := application.GetProviderItem(provider.Name)
|
providerItem := application.GetProviderItem(provider.Name)
|
||||||
if !providerItem.IsProviderVisible() {
|
if !providerItem.IsProviderVisible() {
|
||||||
c.ResponseError(fmt.Sprintf("The provider: %s is not enabled for the application", provider.Name))
|
c.ResponseError(fmt.Sprintf(c.T("ProviderErr.ProviderNotEnabled"), provider.Name))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -306,14 +334,14 @@ func (c *ApiController) Login() {
|
|||||||
|
|
||||||
idProvider := idp.GetIdProvider(provider.Type, provider.SubType, clientId, clientSecret, provider.AppId, form.RedirectUri, provider.Domain, provider.CustomAuthUrl, provider.CustomTokenUrl, provider.CustomUserInfoUrl)
|
idProvider := idp.GetIdProvider(provider.Type, provider.SubType, clientId, clientSecret, provider.AppId, form.RedirectUri, provider.Domain, provider.CustomAuthUrl, provider.CustomTokenUrl, provider.CustomUserInfoUrl)
|
||||||
if idProvider == nil {
|
if idProvider == nil {
|
||||||
c.ResponseError(fmt.Sprintf("The provider type: %s is not supported", provider.Type))
|
c.ResponseError(fmt.Sprintf(c.T("ProviderErr.ProviderNotSupported"), provider.Type))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
setHttpClient(idProvider, provider.Type)
|
setHttpClient(idProvider, provider.Type)
|
||||||
|
|
||||||
if form.State != conf.GetConfigString("authState") && form.State != application.Name {
|
if form.State != conf.GetConfigString("authState") && form.State != application.Name {
|
||||||
c.ResponseError(fmt.Sprintf("state expected: \"%s\", but got: \"%s\"", conf.GetConfigString("authState"), form.State))
|
c.ResponseError(fmt.Sprintf(c.T("AuthErr.AuthStateWrong"), conf.GetConfigString("authState"), form.State))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -325,13 +353,13 @@ func (c *ApiController) Login() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if !token.Valid() {
|
if !token.Valid() {
|
||||||
c.ResponseError("Invalid token")
|
c.ResponseError(c.T("TokenErr.InvalidToken"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
userInfo, err = idProvider.GetUserInfo(token)
|
userInfo, err = idProvider.GetUserInfo(token)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.ResponseError(fmt.Sprintf("Failed to login in: %s", err.Error()))
|
c.ResponseError(fmt.Sprintf(c.T("LoginErr.LoginFail"), err.Error()))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -348,7 +376,7 @@ func (c *ApiController) Login() {
|
|||||||
// Sign in via OAuth (want to sign up but already have account)
|
// Sign in via OAuth (want to sign up but already have account)
|
||||||
|
|
||||||
if user.IsForbidden {
|
if user.IsForbidden {
|
||||||
c.ResponseError("the user is forbidden to sign in, please contact the administrator")
|
c.ResponseError(c.T("LoginErr.UserIsForbidden"))
|
||||||
}
|
}
|
||||||
|
|
||||||
resp = c.HandleLoggedIn(application, user, &form)
|
resp = c.HandleLoggedIn(application, user, &form)
|
||||||
@ -360,12 +388,12 @@ func (c *ApiController) Login() {
|
|||||||
} else if provider.Category == "OAuth" {
|
} else if provider.Category == "OAuth" {
|
||||||
// Sign up via OAuth
|
// Sign up via OAuth
|
||||||
if !application.EnableSignUp {
|
if !application.EnableSignUp {
|
||||||
c.ResponseError(fmt.Sprintf("The account for provider: %s and username: %s (%s) does not exist and is not allowed to sign up as new account, please contact your IT support", provider.Type, userInfo.Username, userInfo.DisplayName))
|
c.ResponseError(fmt.Sprintf(c.T("LoginErr.AppNotEnableSignUp"), provider.Type, userInfo.Username, userInfo.DisplayName))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if !providerItem.CanSignUp {
|
if !providerItem.CanSignUp {
|
||||||
c.ResponseError(fmt.Sprintf("The account for provider: %s and username: %s (%s) does not exist and is not allowed to sign up as new account via %s, please use another way to sign up", provider.Type, userInfo.Username, userInfo.DisplayName, provider.Type))
|
c.ResponseError(fmt.Sprintf(c.T("LoginErr.ProviderCanNotSignUp"), provider.Type, userInfo.Username, userInfo.DisplayName, provider.Type))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -386,7 +414,7 @@ func (c *ApiController) Login() {
|
|||||||
properties["no"] = strconv.Itoa(len(object.GetUsers(application.Organization)) + 2)
|
properties["no"] = strconv.Itoa(len(object.GetUsers(application.Organization)) + 2)
|
||||||
initScore, err := getInitScore()
|
initScore, err := getInitScore()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.ResponseError(fmt.Errorf("get init score failed, error: %w", err).Error())
|
c.ResponseError(fmt.Errorf(c.T("InitErr.InitScoreFailed"), err).Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -413,7 +441,7 @@ func (c *ApiController) Login() {
|
|||||||
|
|
||||||
affected := object.AddUser(user)
|
affected := object.AddUser(user)
|
||||||
if !affected {
|
if !affected {
|
||||||
c.ResponseError(fmt.Sprintf("Failed to create user, user information is invalid: %s", util.StructToJson(user)))
|
c.ResponseError(fmt.Sprintf(c.T("LoginErr.InvalidUserInformation"), util.StructToJson(user)))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -438,13 +466,13 @@ func (c *ApiController) Login() {
|
|||||||
} else { // form.Method != "signup"
|
} else { // form.Method != "signup"
|
||||||
userId := c.GetSessionUsername()
|
userId := c.GetSessionUsername()
|
||||||
if userId == "" {
|
if userId == "" {
|
||||||
c.ResponseError("The account does not exist", userInfo)
|
c.ResponseError(c.T("LoginErr.AccountDoNotExist"), userInfo)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
oldUser := object.GetUserByField(application.Organization, provider.Type, userInfo.Id)
|
oldUser := object.GetUserByField(application.Organization, provider.Type, userInfo.Id)
|
||||||
if oldUser != nil {
|
if oldUser != nil {
|
||||||
c.ResponseError(fmt.Sprintf("The account for provider: %s and username: %s (%s) is already linked to another account: %s (%s)", provider.Type, userInfo.Username, userInfo.DisplayName, oldUser.Name, oldUser.DisplayName))
|
c.ResponseError(fmt.Sprintf(c.T("LoginErr.OldUser"), provider.Type, userInfo.Username, userInfo.DisplayName, oldUser.Name, oldUser.DisplayName))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -465,7 +493,7 @@ func (c *ApiController) Login() {
|
|||||||
// user already signed in to Casdoor, so let the user click the avatar button to do the quick sign-in
|
// user already signed in to Casdoor, so let the user click the avatar button to do the quick sign-in
|
||||||
application := object.GetApplication(fmt.Sprintf("admin/%s", form.Application))
|
application := object.GetApplication(fmt.Sprintf("admin/%s", form.Application))
|
||||||
if application == nil {
|
if application == nil {
|
||||||
c.ResponseError(fmt.Sprintf("The application: %s does not exist", form.Application))
|
c.ResponseError(fmt.Sprintf(c.T("LoginErr.AppDoNotExist"), form.Application))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -477,7 +505,7 @@ func (c *ApiController) Login() {
|
|||||||
record.User = user.Name
|
record.User = user.Name
|
||||||
util.SafeGoroutine(func() { object.AddRecord(record) })
|
util.SafeGoroutine(func() { object.AddRecord(record) })
|
||||||
} else {
|
} else {
|
||||||
c.ResponseError(fmt.Sprintf("unknown authentication type (not password or provider), form = %s", util.StructToJson(form)))
|
c.ResponseError(fmt.Sprintf(c.T("LoginErr.UnknownAuthentication"), util.StructToJson(form)))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -489,7 +517,7 @@ func (c *ApiController) Login() {
|
|||||||
func (c *ApiController) GetSamlLogin() {
|
func (c *ApiController) GetSamlLogin() {
|
||||||
providerId := c.Input().Get("id")
|
providerId := c.Input().Get("id")
|
||||||
relayState := c.Input().Get("relayState")
|
relayState := c.Input().Get("relayState")
|
||||||
authURL, method, err := object.GenerateSamlLoginUrl(providerId, relayState)
|
authURL, method, err := object.GenerateSamlLoginUrl(providerId, relayState, c.GetAcceptLanguage())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.ResponseError(err.Error())
|
c.ResponseError(err.Error())
|
||||||
}
|
}
|
||||||
@ -510,3 +538,46 @@ func (c *ApiController) HandleSamlLogin() {
|
|||||||
slice[4], relayState, samlResponse)
|
slice[4], relayState, samlResponse)
|
||||||
c.Redirect(targetUrl, 303)
|
c.Redirect(targetUrl, 303)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// HandleOfficialAccountEvent ...
|
||||||
|
// @Tag HandleOfficialAccountEvent API
|
||||||
|
// @Title HandleOfficialAccountEvent
|
||||||
|
// @router /api/webhook [POST]
|
||||||
|
func (c *ApiController) HandleOfficialAccountEvent() {
|
||||||
|
respBytes, err := ioutil.ReadAll(c.Ctx.Request.Body)
|
||||||
|
if err != nil {
|
||||||
|
c.ResponseError(err.Error())
|
||||||
|
}
|
||||||
|
var data struct {
|
||||||
|
MsgType string `xml:"MsgType"`
|
||||||
|
Event string `xml:"Event"`
|
||||||
|
EventKey string `xml:"EventKey"`
|
||||||
|
}
|
||||||
|
err = xml.Unmarshal(respBytes, &data)
|
||||||
|
if err != nil {
|
||||||
|
c.ResponseError(err.Error())
|
||||||
|
}
|
||||||
|
lock.Lock()
|
||||||
|
defer lock.Unlock()
|
||||||
|
if data.EventKey != "" {
|
||||||
|
wechatScanType = data.Event
|
||||||
|
c.Ctx.WriteString("")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetWebhookEventType ...
|
||||||
|
// @Tag GetWebhookEventType API
|
||||||
|
// @Title GetWebhookEventType
|
||||||
|
// @router /api/get-webhook-event [GET]
|
||||||
|
func (c *ApiController) GetWebhookEventType() {
|
||||||
|
lock.Lock()
|
||||||
|
defer lock.Unlock()
|
||||||
|
resp := &Response{
|
||||||
|
Status: "ok",
|
||||||
|
Msg: "",
|
||||||
|
Data: wechatScanType,
|
||||||
|
}
|
||||||
|
c.Data["json"] = resp
|
||||||
|
wechatScanType = ""
|
||||||
|
c.ServeJSON()
|
||||||
|
}
|
||||||
|
@ -63,8 +63,7 @@ func (c *ApiController) GetSessionUsername() string {
|
|||||||
if sessionData != nil &&
|
if sessionData != nil &&
|
||||||
sessionData.ExpireTime != 0 &&
|
sessionData.ExpireTime != 0 &&
|
||||||
sessionData.ExpireTime < time.Now().Unix() {
|
sessionData.ExpireTime < time.Now().Unix() {
|
||||||
c.SetSessionUsername("")
|
c.ClearUserSession()
|
||||||
c.SetSessionData(nil)
|
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -85,13 +84,17 @@ func (c *ApiController) GetSessionApplication() *object.Application {
|
|||||||
return application
|
return application
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *ApiController) ClearUserSession() {
|
||||||
|
c.SetSessionUsername("")
|
||||||
|
c.SetSessionData(nil)
|
||||||
|
}
|
||||||
|
|
||||||
func (c *ApiController) GetSessionOidc() (string, string) {
|
func (c *ApiController) GetSessionOidc() (string, string) {
|
||||||
sessionData := c.GetSessionData()
|
sessionData := c.GetSessionData()
|
||||||
if sessionData != nil &&
|
if sessionData != nil &&
|
||||||
sessionData.ExpireTime != 0 &&
|
sessionData.ExpireTime != 0 &&
|
||||||
sessionData.ExpireTime < time.Now().Unix() {
|
sessionData.ExpireTime < time.Now().Unix() {
|
||||||
c.SetSessionUsername("")
|
c.ClearUserSession()
|
||||||
c.SetSessionData(nil)
|
|
||||||
return "", ""
|
return "", ""
|
||||||
}
|
}
|
||||||
scopeValue := c.GetSession("scope")
|
scopeValue := c.GetSession("scope")
|
||||||
|
@ -210,7 +210,7 @@ func (c *RootController) SamlValidate() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if !strings.HasPrefix(target, service) {
|
if !strings.HasPrefix(target, service) {
|
||||||
c.ResponseError(fmt.Sprintf("service %s and %s do not match", target, service))
|
c.ResponseError(fmt.Sprintf(c.T("CasErr.ServiceDoNotMatch"), target, service))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,6 +18,7 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
|
||||||
"github.com/beego/beego/utils/pagination"
|
"github.com/beego/beego/utils/pagination"
|
||||||
|
xormadapter "github.com/casbin/xorm-adapter/v3"
|
||||||
"github.com/casdoor/casdoor/object"
|
"github.com/casdoor/casdoor/object"
|
||||||
"github.com/casdoor/casdoor/util"
|
"github.com/casdoor/casdoor/util"
|
||||||
)
|
)
|
||||||
@ -89,6 +90,69 @@ func (c *ApiController) SyncPolicies() {
|
|||||||
id := c.Input().Get("id")
|
id := c.Input().Get("id")
|
||||||
adapter := object.GetCasbinAdapter(id)
|
adapter := object.GetCasbinAdapter(id)
|
||||||
|
|
||||||
c.Data["json"] = object.SyncPolicies(adapter)
|
policies, err := object.SyncPolicies(adapter)
|
||||||
|
if err != nil {
|
||||||
|
c.ResponseError(err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
c.Data["json"] = policies
|
||||||
|
c.ServeJSON()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *ApiController) UpdatePolicy() {
|
||||||
|
id := c.Input().Get("id")
|
||||||
|
adapter := object.GetCasbinAdapter(id)
|
||||||
|
var policies []xormadapter.CasbinRule
|
||||||
|
err := json.Unmarshal(c.Ctx.Input.RequestBody, &policies)
|
||||||
|
if err != nil {
|
||||||
|
c.ResponseError(err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
affected, err := object.UpdatePolicy(util.CasbinToSlice(policies[0]), util.CasbinToSlice(policies[1]), adapter)
|
||||||
|
if err != nil {
|
||||||
|
c.ResponseError(err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
c.Data["json"] = wrapActionResponse(affected)
|
||||||
|
c.ServeJSON()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *ApiController) AddPolicy() {
|
||||||
|
id := c.Input().Get("id")
|
||||||
|
adapter := object.GetCasbinAdapter(id)
|
||||||
|
var policy xormadapter.CasbinRule
|
||||||
|
err := json.Unmarshal(c.Ctx.Input.RequestBody, &policy)
|
||||||
|
if err != nil {
|
||||||
|
c.ResponseError(err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
affected, err := object.AddPolicy(util.CasbinToSlice(policy), adapter)
|
||||||
|
if err != nil {
|
||||||
|
c.ResponseError(err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
c.Data["json"] = wrapActionResponse(affected)
|
||||||
|
c.ServeJSON()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *ApiController) RemovePolicy() {
|
||||||
|
id := c.Input().Get("id")
|
||||||
|
adapter := object.GetCasbinAdapter(id)
|
||||||
|
var policy xormadapter.CasbinRule
|
||||||
|
err := json.Unmarshal(c.Ctx.Input.RequestBody, &policy)
|
||||||
|
if err != nil {
|
||||||
|
c.ResponseError(err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
affected, err := object.RemovePolicy(util.CasbinToSlice(policy), adapter)
|
||||||
|
if err != nil {
|
||||||
|
c.ResponseError(err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
c.Data["json"] = wrapActionResponse(affected)
|
||||||
c.ServeJSON()
|
c.ServeJSON()
|
||||||
}
|
}
|
||||||
|
@ -21,12 +21,6 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func (c *ApiController) Enforce() {
|
func (c *ApiController) Enforce() {
|
||||||
userId := c.GetSessionUsername()
|
|
||||||
if userId == "" {
|
|
||||||
c.ResponseError("Please sign in first")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
var permissionRule object.PermissionRule
|
var permissionRule object.PermissionRule
|
||||||
err := json.Unmarshal(c.Ctx.Input.RequestBody, &permissionRule)
|
err := json.Unmarshal(c.Ctx.Input.RequestBody, &permissionRule)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -34,17 +28,11 @@ func (c *ApiController) Enforce() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
c.Data["json"] = object.Enforce(userId, &permissionRule)
|
c.Data["json"] = object.Enforce(&permissionRule)
|
||||||
c.ServeJSON()
|
c.ServeJSON()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *ApiController) BatchEnforce() {
|
func (c *ApiController) BatchEnforce() {
|
||||||
userId := c.GetSessionUsername()
|
|
||||||
if userId == "" {
|
|
||||||
c.ResponseError("Please sign in first")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
var permissionRules []object.PermissionRule
|
var permissionRules []object.PermissionRule
|
||||||
err := json.Unmarshal(c.Ctx.Input.RequestBody, &permissionRules)
|
err := json.Unmarshal(c.Ctx.Input.RequestBody, &permissionRules)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -52,14 +40,14 @@ func (c *ApiController) BatchEnforce() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
c.Data["json"] = object.BatchEnforce(userId, permissionRules)
|
c.Data["json"] = object.BatchEnforce(permissionRules)
|
||||||
c.ServeJSON()
|
c.ServeJSON()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *ApiController) GetAllObjects() {
|
func (c *ApiController) GetAllObjects() {
|
||||||
userId := c.GetSessionUsername()
|
userId := c.GetSessionUsername()
|
||||||
if userId == "" {
|
if userId == "" {
|
||||||
c.ResponseError("Please sign in first")
|
c.ResponseError(c.T("EnforcerErr.SignInFirst"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -70,7 +58,7 @@ func (c *ApiController) GetAllObjects() {
|
|||||||
func (c *ApiController) GetAllActions() {
|
func (c *ApiController) GetAllActions() {
|
||||||
userId := c.GetSessionUsername()
|
userId := c.GetSessionUsername()
|
||||||
if userId == "" {
|
if userId == "" {
|
||||||
c.ResponseError("Please sign in first")
|
c.ResponseError(c.T("EnforcerErr.SignInFirst"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -81,7 +69,7 @@ func (c *ApiController) GetAllActions() {
|
|||||||
func (c *ApiController) GetAllRoles() {
|
func (c *ApiController) GetAllRoles() {
|
||||||
userId := c.GetSessionUsername()
|
userId := c.GetSessionUsername()
|
||||||
if userId == "" {
|
if userId == "" {
|
||||||
c.ResponseError("Please sign in first")
|
c.ResponseError(c.T("EnforcerErr.SignInFirst"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -52,7 +52,7 @@ func (c *ApiController) GetLdapUser() {
|
|||||||
ldapServer := LdapServer{}
|
ldapServer := LdapServer{}
|
||||||
err := json.Unmarshal(c.Ctx.Input.RequestBody, &ldapServer)
|
err := json.Unmarshal(c.Ctx.Input.RequestBody, &ldapServer)
|
||||||
if err != nil || util.IsStrsEmpty(ldapServer.Host, ldapServer.Admin, ldapServer.Passwd, ldapServer.BaseDn) {
|
if err != nil || util.IsStrsEmpty(ldapServer.Host, ldapServer.Admin, ldapServer.Passwd, ldapServer.BaseDn) {
|
||||||
c.ResponseError("Missing parameter")
|
c.ResponseError(c.T("ParameterErr.Missing"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -120,7 +120,7 @@ func (c *ApiController) GetLdap() {
|
|||||||
id := c.Input().Get("id")
|
id := c.Input().Get("id")
|
||||||
|
|
||||||
if util.IsStrsEmpty(id) {
|
if util.IsStrsEmpty(id) {
|
||||||
c.ResponseError("Missing parameter")
|
c.ResponseError(c.T("ParameterErr.Missing"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -136,17 +136,17 @@ func (c *ApiController) AddLdap() {
|
|||||||
var ldap object.Ldap
|
var ldap object.Ldap
|
||||||
err := json.Unmarshal(c.Ctx.Input.RequestBody, &ldap)
|
err := json.Unmarshal(c.Ctx.Input.RequestBody, &ldap)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.ResponseError("Missing parameter")
|
c.ResponseError(c.T("ParameterErr.Missing"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if util.IsStrsEmpty(ldap.Owner, ldap.ServerName, ldap.Host, ldap.Admin, ldap.Passwd, ldap.BaseDn) {
|
if util.IsStrsEmpty(ldap.Owner, ldap.ServerName, ldap.Host, ldap.Admin, ldap.Passwd, ldap.BaseDn) {
|
||||||
c.ResponseError("Missing parameter")
|
c.ResponseError(c.T("ParameterErr.Missing"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if object.CheckLdapExist(&ldap) {
|
if object.CheckLdapExist(&ldap) {
|
||||||
c.ResponseError("Ldap server exist")
|
c.ResponseError(c.T("LdapErr.ServerExisted"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -171,7 +171,7 @@ func (c *ApiController) UpdateLdap() {
|
|||||||
var ldap object.Ldap
|
var ldap object.Ldap
|
||||||
err := json.Unmarshal(c.Ctx.Input.RequestBody, &ldap)
|
err := json.Unmarshal(c.Ctx.Input.RequestBody, &ldap)
|
||||||
if err != nil || util.IsStrsEmpty(ldap.Owner, ldap.ServerName, ldap.Host, ldap.Admin, ldap.Passwd, ldap.BaseDn) {
|
if err != nil || util.IsStrsEmpty(ldap.Owner, ldap.ServerName, ldap.Host, ldap.Admin, ldap.Passwd, ldap.BaseDn) {
|
||||||
c.ResponseError("Missing parameter")
|
c.ResponseError(c.T("ParameterErr.Missing"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -49,7 +49,7 @@ func handleBind(w ldapserver.ResponseWriter, m *ldapserver.Message) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
bindpassword := string(r.AuthenticationSimple())
|
bindpassword := string(r.AuthenticationSimple())
|
||||||
binduser, err := object.CheckUserPassword(bindorg, bindusername, bindpassword)
|
binduser, err := object.CheckUserPassword(bindorg, bindusername, bindpassword, "en")
|
||||||
if err != "" {
|
if err != "" {
|
||||||
log.Printf("Bind failed User=%s, Pass=%#v, ErrMsg=%s", string(r.Name()), r.Authentication(), err)
|
log.Printf("Bind failed User=%s, Pass=%#v, ErrMsg=%s", string(r.Name()), r.Authentication(), err)
|
||||||
res.SetResultCode(ldapserver.LDAPResultInvalidCredentials)
|
res.SetResultCode(ldapserver.LDAPResultInvalidCredentials)
|
||||||
|
@ -47,7 +47,7 @@ func (c *ApiController) Unlink() {
|
|||||||
|
|
||||||
if user.Id != unlinkedUser.Id && !user.IsGlobalAdmin {
|
if user.Id != unlinkedUser.Id && !user.IsGlobalAdmin {
|
||||||
// if the user is not the same as the one we are unlinking, we need to make sure the user is the global admin.
|
// if the user is not the same as the one we are unlinking, we need to make sure the user is the global admin.
|
||||||
c.ResponseError("You are not the global admin, you can't unlink other users")
|
c.ResponseError(c.T("AuthErr.CanNotUnlinkUsers"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -55,23 +55,23 @@ func (c *ApiController) Unlink() {
|
|||||||
// if the user is unlinking themselves, should check the provider can be unlinked, if not, we should return an error.
|
// if the user is unlinking themselves, should check the provider can be unlinked, if not, we should return an error.
|
||||||
application := object.GetApplicationByUser(user)
|
application := object.GetApplicationByUser(user)
|
||||||
if application == nil {
|
if application == nil {
|
||||||
c.ResponseError("You can't unlink yourself, you are not a member of any application")
|
c.ResponseError(c.T("AuthErr.CanNotLinkMySelf"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(application.Providers) == 0 {
|
if len(application.Providers) == 0 {
|
||||||
c.ResponseError("This application has no providers")
|
c.ResponseError(c.T("ApplicationErr.HasNoProviders"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
provider := application.GetProviderItemByType(providerType)
|
provider := application.GetProviderItemByType(providerType)
|
||||||
if provider == nil {
|
if provider == nil {
|
||||||
c.ResponseError("This application has no providers of type " + providerType)
|
c.ResponseError(c.T("ApplicationErr.HasNoProvidersOfType") + providerType)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if !provider.CanUnlink {
|
if !provider.CanUnlink {
|
||||||
c.ResponseError("This provider can't be unlinked")
|
c.ResponseError(c.T("ProviderErr.CanNotBeUnlinked"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -84,7 +84,7 @@ func (c *ApiController) Unlink() {
|
|||||||
value := object.GetUserField(&unlinkedUser, providerType)
|
value := object.GetUserField(&unlinkedUser, providerType)
|
||||||
|
|
||||||
if value == "" {
|
if value == "" {
|
||||||
c.ResponseError("Please link first", value)
|
c.ResponseError(c.T("ProviderErr.LinkFirstErr"), value)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -99,6 +99,12 @@ func (c *ApiController) AddOrganization() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
count := object.GetOrganizationCount("", "", "")
|
||||||
|
if err := checkQuotaForOrganization(count); err != nil {
|
||||||
|
c.ResponseError(err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
c.Data["json"] = wrapActionResponse(object.AddOrganization(&organization))
|
c.Data["json"] = wrapActionResponse(object.AddOrganization(&organization))
|
||||||
c.ServeJSON()
|
c.ServeJSON()
|
||||||
}
|
}
|
||||||
|
@ -65,6 +65,20 @@ func (c *ApiController) GetPermissionsBySubmitter() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetPermissionsByRole
|
||||||
|
// @Title GetPermissionsByRole
|
||||||
|
// @Tag Permission API
|
||||||
|
// @Description get permissions by role
|
||||||
|
// @Param id query string true "The id of the role"
|
||||||
|
// @Success 200 {array} object.Permission The Response object
|
||||||
|
// @router /get-permissions-by-role [get]
|
||||||
|
func (c *ApiController) GetPermissionsByRole() {
|
||||||
|
id := c.Input().Get("id")
|
||||||
|
permissions := object.GetPermissionsByRole(id)
|
||||||
|
c.ResponseOk(permissions, len(permissions))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// GetPermission
|
// GetPermission
|
||||||
// @Title GetPermission
|
// @Title GetPermission
|
||||||
// @Tag Permission API
|
// @Tag Permission API
|
||||||
|
@ -141,13 +141,13 @@ func (c *ApiController) BuyProduct() {
|
|||||||
|
|
||||||
userId := c.GetSessionUsername()
|
userId := c.GetSessionUsername()
|
||||||
if userId == "" {
|
if userId == "" {
|
||||||
c.ResponseError("Please login first")
|
c.ResponseError(c.T("LoginErr.LoginFirst"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
user := object.GetUser(userId)
|
user := object.GetUser(userId)
|
||||||
if user == nil {
|
if user == nil {
|
||||||
c.ResponseError(fmt.Sprintf("The user: %s doesn't exist", userId))
|
c.ResponseError(fmt.Sprintf(c.T("UserErr.DoNotExist"), userId))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -48,6 +48,30 @@ func (c *ApiController) GetProviders() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetGlobalProviders
|
||||||
|
// @Title GetGlobalProviders
|
||||||
|
// @Tag Provider API
|
||||||
|
// @Description get Global providers
|
||||||
|
// @Success 200 {array} object.Provider The Response object
|
||||||
|
// @router /get-global-providers [get]
|
||||||
|
func (c *ApiController) GetGlobalProviders() {
|
||||||
|
limit := c.Input().Get("pageSize")
|
||||||
|
page := c.Input().Get("p")
|
||||||
|
field := c.Input().Get("field")
|
||||||
|
value := c.Input().Get("value")
|
||||||
|
sortField := c.Input().Get("sortField")
|
||||||
|
sortOrder := c.Input().Get("sortOrder")
|
||||||
|
if limit == "" || page == "" {
|
||||||
|
c.Data["json"] = object.GetMaskedProviders(object.GetGlobalProviders())
|
||||||
|
c.ServeJSON()
|
||||||
|
} else {
|
||||||
|
limit := util.ParseInt(limit)
|
||||||
|
paginator := pagination.SetPaginator(c.Ctx, limit, int64(object.GetGlobalProviderCount(field, value)))
|
||||||
|
providers := object.GetMaskedProviders(object.GetPaginationGlobalProviders(paginator.Offset(), limit, field, value, sortField, sortOrder))
|
||||||
|
c.ResponseOk(providers, paginator.Nums())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// GetProvider
|
// GetProvider
|
||||||
// @Title GetProvider
|
// @Title GetProvider
|
||||||
// @Tag Provider API
|
// @Tag Provider API
|
||||||
@ -57,7 +81,6 @@ func (c *ApiController) GetProviders() {
|
|||||||
// @router /get-provider [get]
|
// @router /get-provider [get]
|
||||||
func (c *ApiController) GetProvider() {
|
func (c *ApiController) GetProvider() {
|
||||||
id := c.Input().Get("id")
|
id := c.Input().Get("id")
|
||||||
|
|
||||||
c.Data["json"] = object.GetMaskedProvider(object.GetProvider(id))
|
c.Data["json"] = object.GetMaskedProvider(object.GetProvider(id))
|
||||||
c.ServeJSON()
|
c.ServeJSON()
|
||||||
}
|
}
|
||||||
@ -99,6 +122,12 @@ func (c *ApiController) AddProvider() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
count := object.GetProviderCount("", "", "")
|
||||||
|
if err := checkQuotaForProvider(count); err != nil {
|
||||||
|
c.ResponseError(err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
c.Data["json"] = wrapActionResponse(object.AddProvider(&provider))
|
c.Data["json"] = wrapActionResponse(object.AddProvider(&provider))
|
||||||
c.ServeJSON()
|
c.ServeJSON()
|
||||||
}
|
}
|
||||||
|
@ -40,6 +40,15 @@ func (c *ApiController) GetResources() {
|
|||||||
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")
|
||||||
|
|
||||||
|
userObj, ok := c.RequireSignedInUser()
|
||||||
|
if !ok {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if userObj.IsAdmin {
|
||||||
|
user = ""
|
||||||
|
}
|
||||||
|
|
||||||
if limit == "" || page == "" {
|
if limit == "" || page == "" {
|
||||||
c.Data["json"] = object.GetResources(owner, user)
|
c.Data["json"] = object.GetResources(owner, user)
|
||||||
c.ServeJSON()
|
c.ServeJSON()
|
||||||
@ -113,7 +122,7 @@ func (c *ApiController) DeleteResource() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
err = object.DeleteFile(provider, resource.Name)
|
err = object.DeleteFile(provider, resource.Name, c.GetAcceptLanguage())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.ResponseError(err.Error())
|
c.ResponseError(err.Error())
|
||||||
return
|
return
|
||||||
@ -145,7 +154,7 @@ func (c *ApiController) UploadResource() {
|
|||||||
defer file.Close()
|
defer file.Close()
|
||||||
|
|
||||||
if username == "" || fullFilePath == "" {
|
if username == "" || fullFilePath == "" {
|
||||||
c.ResponseError(fmt.Sprintf("username or fullFilePath is empty: username = %s, fullFilePath = %s", username, fullFilePath))
|
c.ResponseError(fmt.Sprintf(c.T("ResourceErr.UsernameOrFilePathEmpty"), username, fullFilePath))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -156,7 +165,7 @@ func (c *ApiController) UploadResource() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
provider, user, ok := c.GetProviderFromContext("Storage")
|
provider, _, ok := c.GetProviderFromContext("Storage")
|
||||||
if !ok {
|
if !ok {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -171,6 +180,20 @@ func (c *ApiController) UploadResource() {
|
|||||||
fileType, _ = util.GetOwnerAndNameFromId(mimeType)
|
fileType, _ = util.GetOwnerAndNameFromId(mimeType)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if tag != "avatar" && tag != "termsOfUse" {
|
||||||
|
ext := filepath.Ext(filepath.Base(fullFilePath))
|
||||||
|
index := len(fullFilePath) - len(ext)
|
||||||
|
for i := 1; ; i++ {
|
||||||
|
_, objectKey := object.GetUploadFileUrl(provider, fullFilePath, true)
|
||||||
|
if object.GetResourceCount(owner, username, "name", objectKey) == 0 {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
// duplicated fullFilePath found, change it
|
||||||
|
fullFilePath = fullFilePath[:index] + fmt.Sprintf("-%d", i) + ext
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fileUrl, objectKey, err := object.UploadFileSafe(provider, fullFilePath, fileBuffer)
|
fileUrl, objectKey, err := object.UploadFileSafe(provider, fullFilePath, fileBuffer)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.ResponseError(err.Error())
|
c.ResponseError(err.Error())
|
||||||
@ -202,12 +225,10 @@ func (c *ApiController) UploadResource() {
|
|||||||
|
|
||||||
switch tag {
|
switch tag {
|
||||||
case "avatar":
|
case "avatar":
|
||||||
|
user := object.GetUserNoCheck(util.GetId(owner, username))
|
||||||
if user == nil {
|
if user == nil {
|
||||||
user = object.GetUserNoCheck(username)
|
c.ResponseError(c.T("ResourceErr.UserIsNil"))
|
||||||
if user == nil {
|
return
|
||||||
c.ResponseError("user is nil for tag: \"avatar\"")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
user.Avatar = fileUrl
|
user.Avatar = fileUrl
|
||||||
|
@ -25,7 +25,7 @@ func (c *ApiController) GetSamlMeta() {
|
|||||||
paramApp := c.Input().Get("application")
|
paramApp := c.Input().Get("application")
|
||||||
application := object.GetApplication(paramApp)
|
application := object.GetApplication(paramApp)
|
||||||
if application == nil {
|
if application == nil {
|
||||||
c.ResponseError(fmt.Sprintf("err: application %s not found", paramApp))
|
c.ResponseError(fmt.Sprintf(c.T("ApplicationErr.AppNotFound"), paramApp))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
metadata, _ := object.GetSamlMeta(application, host)
|
metadata, _ := object.GetSamlMeta(application, host)
|
||||||
|
@ -60,7 +60,7 @@ func (c *ApiController) SendEmail() {
|
|||||||
var provider *object.Provider
|
var provider *object.Provider
|
||||||
if emailForm.Provider != "" {
|
if emailForm.Provider != "" {
|
||||||
// called by frontend's TestEmailWidget, provider name is set by frontend
|
// called by frontend's TestEmailWidget, provider name is set by frontend
|
||||||
provider = object.GetProvider(fmt.Sprintf("admin/%s", emailForm.Provider))
|
provider = object.GetProvider(util.GetId("admin", emailForm.Provider))
|
||||||
} else {
|
} else {
|
||||||
// called by Casdoor SDK via Client ID & Client Secret, so the used Email provider will be the application' Email provider or the default Email provider
|
// called by Casdoor SDK via Client ID & Client Secret, so the used Email provider will be the application' Email provider or the default Email provider
|
||||||
var ok bool
|
var ok bool
|
||||||
@ -81,7 +81,7 @@ func (c *ApiController) SendEmail() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if util.IsStrsEmpty(emailForm.Title, emailForm.Content, emailForm.Sender) {
|
if util.IsStrsEmpty(emailForm.Title, emailForm.Content, emailForm.Sender) {
|
||||||
c.ResponseError(fmt.Sprintf("Empty parameters for emailForm: %v", emailForm))
|
c.ResponseError(fmt.Sprintf(c.T("EmailErr.EmptyParam"), emailForm))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -93,7 +93,7 @@ func (c *ApiController) SendEmail() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if len(invalidReceivers) != 0 {
|
if len(invalidReceivers) != 0 {
|
||||||
c.ResponseError(fmt.Sprintf("Invalid Email receivers: %s", invalidReceivers))
|
c.ResponseError(fmt.Sprintf(c.T("EmailErr.InvalidReceivers"), invalidReceivers))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -141,7 +141,7 @@ func (c *ApiController) SendSms() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if len(invalidReceivers) != 0 {
|
if len(invalidReceivers) != 0 {
|
||||||
c.ResponseError(fmt.Sprintf("Invalid phone receivers: %s", invalidReceivers))
|
c.ResponseError(fmt.Sprintf(c.T("PhoneErr.InvalidReceivers"), invalidReceivers))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -40,7 +40,7 @@ func (c *ApiController) GetSystemInfo() {
|
|||||||
|
|
||||||
user := object.GetUser(id)
|
user := object.GetUser(id)
|
||||||
if user == nil || !user.IsGlobalAdmin {
|
if user == nil || !user.IsGlobalAdmin {
|
||||||
c.ResponseError("You are not authorized to access this resource")
|
c.ResponseError(c.T("ResourceErr.NotAuthorized"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -150,12 +150,12 @@ func (c *ApiController) GetOAuthCode() {
|
|||||||
codeChallenge := c.Input().Get("code_challenge")
|
codeChallenge := c.Input().Get("code_challenge")
|
||||||
|
|
||||||
if challengeMethod != "S256" && challengeMethod != "null" && challengeMethod != "" {
|
if challengeMethod != "S256" && challengeMethod != "null" && challengeMethod != "" {
|
||||||
c.ResponseError("Challenge method should be S256")
|
c.ResponseError(c.T("AuthErr.ChallengeMethodErr"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
host := c.Ctx.Request.Host
|
host := c.Ctx.Request.Host
|
||||||
|
|
||||||
c.Data["json"] = object.GetOAuthCode(userId, clientId, responseType, redirectUri, scope, state, nonce, codeChallenge, host)
|
c.Data["json"] = object.GetOAuthCode(userId, clientId, responseType, redirectUri, scope, state, nonce, codeChallenge, host, c.GetAcceptLanguage())
|
||||||
c.ServeJSON()
|
c.ServeJSON()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -204,7 +204,7 @@ func (c *ApiController) GetOAuthToken() {
|
|||||||
}
|
}
|
||||||
host := c.Ctx.Request.Host
|
host := c.Ctx.Request.Host
|
||||||
|
|
||||||
c.Data["json"] = object.GetOAuthToken(grantType, clientId, clientSecret, code, verifier, scope, username, password, host, tag, avatar)
|
c.Data["json"] = object.GetOAuthToken(grantType, clientId, clientSecret, code, verifier, scope, username, password, host, tag, avatar, c.GetAcceptLanguage())
|
||||||
c.SetTokenErrorHttpStatus()
|
c.SetTokenErrorHttpStatus()
|
||||||
c.ServeJSON()
|
c.ServeJSON()
|
||||||
}
|
}
|
||||||
@ -290,7 +290,7 @@ func (c *ApiController) IntrospectToken() {
|
|||||||
clientId = c.Input().Get("client_id")
|
clientId = c.Input().Get("client_id")
|
||||||
clientSecret = c.Input().Get("client_secret")
|
clientSecret = c.Input().Get("client_secret")
|
||||||
if clientId == "" || clientSecret == "" {
|
if clientId == "" || clientSecret == "" {
|
||||||
c.ResponseError("empty clientId or clientSecret")
|
c.ResponseError(c.T("TokenErr.EmptyClientID"))
|
||||||
c.Data["json"] = &object.TokenError{
|
c.Data["json"] = &object.TokenError{
|
||||||
Error: object.InvalidRequest,
|
Error: object.InvalidRequest,
|
||||||
}
|
}
|
||||||
@ -301,7 +301,7 @@ func (c *ApiController) IntrospectToken() {
|
|||||||
}
|
}
|
||||||
application := object.GetApplicationByClientId(clientId)
|
application := object.GetApplicationByClientId(clientId)
|
||||||
if application == nil || application.ClientSecret != clientSecret {
|
if application == nil || application.ClientSecret != clientSecret {
|
||||||
c.ResponseError("invalid application or wrong clientSecret")
|
c.ResponseError(c.T("TokenErr.InvalidAppOrWrongClientSecret"))
|
||||||
c.Data["json"] = &object.TokenError{
|
c.Data["json"] = &object.TokenError{
|
||||||
Error: object.InvalidClient,
|
Error: object.InvalidClient,
|
||||||
}
|
}
|
||||||
|
@ -100,7 +100,7 @@ func (c *ApiController) GetUser() {
|
|||||||
organization := object.GetOrganization(fmt.Sprintf("%s/%s", "admin", owner))
|
organization := object.GetOrganization(fmt.Sprintf("%s/%s", "admin", owner))
|
||||||
if !organization.IsProfilePublic {
|
if !organization.IsProfilePublic {
|
||||||
requestUserId := c.GetSessionUsername()
|
requestUserId := c.GetSessionUsername()
|
||||||
hasPermission, err := object.CheckUserPermission(requestUserId, id, owner, false)
|
hasPermission, err := object.CheckUserPermission(requestUserId, id, owner, false, c.GetAcceptLanguage())
|
||||||
if !hasPermission {
|
if !hasPermission {
|
||||||
c.ResponseError(err.Error())
|
c.ResponseError(err.Error())
|
||||||
return
|
return
|
||||||
@ -149,7 +149,7 @@ func (c *ApiController) UpdateUser() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if user.DisplayName == "" {
|
if user.DisplayName == "" {
|
||||||
c.ResponseError("Display name cannot be empty")
|
c.ResponseError(c.T("UserErr.DisplayNameCanNotBeEmpty"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -183,7 +183,13 @@ func (c *ApiController) AddUser() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
msg := object.CheckUsername(user.Name)
|
count := object.GetUserCount("", "", "")
|
||||||
|
if err := checkQuotaForUser(count); err != nil {
|
||||||
|
c.ResponseError(err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
msg := object.CheckUsername(user.Name, c.GetAcceptLanguage())
|
||||||
if msg != "" {
|
if msg != "" {
|
||||||
c.ResponseError(msg)
|
c.ResponseError(msg)
|
||||||
return
|
return
|
||||||
@ -230,7 +236,7 @@ func (c *ApiController) GetEmailAndPhone() {
|
|||||||
|
|
||||||
user := object.GetUserByFields(form.Organization, form.Username)
|
user := object.GetUserByFields(form.Organization, form.Username)
|
||||||
if user == nil {
|
if user == nil {
|
||||||
c.ResponseError(fmt.Sprintf("The user: %s/%s doesn't exist", form.Organization, form.Username))
|
c.ResponseError(fmt.Sprintf(c.T("UserErr.DoNotExistInOrg"), form.Organization, form.Username))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -271,7 +277,7 @@ func (c *ApiController) SetPassword() {
|
|||||||
requestUserId := c.GetSessionUsername()
|
requestUserId := c.GetSessionUsername()
|
||||||
userId := fmt.Sprintf("%s/%s", userOwner, userName)
|
userId := fmt.Sprintf("%s/%s", userOwner, userName)
|
||||||
|
|
||||||
hasPermission, err := object.CheckUserPermission(requestUserId, userId, userOwner, true)
|
hasPermission, err := object.CheckUserPermission(requestUserId, userId, userOwner, true, c.GetAcceptLanguage())
|
||||||
if !hasPermission {
|
if !hasPermission {
|
||||||
c.ResponseError(err.Error())
|
c.ResponseError(err.Error())
|
||||||
return
|
return
|
||||||
@ -280,7 +286,7 @@ func (c *ApiController) SetPassword() {
|
|||||||
targetUser := object.GetUser(userId)
|
targetUser := object.GetUser(userId)
|
||||||
|
|
||||||
if oldPassword != "" {
|
if oldPassword != "" {
|
||||||
msg := object.CheckPassword(targetUser, oldPassword)
|
msg := object.CheckPassword(targetUser, oldPassword, c.GetAcceptLanguage())
|
||||||
if msg != "" {
|
if msg != "" {
|
||||||
c.ResponseError(msg)
|
c.ResponseError(msg)
|
||||||
return
|
return
|
||||||
@ -288,12 +294,12 @@ func (c *ApiController) SetPassword() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if strings.Contains(newPassword, " ") {
|
if strings.Contains(newPassword, " ") {
|
||||||
c.ResponseError("New password cannot contain blank space.")
|
c.ResponseError(c.T("SetPasswordErr.CanNotContainBlank"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(newPassword) <= 5 {
|
if len(newPassword) <= 5 {
|
||||||
c.ResponseError("New password must have at least 6 characters")
|
c.ResponseError(c.T("SetPasswordErr.LessThanSixCharacters"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -315,7 +321,7 @@ func (c *ApiController) CheckUserPassword() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
_, msg := object.CheckUserPassword(user.Owner, user.Name, user.Password)
|
_, msg := object.CheckUserPassword(user.Owner, user.Name, user.Password, c.GetAcceptLanguage())
|
||||||
if msg == "" {
|
if msg == "" {
|
||||||
c.ResponseOk()
|
c.ResponseOk()
|
||||||
} else {
|
} else {
|
||||||
|
@ -61,6 +61,6 @@ func (c *ApiController) UploadUsers() {
|
|||||||
if affected {
|
if affected {
|
||||||
c.ResponseOk()
|
c.ResponseOk()
|
||||||
} else {
|
} else {
|
||||||
c.ResponseError("Failed to import users")
|
c.ResponseError(c.T("UserErr.FailToImportUsers"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,8 +17,10 @@ package controllers
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/casdoor/casdoor/conf"
|
"github.com/casdoor/casdoor/conf"
|
||||||
|
"github.com/casdoor/casdoor/i18n"
|
||||||
"github.com/casdoor/casdoor/object"
|
"github.com/casdoor/casdoor/object"
|
||||||
"github.com/casdoor/casdoor/util"
|
"github.com/casdoor/casdoor/util"
|
||||||
)
|
)
|
||||||
@ -48,6 +50,19 @@ func (c *ApiController) ResponseError(error string, data ...interface{}) {
|
|||||||
c.ResponseJsonData(resp, data...)
|
c.ResponseJsonData(resp, data...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *ApiController) T(error string) string {
|
||||||
|
return i18n.Translate(c.GetAcceptLanguage(), error)
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetAcceptLanguage ...
|
||||||
|
func (c *ApiController) GetAcceptLanguage() string {
|
||||||
|
lang := c.Ctx.Request.Header.Get("Accept-Language")
|
||||||
|
if lang == "" || !strings.Contains(conf.GetConfigString("languages"), lang[0:2]) {
|
||||||
|
lang = "en"
|
||||||
|
}
|
||||||
|
return lang[0:2]
|
||||||
|
}
|
||||||
|
|
||||||
// SetTokenErrorHttpStatus ...
|
// SetTokenErrorHttpStatus ...
|
||||||
func (c *ApiController) SetTokenErrorHttpStatus() {
|
func (c *ApiController) SetTokenErrorHttpStatus() {
|
||||||
_, ok := c.Data["json"].(*object.TokenError)
|
_, ok := c.Data["json"].(*object.TokenError)
|
||||||
@ -69,7 +84,7 @@ func (c *ApiController) SetTokenErrorHttpStatus() {
|
|||||||
func (c *ApiController) RequireSignedIn() (string, bool) {
|
func (c *ApiController) RequireSignedIn() (string, bool) {
|
||||||
userId := c.GetSessionUsername()
|
userId := c.GetSessionUsername()
|
||||||
if userId == "" {
|
if userId == "" {
|
||||||
c.ResponseError("Please sign in first")
|
c.ResponseError(c.T("LoginErr.LoginFirst"), "Please login first")
|
||||||
return "", false
|
return "", false
|
||||||
}
|
}
|
||||||
return userId, true
|
return userId, true
|
||||||
@ -84,7 +99,8 @@ func (c *ApiController) RequireSignedInUser() (*object.User, bool) {
|
|||||||
|
|
||||||
user := object.GetUser(userId)
|
user := object.GetUser(userId)
|
||||||
if user == nil {
|
if user == nil {
|
||||||
c.ResponseError(fmt.Sprintf("The user: %s doesn't exist", userId))
|
c.ClearUserSession()
|
||||||
|
c.ResponseError(fmt.Sprintf(c.T("UserErr.DoNotExist"), userId))
|
||||||
return nil, false
|
return nil, false
|
||||||
}
|
}
|
||||||
return user, true
|
return user, true
|
||||||
@ -110,9 +126,9 @@ func getInitScore() (int, error) {
|
|||||||
func (c *ApiController) GetProviderFromContext(category string) (*object.Provider, *object.User, bool) {
|
func (c *ApiController) GetProviderFromContext(category string) (*object.Provider, *object.User, bool) {
|
||||||
providerName := c.Input().Get("provider")
|
providerName := c.Input().Get("provider")
|
||||||
if providerName != "" {
|
if providerName != "" {
|
||||||
provider := object.GetProvider(util.GetId(providerName))
|
provider := object.GetProvider(util.GetId("admin", providerName))
|
||||||
if provider == nil {
|
if provider == nil {
|
||||||
c.ResponseError(fmt.Sprintf("The provider: %s is not found", providerName))
|
c.ResponseError(c.T("ProviderErr.ProviderNotFound"), providerName)
|
||||||
return nil, nil, false
|
return nil, nil, false
|
||||||
}
|
}
|
||||||
return provider, nil, true
|
return provider, nil, true
|
||||||
@ -125,15 +141,59 @@ func (c *ApiController) GetProviderFromContext(category string) (*object.Provide
|
|||||||
|
|
||||||
application, user := object.GetApplicationByUserId(userId)
|
application, user := object.GetApplicationByUserId(userId)
|
||||||
if application == nil {
|
if application == nil {
|
||||||
c.ResponseError(fmt.Sprintf("No application is found for userId: \"%s\"", userId))
|
c.ResponseError(fmt.Sprintf(c.T("ApplicationErr.AppNotFoundForUserID"), userId))
|
||||||
return nil, nil, false
|
return nil, nil, false
|
||||||
}
|
}
|
||||||
|
|
||||||
provider := application.GetProviderByCategory(category)
|
provider := application.GetProviderByCategory(category)
|
||||||
if provider == nil {
|
if provider == nil {
|
||||||
c.ResponseError(fmt.Sprintf("No provider for category: \"%s\" is found for application: %s", category, application.Name))
|
c.ResponseError(fmt.Sprintf(c.T("ProviderErr.ProviderNotFoundForCategory"), category, application.Name))
|
||||||
return nil, nil, false
|
return nil, nil, false
|
||||||
}
|
}
|
||||||
|
|
||||||
return provider, user, true
|
return provider, user, true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func checkQuotaForApplication(count int) error {
|
||||||
|
quota := conf.GetConfigQuota().Application
|
||||||
|
if quota == -1 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
if count >= quota {
|
||||||
|
return fmt.Errorf("application quota is exceeded")
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func checkQuotaForOrganization(count int) error {
|
||||||
|
quota := conf.GetConfigQuota().Organization
|
||||||
|
if quota == -1 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
if count >= quota {
|
||||||
|
return fmt.Errorf("organization quota is exceeded")
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func checkQuotaForProvider(count int) error {
|
||||||
|
quota := conf.GetConfigQuota().Provider
|
||||||
|
if quota == -1 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
if count >= quota {
|
||||||
|
return fmt.Errorf("provider quota is exceeded")
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func checkQuotaForUser(count int) error {
|
||||||
|
quota := conf.GetConfigQuota().User
|
||||||
|
if quota == -1 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
if count >= quota {
|
||||||
|
return fmt.Errorf("user quota is exceeded")
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
@ -50,23 +50,23 @@ func (c *ApiController) SendVerificationCode() {
|
|||||||
remoteAddr := util.GetIPFromRequest(c.Ctx.Request)
|
remoteAddr := util.GetIPFromRequest(c.Ctx.Request)
|
||||||
|
|
||||||
if destType == "" {
|
if destType == "" {
|
||||||
c.ResponseError("Missing parameter: type.")
|
c.ResponseError(c.T("ParameterErr.Missing") + ": type.")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if dest == "" {
|
if dest == "" {
|
||||||
c.ResponseError("Missing parameter: dest.")
|
c.ResponseError(c.T("ParameterErr.Missing") + ": dest.")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if applicationId == "" {
|
if applicationId == "" {
|
||||||
c.ResponseError("Missing parameter: applicationId.")
|
c.ResponseError(c.T("ParameterErr.Missing") + ": applicationId.")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if !strings.Contains(applicationId, "/") {
|
if !strings.Contains(applicationId, "/") {
|
||||||
c.ResponseError("Wrong parameter: applicationId.")
|
c.ResponseError(c.T("ParameterErr.Wrong") + ": applicationId.")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if checkType == "" {
|
if checkType == "" {
|
||||||
c.ResponseError("Missing parameter: checkType.")
|
c.ResponseError(c.T("ParameterErr.Missing") + ": checkType.")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -74,7 +74,7 @@ func (c *ApiController) SendVerificationCode() {
|
|||||||
|
|
||||||
if captchaProvider != nil {
|
if captchaProvider != nil {
|
||||||
if checkKey == "" {
|
if checkKey == "" {
|
||||||
c.ResponseError("Missing parameter: checkKey.")
|
c.ResponseError(c.T("ParameterErr.Missing") + ": checkKey.")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
isHuman, err := captchaProvider.VerifyCaptcha(checkKey, checkId)
|
isHuman, err := captchaProvider.VerifyCaptcha(checkKey, checkId)
|
||||||
@ -84,7 +84,7 @@ func (c *ApiController) SendVerificationCode() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if !isHuman {
|
if !isHuman {
|
||||||
c.ResponseError("Turing test failed.")
|
c.ResponseError(c.T("AuthErr.NotHuman"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -92,9 +92,13 @@ func (c *ApiController) SendVerificationCode() {
|
|||||||
user := c.getCurrentUser()
|
user := c.getCurrentUser()
|
||||||
application := object.GetApplication(applicationId)
|
application := object.GetApplication(applicationId)
|
||||||
organization := object.GetOrganization(fmt.Sprintf("%s/%s", application.Owner, application.Organization))
|
organization := object.GetOrganization(fmt.Sprintf("%s/%s", application.Owner, application.Organization))
|
||||||
|
if organization == nil {
|
||||||
|
c.ResponseError(c.T("OrgErr.DoNotExist"))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
if checkUser == "true" && user == nil && object.GetUserByFields(organization.Name, dest) == nil {
|
if checkUser == "true" && user == nil && object.GetUserByFields(organization.Name, dest) == nil {
|
||||||
c.ResponseError("Please login first")
|
c.ResponseError(c.T("LoginErr.LoginFirst"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -110,7 +114,13 @@ func (c *ApiController) SendVerificationCode() {
|
|||||||
dest = user.Email
|
dest = user.Email
|
||||||
}
|
}
|
||||||
if !util.IsEmailValid(dest) {
|
if !util.IsEmailValid(dest) {
|
||||||
c.ResponseError("Invalid Email address")
|
c.ResponseError(c.T("EmailErr.EmailInvalid"))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
userByEmail := object.GetUserByEmail(organization.Name, dest)
|
||||||
|
if userByEmail == nil {
|
||||||
|
c.ResponseError(c.T("UserErr.DoNotExistSignUp"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -121,11 +131,13 @@ func (c *ApiController) SendVerificationCode() {
|
|||||||
dest = user.Phone
|
dest = user.Phone
|
||||||
}
|
}
|
||||||
if !util.IsPhoneCnValid(dest) {
|
if !util.IsPhoneCnValid(dest) {
|
||||||
c.ResponseError("Invalid phone number")
|
c.ResponseError(c.T("PhoneErr.NumberInvalid"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if organization == nil {
|
|
||||||
c.ResponseError("The organization doesn't exist.")
|
userByPhone := object.GetUserByPhone(organization.Name, dest)
|
||||||
|
if userByPhone == nil {
|
||||||
|
c.ResponseError(c.T("UserErr.DoNotExistSignUp"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -157,7 +169,7 @@ func (c *ApiController) ResetEmailOrPhone() {
|
|||||||
dest := c.Ctx.Request.Form.Get("dest")
|
dest := c.Ctx.Request.Form.Get("dest")
|
||||||
code := c.Ctx.Request.Form.Get("code")
|
code := c.Ctx.Request.Form.Get("code")
|
||||||
if len(dest) == 0 || len(code) == 0 || len(destType) == 0 {
|
if len(dest) == 0 || len(code) == 0 || len(destType) == 0 {
|
||||||
c.ResponseError("Missing parameter.")
|
c.ResponseError(c.T("ParameterErr.Missing"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -166,11 +178,11 @@ func (c *ApiController) ResetEmailOrPhone() {
|
|||||||
if destType == "phone" {
|
if destType == "phone" {
|
||||||
phoneItem := object.GetAccountItemByName("Phone", org)
|
phoneItem := object.GetAccountItemByName("Phone", org)
|
||||||
if phoneItem == nil {
|
if phoneItem == nil {
|
||||||
c.ResponseError("Unable to get the phone modify rule.")
|
c.ResponseError(c.T("PhoneErr.UnableGetModifyRule"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if pass, errMsg := object.CheckAccountItemModifyRule(phoneItem, user); !pass {
|
if pass, errMsg := object.CheckAccountItemModifyRule(phoneItem, user, c.GetAcceptLanguage()); !pass {
|
||||||
c.ResponseError(errMsg)
|
c.ResponseError(errMsg)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -183,16 +195,16 @@ func (c *ApiController) ResetEmailOrPhone() {
|
|||||||
} else if destType == "email" {
|
} else if destType == "email" {
|
||||||
emailItem := object.GetAccountItemByName("Email", org)
|
emailItem := object.GetAccountItemByName("Email", org)
|
||||||
if emailItem == nil {
|
if emailItem == nil {
|
||||||
c.ResponseError("Unable to get the email modify rule.")
|
c.ResponseError(c.T("EmailErr.UnableGetModifyRule"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if pass, errMsg := object.CheckAccountItemModifyRule(emailItem, user); !pass {
|
if pass, errMsg := object.CheckAccountItemModifyRule(emailItem, user, c.GetAcceptLanguage()); !pass {
|
||||||
c.ResponseError(errMsg)
|
c.ResponseError(errMsg)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ret := object.CheckVerificationCode(checkDest, code); len(ret) != 0 {
|
if ret := object.CheckVerificationCode(checkDest, code, c.GetAcceptLanguage()); len(ret) != 0 {
|
||||||
c.ResponseError(ret)
|
c.ResponseError(ret)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -205,7 +217,7 @@ func (c *ApiController) ResetEmailOrPhone() {
|
|||||||
user.Phone = dest
|
user.Phone = dest
|
||||||
object.SetUserField(user, "phone", user.Phone)
|
object.SetUserField(user, "phone", user.Phone)
|
||||||
default:
|
default:
|
||||||
c.ResponseError("Unknown type.")
|
c.ResponseError(c.T("ParameterErr.UnknownType"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -224,17 +236,17 @@ func (c *ApiController) VerifyCaptcha() {
|
|||||||
captchaToken := c.Ctx.Request.Form.Get("captchaToken")
|
captchaToken := c.Ctx.Request.Form.Get("captchaToken")
|
||||||
clientSecret := c.Ctx.Request.Form.Get("clientSecret")
|
clientSecret := c.Ctx.Request.Form.Get("clientSecret")
|
||||||
if captchaToken == "" {
|
if captchaToken == "" {
|
||||||
c.ResponseError("Missing parameter: captchaToken.")
|
c.ResponseError(c.T("ParameterErr.Missing") + ": captchaToken.")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if clientSecret == "" {
|
if clientSecret == "" {
|
||||||
c.ResponseError("Missing parameter: clientSecret.")
|
c.ResponseError(c.T("ParameterErr.Missing") + ": clientSecret.")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
provider := captcha.GetCaptchaProvider(captchaType)
|
provider := captcha.GetCaptchaProvider(captchaType)
|
||||||
if provider == nil {
|
if provider == nil {
|
||||||
c.ResponseError("Invalid captcha provider.")
|
c.ResponseError(c.T("ProviderErr.InvalidProvider"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,7 +35,7 @@ func (c *ApiController) WebAuthnSignupBegin() {
|
|||||||
webauthnObj := object.GetWebAuthnObject(c.Ctx.Request.Host)
|
webauthnObj := object.GetWebAuthnObject(c.Ctx.Request.Host)
|
||||||
user := c.getCurrentUser()
|
user := c.getCurrentUser()
|
||||||
if user == nil {
|
if user == nil {
|
||||||
c.ResponseError("Please login first.")
|
c.ResponseError(c.T("LoginErr.LoginFirst"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -66,13 +66,13 @@ func (c *ApiController) WebAuthnSignupFinish() {
|
|||||||
webauthnObj := object.GetWebAuthnObject(c.Ctx.Request.Host)
|
webauthnObj := object.GetWebAuthnObject(c.Ctx.Request.Host)
|
||||||
user := c.getCurrentUser()
|
user := c.getCurrentUser()
|
||||||
if user == nil {
|
if user == nil {
|
||||||
c.ResponseError("Please login first.")
|
c.ResponseError(c.T("LoginErr.LoginFirst"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
sessionObj := c.GetSession("registration")
|
sessionObj := c.GetSession("registration")
|
||||||
sessionData, ok := sessionObj.(webauthn.SessionData)
|
sessionData, ok := sessionObj.(webauthn.SessionData)
|
||||||
if !ok {
|
if !ok {
|
||||||
c.ResponseError("Please call WebAuthnSignupBegin first")
|
c.ResponseError(c.T("AuthErr.CallWebAuthnSigninBegin"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
c.Ctx.Request.Body = io.NopCloser(bytes.NewBuffer(c.Ctx.Input.RequestBody))
|
c.Ctx.Request.Body = io.NopCloser(bytes.NewBuffer(c.Ctx.Input.RequestBody))
|
||||||
@ -101,9 +101,14 @@ func (c *ApiController) WebAuthnSigninBegin() {
|
|||||||
userName := c.Input().Get("name")
|
userName := c.Input().Get("name")
|
||||||
user := object.GetUserByFields(userOwner, userName)
|
user := object.GetUserByFields(userOwner, userName)
|
||||||
if user == nil {
|
if user == nil {
|
||||||
c.ResponseError(fmt.Sprintf("The user: %s/%s doesn't exist", userOwner, userName))
|
c.ResponseError(fmt.Sprintf(c.T("UserErr.DoNotExistInOrg"), userOwner, userName))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if len(user.WebauthnCredentials) == 0 {
|
||||||
|
c.ResponseError(c.T("UserErr.NoWebAuthnCredential"))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
options, sessionData, err := webauthnObj.BeginLogin(user)
|
options, sessionData, err := webauthnObj.BeginLogin(user)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.ResponseError(err.Error())
|
c.ResponseError(err.Error())
|
||||||
@ -127,7 +132,7 @@ func (c *ApiController) WebAuthnSigninFinish() {
|
|||||||
sessionObj := c.GetSession("authentication")
|
sessionObj := c.GetSession("authentication")
|
||||||
sessionData, ok := sessionObj.(webauthn.SessionData)
|
sessionData, ok := sessionObj.(webauthn.SessionData)
|
||||||
if !ok {
|
if !ok {
|
||||||
c.ResponseError("Please call WebAuthnSigninBegin first")
|
c.ResponseError(c.T("AuthErr.CallWebAuthnSigninBegin"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
c.Ctx.Request.Body = io.NopCloser(bytes.NewBuffer(c.Ctx.Input.RequestBody))
|
c.Ctx.Request.Body = io.NopCloser(bytes.NewBuffer(c.Ctx.Input.RequestBody))
|
||||||
|
@ -21,9 +21,10 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/casdoor/casdoor/object"
|
"github.com/casdoor/casdoor/object"
|
||||||
|
"github.com/casdoor/casdoor/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestDeployStaticFiles(t *testing.T) {
|
func TestDeployStaticFiles(t *testing.T) {
|
||||||
provider := object.GetProvider("admin/provider_storage_aliyun_oss")
|
provider := object.GetProvider(util.GetId("admin", "provider_storage_aliyun_oss"))
|
||||||
deployStaticFiles(provider)
|
deployStaticFiles(provider)
|
||||||
}
|
}
|
||||||
|
8
go.mod
8
go.mod
@ -4,6 +4,7 @@ go 1.16
|
|||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/RobotsAndPencils/go-saml v0.0.0-20170520135329-fb13cb52a46b
|
github.com/RobotsAndPencils/go-saml v0.0.0-20170520135329-fb13cb52a46b
|
||||||
|
github.com/Unknwon/goconfig v1.0.0
|
||||||
github.com/alexedwards/argon2id v0.0.0-20211130144151-3585854a6387
|
github.com/alexedwards/argon2id v0.0.0-20211130144151-3585854a6387
|
||||||
github.com/aws/aws-sdk-go v1.44.4
|
github.com/aws/aws-sdk-go v1.44.4
|
||||||
github.com/beego/beego v1.12.11
|
github.com/beego/beego v1.12.11
|
||||||
@ -22,6 +23,7 @@ require (
|
|||||||
github.com/go-pay/gopay v1.5.72
|
github.com/go-pay/gopay v1.5.72
|
||||||
github.com/go-sql-driver/mysql v1.5.0
|
github.com/go-sql-driver/mysql v1.5.0
|
||||||
github.com/golang-jwt/jwt/v4 v4.2.0
|
github.com/golang-jwt/jwt/v4 v4.2.0
|
||||||
|
github.com/golang/snappy v0.0.4 // indirect
|
||||||
github.com/google/go-cmp v0.5.8 // indirect
|
github.com/google/go-cmp v0.5.8 // indirect
|
||||||
github.com/google/uuid v1.2.0
|
github.com/google/uuid v1.2.0
|
||||||
github.com/kardianos/osext v0.0.0-20190222173326-2bc1f35cddc0 // indirect
|
github.com/kardianos/osext v0.0.0-20190222173326-2bc1f35cddc0 // indirect
|
||||||
@ -35,6 +37,7 @@ require (
|
|||||||
github.com/russellhaering/goxmldsig v1.1.1
|
github.com/russellhaering/goxmldsig v1.1.1
|
||||||
github.com/satori/go.uuid v1.2.0
|
github.com/satori/go.uuid v1.2.0
|
||||||
github.com/shirou/gopsutil v3.21.11+incompatible
|
github.com/shirou/gopsutil v3.21.11+incompatible
|
||||||
|
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e
|
||||||
github.com/smartystreets/goconvey v1.6.4 // indirect
|
github.com/smartystreets/goconvey v1.6.4 // indirect
|
||||||
github.com/stretchr/testify v1.8.0
|
github.com/stretchr/testify v1.8.0
|
||||||
github.com/tealeg/xlsx v1.0.5
|
github.com/tealeg/xlsx v1.0.5
|
||||||
@ -47,9 +50,10 @@ require (
|
|||||||
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a // indirect
|
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a // indirect
|
||||||
gopkg.in/alexcesaro/quotedprintable.v3 v3.0.0-20150716171945-2caba252f4dc // indirect
|
gopkg.in/alexcesaro/quotedprintable.v3 v3.0.0-20150716171945-2caba252f4dc // indirect
|
||||||
gopkg.in/gomail.v2 v2.0.0-20160411212932-81ebce5c23df // indirect
|
gopkg.in/gomail.v2 v2.0.0-20160411212932-81ebce5c23df // indirect
|
||||||
gopkg.in/ini.v1 v1.62.0 // indirect
|
gopkg.in/ini.v1 v1.67.0
|
||||||
gopkg.in/square/go-jose.v2 v2.6.0
|
gopkg.in/square/go-jose.v2 v2.6.0
|
||||||
gopkg.in/yaml.v2 v2.3.0 // indirect
|
gopkg.in/yaml.v2 v2.3.0 // indirect
|
||||||
|
xorm.io/builder v0.3.12 // indirect
|
||||||
xorm.io/core v0.7.2
|
xorm.io/core v0.7.2
|
||||||
xorm.io/xorm v1.0.4
|
xorm.io/xorm v1.0.5
|
||||||
)
|
)
|
||||||
|
18
go.sum
18
go.sum
@ -61,6 +61,8 @@ github.com/Knetic/govaluate v3.0.1-0.20171022003610-9aa49832a739+incompatible/go
|
|||||||
github.com/PuerkitoBio/goquery v1.5.1/go.mod h1:GsLWisAFVj4WgDibEWF4pvYnkVQBpKBKeU+7zCJoLcc=
|
github.com/PuerkitoBio/goquery v1.5.1/go.mod h1:GsLWisAFVj4WgDibEWF4pvYnkVQBpKBKeU+7zCJoLcc=
|
||||||
github.com/RobotsAndPencils/go-saml v0.0.0-20170520135329-fb13cb52a46b h1:EgJ6N2S0h1WfFIjU5/VVHWbMSVYXAluop97Qxpr/lfQ=
|
github.com/RobotsAndPencils/go-saml v0.0.0-20170520135329-fb13cb52a46b h1:EgJ6N2S0h1WfFIjU5/VVHWbMSVYXAluop97Qxpr/lfQ=
|
||||||
github.com/RobotsAndPencils/go-saml v0.0.0-20170520135329-fb13cb52a46b/go.mod h1:3SAoF0F5EbcOuBD5WT9nYkbIJieBS84cUQXADbXeBsU=
|
github.com/RobotsAndPencils/go-saml v0.0.0-20170520135329-fb13cb52a46b/go.mod h1:3SAoF0F5EbcOuBD5WT9nYkbIJieBS84cUQXADbXeBsU=
|
||||||
|
github.com/Unknwon/goconfig v1.0.0 h1:9IAu/BYbSLQi8puFjUQApZTxIHqSwrj5d8vpP8vTq4A=
|
||||||
|
github.com/Unknwon/goconfig v1.0.0/go.mod h1:wngxua9XCNjvHjDiTiV26DaKDT+0c63QR6H5hjVUUxw=
|
||||||
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
|
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
|
||||||
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
|
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
|
||||||
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
|
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
|
||||||
@ -211,8 +213,9 @@ github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw
|
|||||||
github.com/golang/protobuf v1.4.3 h1:JjCZWpVbqXDqFVmTfYWEVTMIYrL/NPdPSCHPJ0T/raM=
|
github.com/golang/protobuf v1.4.3 h1:JjCZWpVbqXDqFVmTfYWEVTMIYrL/NPdPSCHPJ0T/raM=
|
||||||
github.com/golang/protobuf v1.4.3/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI=
|
github.com/golang/protobuf v1.4.3/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI=
|
||||||
github.com/golang/snappy v0.0.0-20170215233205-553a64147049/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
|
github.com/golang/snappy v0.0.0-20170215233205-553a64147049/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
|
||||||
github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db h1:woRePGFeVFfLKN/pOkfl+p/TAqKOfFu+7KPlMVpok/w=
|
|
||||||
github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
|
github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
|
||||||
|
github.com/golang/snappy v0.0.4 h1:yAGX7huGHXlcLOEtBnF4w7FQwA26wojNCwOYAEhLjQM=
|
||||||
|
github.com/golang/snappy v0.0.4/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
|
||||||
github.com/gomodule/redigo v2.0.0+incompatible h1:K/R+8tc58AaqLkqG2Ol3Qk+DR/TlNuhuh457pBFPtt0=
|
github.com/gomodule/redigo v2.0.0+incompatible h1:K/R+8tc58AaqLkqG2Ol3Qk+DR/TlNuhuh457pBFPtt0=
|
||||||
github.com/gomodule/redigo v2.0.0+incompatible/go.mod h1:B4C85qUVwatsJoIUNIfCRsp7qO0iAmpGFZ4EELWSbC4=
|
github.com/gomodule/redigo v2.0.0+incompatible/go.mod h1:B4C85qUVwatsJoIUNIfCRsp7qO0iAmpGFZ4EELWSbC4=
|
||||||
github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
|
github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
|
||||||
@ -392,6 +395,8 @@ github.com/siddontang/goredis v0.0.0-20150324035039-760763f78400/go.mod h1:DDcKz
|
|||||||
github.com/siddontang/rdb v0.0.0-20150307021120-fc89ed2e418d/go.mod h1:AMEsy7v5z92TR1JKMkLLoaOQk++LVnOKL3ScbJ8GNGA=
|
github.com/siddontang/rdb v0.0.0-20150307021120-fc89ed2e418d/go.mod h1:AMEsy7v5z92TR1JKMkLLoaOQk++LVnOKL3ScbJ8GNGA=
|
||||||
github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
|
github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
|
||||||
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
|
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
|
||||||
|
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e h1:MRM5ITcdelLK2j1vwZ3Je0FKVCfqOLp5zO6trqMLYs0=
|
||||||
|
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e/go.mod h1:XV66xRDqSt+GTGFMVlhk3ULuV0y9ZmzeVGR4mloJI3M=
|
||||||
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykElWQ6/NYmHa3jpm/yHnI4xSofP+UP6SpjHcSeM=
|
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykElWQ6/NYmHa3jpm/yHnI4xSofP+UP6SpjHcSeM=
|
||||||
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
|
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
|
||||||
github.com/smartystreets/goconvey v0.0.0-20190330032615-68dc04aab96a/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA=
|
github.com/smartystreets/goconvey v0.0.0-20190330032615-68dc04aab96a/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA=
|
||||||
@ -757,8 +762,8 @@ gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMy
|
|||||||
gopkg.in/gomail.v2 v2.0.0-20160411212932-81ebce5c23df h1:n7WqCuqOuCbNr617RXOY0AWRXxgwEyPp2z+p0+hgMuE=
|
gopkg.in/gomail.v2 v2.0.0-20160411212932-81ebce5c23df h1:n7WqCuqOuCbNr617RXOY0AWRXxgwEyPp2z+p0+hgMuE=
|
||||||
gopkg.in/gomail.v2 v2.0.0-20160411212932-81ebce5c23df/go.mod h1:LRQQ+SO6ZHR7tOkpBDuZnXENFzX8qRjMDMyPD6BRkCw=
|
gopkg.in/gomail.v2 v2.0.0-20160411212932-81ebce5c23df/go.mod h1:LRQQ+SO6ZHR7tOkpBDuZnXENFzX8qRjMDMyPD6BRkCw=
|
||||||
gopkg.in/ini.v1 v1.42.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
|
gopkg.in/ini.v1 v1.42.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
|
||||||
gopkg.in/ini.v1 v1.62.0 h1:duBzk771uxoUuOlyRLkHsygud9+5lrlGjdFBb4mSKDU=
|
gopkg.in/ini.v1 v1.67.0 h1:Dgnx+6+nfE+IfzjUEISNeydPJh9AXNNsWbGP9KzCsOA=
|
||||||
gopkg.in/ini.v1 v1.62.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
|
gopkg.in/ini.v1 v1.67.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
|
||||||
gopkg.in/mgo.v2 v2.0.0-20190816093944-a6b53ec6cb22/go.mod h1:yeKp02qBN3iKW1OzL3MGk2IdtZzaj7SFntXj72NppTA=
|
gopkg.in/mgo.v2 v2.0.0-20190816093944-a6b53ec6cb22/go.mod h1:yeKp02qBN3iKW1OzL3MGk2IdtZzaj7SFntXj72NppTA=
|
||||||
gopkg.in/square/go-jose.v2 v2.6.0 h1:NGk74WTnPKBNUhNzQX7PYcTLUjoq7mzKk2OKbvwk2iI=
|
gopkg.in/square/go-jose.v2 v2.6.0 h1:NGk74WTnPKBNUhNzQX7PYcTLUjoq7mzKk2OKbvwk2iI=
|
||||||
gopkg.in/square/go-jose.v2 v2.6.0/go.mod h1:M9dMgbHiYLoDGQrXy7OpJDJWiKiU//h+vD76mk0e1AI=
|
gopkg.in/square/go-jose.v2 v2.6.0/go.mod h1:M9dMgbHiYLoDGQrXy7OpJDJWiKiU//h+vD76mk0e1AI=
|
||||||
@ -785,10 +790,11 @@ honnef.co/go/tools v0.0.1-2020.1.4/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9
|
|||||||
rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8=
|
rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8=
|
||||||
rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0=
|
rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0=
|
||||||
rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA=
|
rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA=
|
||||||
xorm.io/builder v0.3.7 h1:2pETdKRK+2QG4mLX4oODHEhn5Z8j1m8sXa7jfu+/SZI=
|
|
||||||
xorm.io/builder v0.3.7/go.mod h1:aUW0S9eb9VCaPohFCH3j7czOx1PMW3i1HrSzbLYGBSE=
|
xorm.io/builder v0.3.7/go.mod h1:aUW0S9eb9VCaPohFCH3j7czOx1PMW3i1HrSzbLYGBSE=
|
||||||
|
xorm.io/builder v0.3.12 h1:ASZYX7fQmy+o8UJdhlLHSW57JDOkM8DNhcAF5d0LiJM=
|
||||||
|
xorm.io/builder v0.3.12/go.mod h1:aUW0S9eb9VCaPohFCH3j7czOx1PMW3i1HrSzbLYGBSE=
|
||||||
xorm.io/core v0.7.2 h1:mEO22A2Z7a3fPaZMk6gKL/jMD80iiyNwRrX5HOv3XLw=
|
xorm.io/core v0.7.2 h1:mEO22A2Z7a3fPaZMk6gKL/jMD80iiyNwRrX5HOv3XLw=
|
||||||
xorm.io/core v0.7.2/go.mod h1:jJfd0UAEzZ4t87nbQYtVjmqpIODugN6PD2D9E+dJvdM=
|
xorm.io/core v0.7.2/go.mod h1:jJfd0UAEzZ4t87nbQYtVjmqpIODugN6PD2D9E+dJvdM=
|
||||||
xorm.io/xorm v1.0.3/go.mod h1:uF9EtbhODq5kNWxMbnBEj8hRRZnlcNSz2t2N7HW/+A4=
|
xorm.io/xorm v1.0.3/go.mod h1:uF9EtbhODq5kNWxMbnBEj8hRRZnlcNSz2t2N7HW/+A4=
|
||||||
xorm.io/xorm v1.0.4 h1:UBXA4I3NhiyjXfPqxXUkS2t5hMta9SSPATeMMaZg9oA=
|
xorm.io/xorm v1.0.5 h1:LRr5PfOUb4ODPR63YwbowkNDwcolT2LnkwP/TUaMaB0=
|
||||||
xorm.io/xorm v1.0.4/go.mod h1:uF9EtbhODq5kNWxMbnBEj8hRRZnlcNSz2t2N7HW/+A4=
|
xorm.io/xorm v1.0.5/go.mod h1:uF9EtbhODq5kNWxMbnBEj8hRRZnlcNSz2t2N7HW/+A4=
|
||||||
|
@ -83,7 +83,7 @@ func parseToData() *I18nData {
|
|||||||
|
|
||||||
data := I18nData{}
|
data := I18nData{}
|
||||||
for _, word := range allWords {
|
for _, word := range allWords {
|
||||||
tokens := strings.Split(word, ":")
|
tokens := strings.SplitN(word, ":", 2)
|
||||||
namespace := tokens[0]
|
namespace := tokens[0]
|
||||||
key := tokens[1]
|
key := tokens[1]
|
||||||
|
|
||||||
|
122
i18n/generate_backend.go
Normal file
122
i18n/generate_backend.go
Normal file
@ -0,0 +1,122 @@
|
|||||||
|
// Copyright 2022 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 i18n
|
||||||
|
|
||||||
|
import (
|
||||||
|
"log"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"regexp"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/Unknwon/goconfig"
|
||||||
|
"github.com/casdoor/casdoor/util"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
reI18nBackendObject *regexp.Regexp
|
||||||
|
re18nBackendController *regexp.Regexp
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
reI18nBackendObject, _ = regexp.Compile("i18n.Translate\\((.*?)\"\\)")
|
||||||
|
re18nBackendController, _ = regexp.Compile("c.T\\((.*?)\"\\)")
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetAllI18nStrings(fileContent string, path string) []string {
|
||||||
|
res := []string{}
|
||||||
|
if strings.Contains(path, "object") {
|
||||||
|
matches := reI18nBackendObject.FindAllStringSubmatch(fileContent, -1)
|
||||||
|
if matches == nil {
|
||||||
|
return res
|
||||||
|
}
|
||||||
|
for _, match := range matches {
|
||||||
|
match := strings.Split(match[1], ",")
|
||||||
|
res = append(res, match[1][2:])
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
matches := re18nBackendController.FindAllStringSubmatch(fileContent, -1)
|
||||||
|
if matches == nil {
|
||||||
|
return res
|
||||||
|
}
|
||||||
|
for _, match := range matches {
|
||||||
|
res = append(res, match[1][1:])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return res
|
||||||
|
}
|
||||||
|
|
||||||
|
func getAllGoFilePaths() []string {
|
||||||
|
path := "../"
|
||||||
|
|
||||||
|
res := []string{}
|
||||||
|
err := filepath.Walk(path,
|
||||||
|
func(path string, info os.FileInfo, err error) error {
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if !strings.HasSuffix(info.Name(), ".go") {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
res = append(res, path)
|
||||||
|
// fmt.Println(path, info.Name())
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return res
|
||||||
|
}
|
||||||
|
|
||||||
|
func getErrName(paths []string) map[string]bool {
|
||||||
|
ErrName := make(map[string]bool)
|
||||||
|
for i := 0; i < len(paths); i++ {
|
||||||
|
content := util.ReadStringFromPath(paths[i])
|
||||||
|
words := GetAllI18nStrings(content, paths[i])
|
||||||
|
for i := 0; i < len(words); i++ {
|
||||||
|
ErrName[words[i]] = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ErrName
|
||||||
|
}
|
||||||
|
|
||||||
|
func writeToAllLanguageFiles(errName map[string]bool) {
|
||||||
|
languages := "en,zh,es,fr,de,ja,ko,ru"
|
||||||
|
languageArr := strings.Split(languages, ",")
|
||||||
|
var c [10]*goconfig.ConfigFile
|
||||||
|
for i := 0; i < len(languageArr); i++ {
|
||||||
|
var err error
|
||||||
|
c[i], err = goconfig.LoadConfigFile("../i18n/languages/" + "locale_" + languageArr[i] + ".ini")
|
||||||
|
if err != nil {
|
||||||
|
log.Println(err.Error())
|
||||||
|
}
|
||||||
|
for j := range errName {
|
||||||
|
parts := strings.Split(j, ".")
|
||||||
|
_, err := c[i].GetValue(parts[0], parts[1])
|
||||||
|
if err != nil {
|
||||||
|
c[i].SetValue(parts[0], parts[1], parts[1])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
c[i].SetPrettyFormat(true)
|
||||||
|
err = goconfig.SaveConfigFile(c[i], "../i18n/languages/"+"locale_"+languageArr[i]+".ini")
|
||||||
|
if err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -14,7 +14,10 @@
|
|||||||
|
|
||||||
package i18n
|
package i18n
|
||||||
|
|
||||||
import "testing"
|
import (
|
||||||
|
"fmt"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
func applyToOtherLanguage(dataEn *I18nData, lang string) {
|
func applyToOtherLanguage(dataEn *I18nData, lang string) {
|
||||||
dataOther := readI18nFile(lang)
|
dataOther := readI18nFile(lang)
|
||||||
@ -24,7 +27,7 @@ func applyToOtherLanguage(dataEn *I18nData, lang string) {
|
|||||||
writeI18nFile(lang, dataEn)
|
writeI18nFile(lang, dataEn)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGenerateI18nStrings(t *testing.T) {
|
func TestGenerateI18nStringsForFrontend(t *testing.T) {
|
||||||
dataEn := parseToData()
|
dataEn := parseToData()
|
||||||
writeI18nFile("en", dataEn)
|
writeI18nFile("en", dataEn)
|
||||||
|
|
||||||
@ -35,3 +38,17 @@ func TestGenerateI18nStrings(t *testing.T) {
|
|||||||
applyToOtherLanguage(dataEn, "ru")
|
applyToOtherLanguage(dataEn, "ru")
|
||||||
applyToOtherLanguage(dataEn, "zh")
|
applyToOtherLanguage(dataEn, "zh")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestGenerateI18nStringsForBackend(t *testing.T) {
|
||||||
|
paths := getAllGoFilePaths()
|
||||||
|
|
||||||
|
errName := getErrName(paths)
|
||||||
|
|
||||||
|
writeToAllLanguageFiles(errName)
|
||||||
|
|
||||||
|
fmt.Println("Total Err Words:", len(errName))
|
||||||
|
|
||||||
|
for i := range errName {
|
||||||
|
fmt.Println(i)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
138
i18n/languages/locale_de.ini
Normal file
138
i18n/languages/locale_de.ini
Normal file
@ -0,0 +1,138 @@
|
|||||||
|
[ApplicationErr]
|
||||||
|
AppNotFound = Application %s not found
|
||||||
|
AppNotFoundForUserID = No application is found for userId: %s
|
||||||
|
GrantTypeNotSupport = Grant_type: %s is not supported in this application
|
||||||
|
HasNoProviders = This application has no providers
|
||||||
|
HasNoProvidersOfType = This application has no providers of type
|
||||||
|
InvalidID = Invalid application id
|
||||||
|
|
||||||
|
[AuthErr]
|
||||||
|
AuthStateWrong = State expected: %s, but got: %s
|
||||||
|
ChallengeMethodErr = Challenge method should be S256
|
||||||
|
CanNotUnlinkUsers = You are not the global admin, you can't unlink other users
|
||||||
|
CanNotLinkMySelf = You can't unlink yourself, you are not a member of any application
|
||||||
|
CallWebAuthnSigninBegin = Please call WebAuthnSigninBegin first
|
||||||
|
NotHuman = Turing test failed.
|
||||||
|
Unauthorized = Unauthorized operation
|
||||||
|
WrongPasswordManyTimes = WrongPasswordManyTimes
|
||||||
|
|
||||||
|
[CasErr]
|
||||||
|
ServiceDoNotMatch = Service %s and %s do not match
|
||||||
|
|
||||||
|
[EmailErr]
|
||||||
|
ExistedErr = Email already exists
|
||||||
|
EmptyErr = Email cannot be empty
|
||||||
|
EmailInvalid = Email is invalid
|
||||||
|
EmailCheckResult = Email: %s
|
||||||
|
EmptyParam = Empty parameters for emailForm: %v
|
||||||
|
InvalidReceivers = Invalid Email receivers: %s
|
||||||
|
UnableGetModifyRule = Unable to get the email modify rule.
|
||||||
|
|
||||||
|
[EnforcerErr]
|
||||||
|
SignInFirst = Please sign in first
|
||||||
|
|
||||||
|
[InitErr]
|
||||||
|
InitScoreFailed = Get init score failed, error: %%w
|
||||||
|
|
||||||
|
[LdapErr]
|
||||||
|
MultipleAccounts = Multiple accounts with same uid, please check your ldap server
|
||||||
|
PasswordWrong = Ldap user name or password incorrect
|
||||||
|
ServerExisted = Ldap server exist
|
||||||
|
|
||||||
|
[LoginErr]
|
||||||
|
AppDoNotExist = The application: %s does not exist
|
||||||
|
AppNotEnableSignUp = The account for provider: %s and username: %s (%s) does not exist and is not allowed to sign up as new account, please contact your IT support
|
||||||
|
AccountDoNotExist = The account does not exist
|
||||||
|
InvalidUserInformation = Failed to create user, user information is invalid: %s
|
||||||
|
LoginFirst = Please login first
|
||||||
|
LoginFail = Failed to login in: %s
|
||||||
|
NoPermission = You don't have the permission to do this
|
||||||
|
OldUser = The account for provider: %s and username: %s (%s) is already linked to another account: %s (%s)
|
||||||
|
ProviderCanNotSignUp = The account for provider: %s and username: %s (%s) does not exist and is not allowed to sign up as new account via %%s, please use another way to sign up
|
||||||
|
SessionOutdated = Session outdated, please login again
|
||||||
|
SignOutFirst = Please sign out first before signing in
|
||||||
|
UserDoNotExist = The user: %s/%s doesn't exist
|
||||||
|
UserIsForbidden = The user is forbidden to sign in, please contact the administrator
|
||||||
|
UnknownAuthentication = Unknown authentication type (not password or provider), form = %s
|
||||||
|
UnsupportedPasswordType = unsupported password type: %s
|
||||||
|
|
||||||
|
[OrgErr]
|
||||||
|
DoNotExist = Organization does not exist
|
||||||
|
Immutable = The %s is immutable.
|
||||||
|
OnlyAdmin = Only admin can modify the %s.
|
||||||
|
UnknownModifyRule = Unknown modify rule %s.
|
||||||
|
|
||||||
|
[ParameterErr]
|
||||||
|
OrgMissingErr = Parameter organization is missing
|
||||||
|
Missing = Missing parameter
|
||||||
|
UnknownType = Unknown type
|
||||||
|
Wrong = Wrong parameter
|
||||||
|
|
||||||
|
[PhoneErr]
|
||||||
|
CodeNotSent = Code has not been sent yet!
|
||||||
|
CodeTimeOut = You should verify your code in %d min!
|
||||||
|
ExistedErr = Phone already exists
|
||||||
|
EmptyErr = Phone cannot be empty
|
||||||
|
InvalidReceivers = Invalid phone receivers: %s
|
||||||
|
NumberInvalid = Phone number is invalid
|
||||||
|
NoPrefix = %s No phone prefix
|
||||||
|
PhoneCheckResult = Phone: %s
|
||||||
|
UnableGetModifyRule = Unable to get the phone modify rule.
|
||||||
|
|
||||||
|
[ProviderErr]
|
||||||
|
CanNotBeUnlinked = This provider can't be unlinked
|
||||||
|
CategoryNotSAML = provider %s's category is not SAML
|
||||||
|
DoNotExist = the provider: %s does not exist
|
||||||
|
InvalidProvider = Invalid captcha provider.
|
||||||
|
LinkFirstErr = Please link first
|
||||||
|
ProviderNotEnabled = The provider: %s is not enabled for the application
|
||||||
|
ProviderNotSupported = The provider type: %s is not supported
|
||||||
|
ProviderNotFound = The provider: %s is not found
|
||||||
|
ProviderNotFoundForCategory = No provider for category: %s is found for application: %s
|
||||||
|
|
||||||
|
[ResourceErr]
|
||||||
|
NotAuthorized = You are not authorized to access this resource
|
||||||
|
UserIsNil = User is nil for tag: /"avatar/"
|
||||||
|
UsernameOrFilePathEmpty = Username or fullFilePath is empty: username = %s, fullFilePath = %s
|
||||||
|
|
||||||
|
[SetPasswordErr]
|
||||||
|
CanNotContainBlank = New password cannot contain blank space.
|
||||||
|
LessThanSixCharacters = New password must have at least 6 characters
|
||||||
|
|
||||||
|
[SignUpErr]
|
||||||
|
DoNotAllowSignUp = The application does not allow to sign up new account
|
||||||
|
SignOutFirst = Please sign out first before signing up
|
||||||
|
|
||||||
|
[StorageErr]
|
||||||
|
ObjectKeyNotAllowed = The objectKey: %s is not allowed
|
||||||
|
|
||||||
|
[TokenErr]
|
||||||
|
EmptyClientID = Empty clientId or clientSecret
|
||||||
|
InvalidToken = Invalid token
|
||||||
|
InvalidAppOrWrongClientSecret = Invalid application or wrong clientSecret
|
||||||
|
InvalidClientId = Invalid client_id
|
||||||
|
RedirectURIDoNotExist = Redirect URI: %s doesn't exist in the allowed Redirect URI list
|
||||||
|
|
||||||
|
[UserErr]
|
||||||
|
AffiliationBlankErr = Affiliation cannot be blank
|
||||||
|
DisplayNameBlankErr = DisplayName cannot be blank
|
||||||
|
DisplayNameInvalid = DisplayName is not valid real name
|
||||||
|
DisplayNameCanNotBeEmpty = Display name cannot be empty
|
||||||
|
DoNotExist = The user: %s doesn't exist
|
||||||
|
DoNotExistInOrg = The user: %s/%s doesn't exist
|
||||||
|
DoNotExistSignUp = the user does not exist, please sign up first
|
||||||
|
FirstNameBlankErr = FirstName cannot be blank
|
||||||
|
FailToImportUsers = Failed to import users
|
||||||
|
LastNameBlankErr = LastName cannot be blank
|
||||||
|
NameLessThanTwoCharacters = Username must have at least 2 characters
|
||||||
|
NameStartWithADigitErr = Username cannot start with a digit
|
||||||
|
NameIsEmailErr = Username cannot be an email address
|
||||||
|
NameCantainWhitSpaceErr = Username cannot contain white spaces
|
||||||
|
NameExistedErr = Username already exists
|
||||||
|
NameEmptyErr = Empty username.
|
||||||
|
NameTooLang = Username is too long (maximum is 39 characters).
|
||||||
|
NameFormatErr = 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.
|
||||||
|
PasswordLessThanSixCharacters = Password must have at least 6 characters
|
||||||
|
InvalidInformation = Invalid information
|
||||||
|
NoWebAuthnCredential = Found no credentials for this user
|
||||||
|
|
138
i18n/languages/locale_en.ini
Normal file
138
i18n/languages/locale_en.ini
Normal file
@ -0,0 +1,138 @@
|
|||||||
|
[ApplicationErr]
|
||||||
|
AppNotFound = Application %s not found
|
||||||
|
AppNotFoundForUserID = No application is found for userId: %s
|
||||||
|
GrantTypeNotSupport = Grant_type: %s is not supported in this application
|
||||||
|
HasNoProviders = This application has no providers
|
||||||
|
HasNoProvidersOfType = This application has no providers of type
|
||||||
|
InvalidID = Invalid application id
|
||||||
|
|
||||||
|
[AuthErr]
|
||||||
|
AuthStateWrong = State expected: %s, but got: %s
|
||||||
|
ChallengeMethodErr = Challenge method should be S256
|
||||||
|
CanNotUnlinkUsers = You are not the global admin, you can't unlink other users
|
||||||
|
CanNotLinkMySelf = You can't unlink yourself, you are not a member of any application
|
||||||
|
CallWebAuthnSigninBegin = Please call WebAuthnSigninBegin first
|
||||||
|
NotHuman = Turing test failed.
|
||||||
|
WrongPasswordManyTimes = You have entered the wrong password too many times, please wait for %d minutes %d seconds and try again
|
||||||
|
Unauthorized = Unauthorized operation
|
||||||
|
|
||||||
|
[CasErr]
|
||||||
|
ServiceDoNotMatch = Service %s and %s do not match
|
||||||
|
|
||||||
|
[EmailErr]
|
||||||
|
ExistedErr = Email already exists
|
||||||
|
EmptyErr = Email cannot be empty
|
||||||
|
EmailInvalid = Email is invalid
|
||||||
|
EmailCheckResult = Email: %s
|
||||||
|
EmptyParam = Empty parameters for emailForm: %v
|
||||||
|
InvalidReceivers = Invalid Email receivers: %s
|
||||||
|
UnableGetModifyRule = Unable to get the email modify rule.
|
||||||
|
|
||||||
|
[EnforcerErr]
|
||||||
|
SignInFirst = Please sign in first
|
||||||
|
|
||||||
|
[InitErr]
|
||||||
|
InitScoreFailed = Get init score failed, error: %%w
|
||||||
|
|
||||||
|
[LdapErr]
|
||||||
|
MultipleAccounts = Multiple accounts with same uid, please check your ldap server
|
||||||
|
PasswordWrong = Ldap user name or password incorrect
|
||||||
|
ServerExisted = Ldap server exist
|
||||||
|
|
||||||
|
[LoginErr]
|
||||||
|
AppDoNotExist = The application: %s does not exist
|
||||||
|
AppNotEnableSignUp = The account for provider: %s and username: %s (%s) does not exist and is not allowed to sign up as new account, please contact your IT support
|
||||||
|
AccountDoNotExist = The account does not exist
|
||||||
|
InvalidUserInformation = Failed to create user, user information is invalid: %s
|
||||||
|
LoginFirst = Please login first
|
||||||
|
LoginFail = Failed to login in: %s
|
||||||
|
NoPermission = You don't have the permission to do this
|
||||||
|
OldUser = The account for provider: %s and username: %s (%s) is already linked to another account: %s (%s)
|
||||||
|
ProviderCanNotSignUp = The account for provider: %s and username: %s (%s) does not exist and is not allowed to sign up as new account via %%s, please use another way to sign up
|
||||||
|
SessionOutdated = Session outdated, please login again
|
||||||
|
SignOutFirst = Please sign out first before signing in
|
||||||
|
UserDoNotExist = The user: %s/%s doesn't exist
|
||||||
|
UserIsForbidden = The user is forbidden to sign in, please contact the administrator
|
||||||
|
UnknownAuthentication = Unknown authentication type (not password or provider), form = %s
|
||||||
|
UnsupportedPasswordType = unsupported password type: %s
|
||||||
|
|
||||||
|
[OrgErr]
|
||||||
|
DoNotExist = Organization does not exist
|
||||||
|
Immutable = The %s is immutable.
|
||||||
|
OnlyAdmin = Only admin can modify the %s.
|
||||||
|
UnknownModifyRule = Unknown modify rule %s.
|
||||||
|
|
||||||
|
[ParameterErr]
|
||||||
|
OrgMissingErr = Parameter organization is missing
|
||||||
|
Missing = Missing parameter
|
||||||
|
UnknownType = Unknown type
|
||||||
|
Wrong = Wrong parameter
|
||||||
|
|
||||||
|
[PhoneErr]
|
||||||
|
CodeNotSent = Code has not been sent yet!
|
||||||
|
CodeTimeOut = You should verify your code in %d min!
|
||||||
|
ExistedErr = Phone already exists
|
||||||
|
EmptyErr = Phone cannot be empty
|
||||||
|
InvalidReceivers = Invalid phone receivers: %s
|
||||||
|
NumberInvalid = Phone number is invalid
|
||||||
|
NoPrefix = %s No phone prefix
|
||||||
|
PhoneCheckResult = Phone: %s
|
||||||
|
UnableGetModifyRule = Unable to get the phone modify rule.
|
||||||
|
|
||||||
|
[ProviderErr]
|
||||||
|
CanNotBeUnlinked = This provider can't be unlinked
|
||||||
|
CategoryNotSAML = provider %s's category is not SAML
|
||||||
|
DoNotExist = the provider: %s does not exist
|
||||||
|
InvalidProvider = Invalid captcha provider.
|
||||||
|
LinkFirstErr = Please link first
|
||||||
|
ProviderNotEnabled = The provider: %s is not enabled for the application
|
||||||
|
ProviderNotSupported = The provider type: %s is not supported
|
||||||
|
ProviderNotFound = The provider: %s is not found
|
||||||
|
ProviderNotFoundForCategory = No provider for category: %s is found for application: %s
|
||||||
|
|
||||||
|
[ResourceErr]
|
||||||
|
NotAuthorized = You are not authorized to access this resource
|
||||||
|
UserIsNil = User is nil for tag: /"avatar/"
|
||||||
|
UsernameOrFilePathEmpty = Username or fullFilePath is empty: username = %s, fullFilePath = %s
|
||||||
|
|
||||||
|
[SetPasswordErr]
|
||||||
|
CanNotContainBlank = New password cannot contain blank space.
|
||||||
|
LessThanSixCharacters = New password must have at least 6 characters
|
||||||
|
|
||||||
|
[SignUpErr]
|
||||||
|
DoNotAllowSignUp = The application does not allow to sign up new account
|
||||||
|
SignOutFirst = Please sign out first before signing up
|
||||||
|
|
||||||
|
[StorageErr]
|
||||||
|
ObjectKeyNotAllowed = The objectKey: %s is not allowed
|
||||||
|
|
||||||
|
[TokenErr]
|
||||||
|
EmptyClientID = Empty clientId or clientSecret
|
||||||
|
InvalidToken = Invalid token
|
||||||
|
InvalidAppOrWrongClientSecret = Invalid application or wrong clientSecret
|
||||||
|
InvalidClientId = Invalid client_id
|
||||||
|
RedirectURIDoNotExist = Redirect URI: %s doesn't exist in the allowed Redirect URI list
|
||||||
|
|
||||||
|
[UserErr]
|
||||||
|
AffiliationBlankErr = Affiliation cannot be blank
|
||||||
|
DisplayNameBlankErr = DisplayName cannot be blank
|
||||||
|
DisplayNameInvalid = DisplayName is not valid real name
|
||||||
|
DisplayNameCanNotBeEmpty = Display name cannot be empty
|
||||||
|
DoNotExist = The user: %s doesn't exist
|
||||||
|
DoNotExistInOrg = The user: %s/%s doesn't exist
|
||||||
|
DoNotExistSignUp = the user does not exist, please sign up first
|
||||||
|
FirstNameBlankErr = FirstName cannot be blank
|
||||||
|
FailToImportUsers = Failed to import users
|
||||||
|
LastNameBlankErr = LastName cannot be blank
|
||||||
|
NameLessThanTwoCharacters = Username must have at least 2 characters
|
||||||
|
NameStartWithADigitErr = Username cannot start with a digit
|
||||||
|
NameIsEmailErr = Username cannot be an email address
|
||||||
|
NameCantainWhitSpaceErr = Username cannot contain white spaces
|
||||||
|
NameExistedErr = Username already exists
|
||||||
|
NameEmptyErr = Empty username.
|
||||||
|
NameTooLang = Username is too long (maximum is 39 characters).
|
||||||
|
NameFormatErr = 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.
|
||||||
|
PasswordLessThanSixCharacters = Password must have at least 6 characters
|
||||||
|
InvalidInformation = Invalid information
|
||||||
|
NoWebAuthnCredential = Found no credentials for this user
|
||||||
|
|
138
i18n/languages/locale_es.ini
Normal file
138
i18n/languages/locale_es.ini
Normal file
@ -0,0 +1,138 @@
|
|||||||
|
[ApplicationErr]
|
||||||
|
AppNotFound = Application %s not found
|
||||||
|
AppNotFoundForUserID = No application is found for userId: %s
|
||||||
|
GrantTypeNotSupport = Grant_type: %s is not supported in this application
|
||||||
|
HasNoProviders = This application has no providers
|
||||||
|
HasNoProvidersOfType = This application has no providers of type
|
||||||
|
InvalidID = Invalid application id
|
||||||
|
|
||||||
|
[AuthErr]
|
||||||
|
AuthStateWrong = State expected: %s, but got: %s
|
||||||
|
ChallengeMethodErr = Challenge method should be S256
|
||||||
|
CanNotUnlinkUsers = You are not the global admin, you can't unlink other users
|
||||||
|
CanNotLinkMySelf = You can't unlink yourself, you are not a member of any application
|
||||||
|
CallWebAuthnSigninBegin = Please call WebAuthnSigninBegin first
|
||||||
|
NotHuman = Turing test failed.
|
||||||
|
Unauthorized = Unauthorized operation
|
||||||
|
WrongPasswordManyTimes = WrongPasswordManyTimes
|
||||||
|
|
||||||
|
[CasErr]
|
||||||
|
ServiceDoNotMatch = Service %s and %s do not match
|
||||||
|
|
||||||
|
[EmailErr]
|
||||||
|
ExistedErr = Email already exists
|
||||||
|
EmptyErr = Email cannot be empty
|
||||||
|
EmailInvalid = Email is invalid
|
||||||
|
EmailCheckResult = Email: %s
|
||||||
|
EmptyParam = Empty parameters for emailForm: %v
|
||||||
|
InvalidReceivers = Invalid Email receivers: %s
|
||||||
|
UnableGetModifyRule = Unable to get the email modify rule.
|
||||||
|
|
||||||
|
[EnforcerErr]
|
||||||
|
SignInFirst = Please sign in first
|
||||||
|
|
||||||
|
[InitErr]
|
||||||
|
InitScoreFailed = Get init score failed, error: %%w
|
||||||
|
|
||||||
|
[LdapErr]
|
||||||
|
MultipleAccounts = Multiple accounts with same uid, please check your ldap server
|
||||||
|
PasswordWrong = Ldap user name or password incorrect
|
||||||
|
ServerExisted = Ldap server exist
|
||||||
|
|
||||||
|
[LoginErr]
|
||||||
|
AppDoNotExist = The application: %s does not exist
|
||||||
|
AppNotEnableSignUp = The account for provider: %s and username: %s (%s) does not exist and is not allowed to sign up as new account, please contact your IT support
|
||||||
|
AccountDoNotExist = The account does not exist
|
||||||
|
InvalidUserInformation = Failed to create user, user information is invalid: %s
|
||||||
|
LoginFirst = Please login first
|
||||||
|
LoginFail = Failed to login in: %s
|
||||||
|
NoPermission = You don't have the permission to do this
|
||||||
|
OldUser = The account for provider: %s and username: %s (%s) is already linked to another account: %s (%s)
|
||||||
|
ProviderCanNotSignUp = The account for provider: %s and username: %s (%s) does not exist and is not allowed to sign up as new account via %%s, please use another way to sign up
|
||||||
|
SessionOutdated = Session outdated, please login again
|
||||||
|
SignOutFirst = Please sign out first before signing in
|
||||||
|
UserDoNotExist = The user: %s/%s doesn't exist
|
||||||
|
UserIsForbidden = The user is forbidden to sign in, please contact the administrator
|
||||||
|
UnknownAuthentication = Unknown authentication type (not password or provider), form = %s
|
||||||
|
UnsupportedPasswordType = unsupported password type: %s
|
||||||
|
|
||||||
|
[OrgErr]
|
||||||
|
DoNotExist = Organization does not exist
|
||||||
|
Immutable = The %s is immutable.
|
||||||
|
OnlyAdmin = Only admin can modify the %s.
|
||||||
|
UnknownModifyRule = Unknown modify rule %s.
|
||||||
|
|
||||||
|
[ParameterErr]
|
||||||
|
OrgMissingErr = Parameter organization is missing
|
||||||
|
Missing = Missing parameter
|
||||||
|
UnknownType = Unknown type
|
||||||
|
Wrong = Wrong parameter
|
||||||
|
|
||||||
|
[PhoneErr]
|
||||||
|
CodeNotSent = Code has not been sent yet!
|
||||||
|
CodeTimeOut = You should verify your code in %d min!
|
||||||
|
ExistedErr = Phone already exists
|
||||||
|
EmptyErr = Phone cannot be empty
|
||||||
|
InvalidReceivers = Invalid phone receivers: %s
|
||||||
|
NumberInvalid = Phone number is invalid
|
||||||
|
NoPrefix = %s No phone prefix
|
||||||
|
PhoneCheckResult = Phone: %s
|
||||||
|
UnableGetModifyRule = Unable to get the phone modify rule.
|
||||||
|
|
||||||
|
[ProviderErr]
|
||||||
|
CanNotBeUnlinked = This provider can't be unlinked
|
||||||
|
CategoryNotSAML = provider %s's category is not SAML
|
||||||
|
DoNotExist = the provider: %s does not exist
|
||||||
|
InvalidProvider = Invalid captcha provider.
|
||||||
|
LinkFirstErr = Please link first
|
||||||
|
ProviderNotEnabled = The provider: %s is not enabled for the application
|
||||||
|
ProviderNotSupported = The provider type: %s is not supported
|
||||||
|
ProviderNotFound = The provider: %s is not found
|
||||||
|
ProviderNotFoundForCategory = No provider for category: %s is found for application: %s
|
||||||
|
|
||||||
|
[ResourceErr]
|
||||||
|
NotAuthorized = You are not authorized to access this resource
|
||||||
|
UserIsNil = User is nil for tag: /"avatar/"
|
||||||
|
UsernameOrFilePathEmpty = Username or fullFilePath is empty: username = %s, fullFilePath = %s
|
||||||
|
|
||||||
|
[SetPasswordErr]
|
||||||
|
CanNotContainBlank = New password cannot contain blank space.
|
||||||
|
LessThanSixCharacters = New password must have at least 6 characters
|
||||||
|
|
||||||
|
[SignUpErr]
|
||||||
|
DoNotAllowSignUp = The application does not allow to sign up new account
|
||||||
|
SignOutFirst = Please sign out first before signing up
|
||||||
|
|
||||||
|
[StorageErr]
|
||||||
|
ObjectKeyNotAllowed = The objectKey: %s is not allowed
|
||||||
|
|
||||||
|
[TokenErr]
|
||||||
|
EmptyClientID = Empty clientId or clientSecret
|
||||||
|
InvalidToken = Invalid token
|
||||||
|
InvalidAppOrWrongClientSecret = Invalid application or wrong clientSecret
|
||||||
|
InvalidClientId = Invalid client_id
|
||||||
|
RedirectURIDoNotExist = Redirect URI: %s doesn't exist in the allowed Redirect URI list
|
||||||
|
|
||||||
|
[UserErr]
|
||||||
|
AffiliationBlankErr = Affiliation cannot be blank
|
||||||
|
DisplayNameBlankErr = DisplayName cannot be blank
|
||||||
|
DisplayNameInvalid = DisplayName is not valid real name
|
||||||
|
DisplayNameCanNotBeEmpty = Display name cannot be empty
|
||||||
|
DoNotExist = The user: %s doesn't exist
|
||||||
|
DoNotExistInOrg = The user: %s/%s doesn't exist
|
||||||
|
DoNotExistSignUp = the user does not exist, please sign up first
|
||||||
|
FirstNameBlankErr = FirstName cannot be blank
|
||||||
|
FailToImportUsers = Failed to import users
|
||||||
|
LastNameBlankErr = LastName cannot be blank
|
||||||
|
NameLessThanTwoCharacters = Username must have at least 2 characters
|
||||||
|
NameStartWithADigitErr = Username cannot start with a digit
|
||||||
|
NameIsEmailErr = Username cannot be an email address
|
||||||
|
NameCantainWhitSpaceErr = Username cannot contain white spaces
|
||||||
|
NameExistedErr = Username already exists
|
||||||
|
NameEmptyErr = Empty username.
|
||||||
|
NameTooLang = Username is too long (maximum is 39 characters).
|
||||||
|
NameFormatErr = 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.
|
||||||
|
PasswordLessThanSixCharacters = Password must have at least 6 characters
|
||||||
|
InvalidInformation = Invalid information
|
||||||
|
NoWebAuthnCredential = Found no credentials for this user
|
||||||
|
|
138
i18n/languages/locale_fr.ini
Normal file
138
i18n/languages/locale_fr.ini
Normal file
@ -0,0 +1,138 @@
|
|||||||
|
[ApplicationErr]
|
||||||
|
AppNotFound = Application %s not found
|
||||||
|
AppNotFoundForUserID = No application is found for userId: %s
|
||||||
|
GrantTypeNotSupport = Grant_type: %s is not supported in this application
|
||||||
|
HasNoProviders = This application has no providers
|
||||||
|
HasNoProvidersOfType = This application has no providers of type
|
||||||
|
InvalidID = Invalid application id
|
||||||
|
|
||||||
|
[AuthErr]
|
||||||
|
AuthStateWrong = State expected: %s, but got: %s
|
||||||
|
ChallengeMethodErr = Challenge method should be S256
|
||||||
|
CanNotUnlinkUsers = You are not the global admin, you can't unlink other users
|
||||||
|
CanNotLinkMySelf = You can't unlink yourself, you are not a member of any application
|
||||||
|
CallWebAuthnSigninBegin = Please call WebAuthnSigninBegin first
|
||||||
|
NotHuman = Turing test failed.
|
||||||
|
Unauthorized = Unauthorized operation
|
||||||
|
WrongPasswordManyTimes = WrongPasswordManyTimes
|
||||||
|
|
||||||
|
[CasErr]
|
||||||
|
ServiceDoNotMatch = Service %s and %s do not match
|
||||||
|
|
||||||
|
[EmailErr]
|
||||||
|
ExistedErr = Email already exists
|
||||||
|
EmptyErr = Email cannot be empty
|
||||||
|
EmailInvalid = Email is invalid
|
||||||
|
EmailCheckResult = Email: %s
|
||||||
|
EmptyParam = Empty parameters for emailForm: %v
|
||||||
|
InvalidReceivers = Invalid Email receivers: %s
|
||||||
|
UnableGetModifyRule = Unable to get the email modify rule.
|
||||||
|
|
||||||
|
[EnforcerErr]
|
||||||
|
SignInFirst = Please sign in first
|
||||||
|
|
||||||
|
[InitErr]
|
||||||
|
InitScoreFailed = Get init score failed, error: %%w
|
||||||
|
|
||||||
|
[LdapErr]
|
||||||
|
MultipleAccounts = Multiple accounts with same uid, please check your ldap server
|
||||||
|
PasswordWrong = Ldap user name or password incorrect
|
||||||
|
ServerExisted = Ldap server exist
|
||||||
|
|
||||||
|
[LoginErr]
|
||||||
|
AppDoNotExist = The application: %s does not exist
|
||||||
|
AppNotEnableSignUp = The account for provider: %s and username: %s (%s) does not exist and is not allowed to sign up as new account, please contact your IT support
|
||||||
|
AccountDoNotExist = The account does not exist
|
||||||
|
InvalidUserInformation = Failed to create user, user information is invalid: %s
|
||||||
|
LoginFirst = Please login first
|
||||||
|
LoginFail = Failed to login in: %s
|
||||||
|
NoPermission = You don't have the permission to do this
|
||||||
|
OldUser = The account for provider: %s and username: %s (%s) is already linked to another account: %s (%s)
|
||||||
|
ProviderCanNotSignUp = The account for provider: %s and username: %s (%s) does not exist and is not allowed to sign up as new account via %%s, please use another way to sign up
|
||||||
|
SessionOutdated = Session outdated, please login again
|
||||||
|
SignOutFirst = Please sign out first before signing in
|
||||||
|
UserDoNotExist = The user: %s/%s doesn't exist
|
||||||
|
UserIsForbidden = The user is forbidden to sign in, please contact the administrator
|
||||||
|
UnknownAuthentication = Unknown authentication type (not password or provider), form = %s
|
||||||
|
UnsupportedPasswordType = unsupported password type: %s
|
||||||
|
|
||||||
|
[OrgErr]
|
||||||
|
DoNotExist = Organization does not exist
|
||||||
|
Immutable = The %s is immutable.
|
||||||
|
OnlyAdmin = Only admin can modify the %s.
|
||||||
|
UnknownModifyRule = Unknown modify rule %s.
|
||||||
|
|
||||||
|
[ParameterErr]
|
||||||
|
OrgMissingErr = Parameter organization is missing
|
||||||
|
Missing = Missing parameter
|
||||||
|
UnknownType = Unknown type
|
||||||
|
Wrong = Wrong parameter
|
||||||
|
|
||||||
|
[PhoneErr]
|
||||||
|
CodeNotSent = Code has not been sent yet!
|
||||||
|
CodeTimeOut = You should verify your code in %d min!
|
||||||
|
ExistedErr = Phone already exists
|
||||||
|
EmptyErr = Phone cannot be empty
|
||||||
|
InvalidReceivers = Invalid phone receivers: %s
|
||||||
|
NumberInvalid = Phone number is invalid
|
||||||
|
NoPrefix = %s No phone prefix
|
||||||
|
PhoneCheckResult = Phone: %s
|
||||||
|
UnableGetModifyRule = Unable to get the phone modify rule.
|
||||||
|
|
||||||
|
[ProviderErr]
|
||||||
|
CanNotBeUnlinked = This provider can't be unlinked
|
||||||
|
CategoryNotSAML = provider %s's category is not SAML
|
||||||
|
DoNotExist = the provider: %s does not exist
|
||||||
|
InvalidProvider = Invalid captcha provider.
|
||||||
|
LinkFirstErr = Please link first
|
||||||
|
ProviderNotEnabled = The provider: %s is not enabled for the application
|
||||||
|
ProviderNotSupported = The provider type: %s is not supported
|
||||||
|
ProviderNotFound = The provider: %s is not found
|
||||||
|
ProviderNotFoundForCategory = No provider for category: %s is found for application: %s
|
||||||
|
|
||||||
|
[ResourceErr]
|
||||||
|
NotAuthorized = You are not authorized to access this resource
|
||||||
|
UserIsNil = User is nil for tag: /"avatar/"
|
||||||
|
UsernameOrFilePathEmpty = Username or fullFilePath is empty: username = %s, fullFilePath = %s
|
||||||
|
|
||||||
|
[SetPasswordErr]
|
||||||
|
CanNotContainBlank = New password cannot contain blank space.
|
||||||
|
LessThanSixCharacters = New password must have at least 6 characters
|
||||||
|
|
||||||
|
[SignUpErr]
|
||||||
|
DoNotAllowSignUp = The application does not allow to sign up new account
|
||||||
|
SignOutFirst = Please sign out first before signing up
|
||||||
|
|
||||||
|
[StorageErr]
|
||||||
|
ObjectKeyNotAllowed = The objectKey: %s is not allowed
|
||||||
|
|
||||||
|
[TokenErr]
|
||||||
|
EmptyClientID = Empty clientId or clientSecret
|
||||||
|
InvalidToken = Invalid token
|
||||||
|
InvalidAppOrWrongClientSecret = Invalid application or wrong clientSecret
|
||||||
|
InvalidClientId = Invalid client_id
|
||||||
|
RedirectURIDoNotExist = Redirect URI: %s doesn't exist in the allowed Redirect URI list
|
||||||
|
|
||||||
|
[UserErr]
|
||||||
|
AffiliationBlankErr = Affiliation cannot be blank
|
||||||
|
DisplayNameBlankErr = DisplayName cannot be blank
|
||||||
|
DisplayNameInvalid = DisplayName is not valid real name
|
||||||
|
DisplayNameCanNotBeEmpty = Display name cannot be empty
|
||||||
|
DoNotExist = The user: %s doesn't exist
|
||||||
|
DoNotExistInOrg = The user: %s/%s doesn't exist
|
||||||
|
DoNotExistSignUp = the user does not exist, please sign up first
|
||||||
|
FirstNameBlankErr = FirstName cannot be blank
|
||||||
|
FailToImportUsers = Failed to import users
|
||||||
|
LastNameBlankErr = LastName cannot be blank
|
||||||
|
NameLessThanTwoCharacters = Username must have at least 2 characters
|
||||||
|
NameStartWithADigitErr = Username cannot start with a digit
|
||||||
|
NameIsEmailErr = Username cannot be an email address
|
||||||
|
NameCantainWhitSpaceErr = Username cannot contain white spaces
|
||||||
|
NameExistedErr = Username already exists
|
||||||
|
NameEmptyErr = Empty username.
|
||||||
|
NameTooLang = Username is too long (maximum is 39 characters).
|
||||||
|
NameFormatErr = 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.
|
||||||
|
PasswordLessThanSixCharacters = Password must have at least 6 characters
|
||||||
|
InvalidInformation = Invalid information
|
||||||
|
NoWebAuthnCredential = Found no credentials for this user
|
||||||
|
|
138
i18n/languages/locale_ja.ini
Normal file
138
i18n/languages/locale_ja.ini
Normal file
@ -0,0 +1,138 @@
|
|||||||
|
[ApplicationErr]
|
||||||
|
AppNotFound = Application %s not found
|
||||||
|
AppNotFoundForUserID = No application is found for userId: %s
|
||||||
|
GrantTypeNotSupport = Grant_type: %s is not supported in this application
|
||||||
|
HasNoProviders = This application has no providers
|
||||||
|
HasNoProvidersOfType = This application has no providers of type
|
||||||
|
InvalidID = Invalid application id
|
||||||
|
|
||||||
|
[AuthErr]
|
||||||
|
AuthStateWrong = State expected: %s, but got: %s
|
||||||
|
ChallengeMethodErr = Challenge method should be S256
|
||||||
|
CanNotUnlinkUsers = You are not the global admin, you can't unlink other users
|
||||||
|
CanNotLinkMySelf = You can't unlink yourself, you are not a member of any application
|
||||||
|
CallWebAuthnSigninBegin = Please call WebAuthnSigninBegin first
|
||||||
|
NotHuman = Turing test failed.
|
||||||
|
Unauthorized = Unauthorized operation
|
||||||
|
WrongPasswordManyTimes = WrongPasswordManyTimes
|
||||||
|
|
||||||
|
[CasErr]
|
||||||
|
ServiceDoNotMatch = Service %s and %s do not match
|
||||||
|
|
||||||
|
[EmailErr]
|
||||||
|
ExistedErr = Email already exists
|
||||||
|
EmptyErr = Email cannot be empty
|
||||||
|
EmailInvalid = Email is invalid
|
||||||
|
EmailCheckResult = Email: %s
|
||||||
|
EmptyParam = Empty parameters for emailForm: %v
|
||||||
|
InvalidReceivers = Invalid Email receivers: %s
|
||||||
|
UnableGetModifyRule = Unable to get the email modify rule.
|
||||||
|
|
||||||
|
[EnforcerErr]
|
||||||
|
SignInFirst = Please sign in first
|
||||||
|
|
||||||
|
[InitErr]
|
||||||
|
InitScoreFailed = Get init score failed, error: %%w
|
||||||
|
|
||||||
|
[LdapErr]
|
||||||
|
MultipleAccounts = Multiple accounts with same uid, please check your ldap server
|
||||||
|
PasswordWrong = Ldap user name or password incorrect
|
||||||
|
ServerExisted = Ldap server exist
|
||||||
|
|
||||||
|
[LoginErr]
|
||||||
|
AppDoNotExist = The application: %s does not exist
|
||||||
|
AppNotEnableSignUp = The account for provider: %s and username: %s (%s) does not exist and is not allowed to sign up as new account, please contact your IT support
|
||||||
|
AccountDoNotExist = The account does not exist
|
||||||
|
InvalidUserInformation = Failed to create user, user information is invalid: %s
|
||||||
|
LoginFirst = Please login first
|
||||||
|
LoginFail = Failed to login in: %s
|
||||||
|
NoPermission = You don't have the permission to do this
|
||||||
|
OldUser = The account for provider: %s and username: %s (%s) is already linked to another account: %s (%s)
|
||||||
|
ProviderCanNotSignUp = The account for provider: %s and username: %s (%s) does not exist and is not allowed to sign up as new account via %%s, please use another way to sign up
|
||||||
|
SessionOutdated = Session outdated, please login again
|
||||||
|
SignOutFirst = Please sign out first before signing in
|
||||||
|
UserDoNotExist = The user: %s/%s doesn't exist
|
||||||
|
UserIsForbidden = The user is forbidden to sign in, please contact the administrator
|
||||||
|
UnknownAuthentication = Unknown authentication type (not password or provider), form = %s
|
||||||
|
UnsupportedPasswordType = unsupported password type: %s
|
||||||
|
|
||||||
|
[OrgErr]
|
||||||
|
DoNotExist = Organization does not exist
|
||||||
|
Immutable = The %s is immutable.
|
||||||
|
OnlyAdmin = Only admin can modify the %s.
|
||||||
|
UnknownModifyRule = Unknown modify rule %s.
|
||||||
|
|
||||||
|
[ParameterErr]
|
||||||
|
OrgMissingErr = Parameter organization is missing
|
||||||
|
Missing = Missing parameter
|
||||||
|
UnknownType = Unknown type
|
||||||
|
Wrong = Wrong parameter
|
||||||
|
|
||||||
|
[PhoneErr]
|
||||||
|
CodeNotSent = Code has not been sent yet!
|
||||||
|
CodeTimeOut = You should verify your code in %d min!
|
||||||
|
ExistedErr = Phone already exists
|
||||||
|
EmptyErr = Phone cannot be empty
|
||||||
|
InvalidReceivers = Invalid phone receivers: %s
|
||||||
|
NumberInvalid = Phone number is invalid
|
||||||
|
NoPrefix = %s No phone prefix
|
||||||
|
PhoneCheckResult = Phone: %s
|
||||||
|
UnableGetModifyRule = Unable to get the phone modify rule.
|
||||||
|
|
||||||
|
[ProviderErr]
|
||||||
|
CanNotBeUnlinked = This provider can't be unlinked
|
||||||
|
CategoryNotSAML = provider %s's category is not SAML
|
||||||
|
DoNotExist = the provider: %s does not exist
|
||||||
|
InvalidProvider = Invalid captcha provider.
|
||||||
|
LinkFirstErr = Please link first
|
||||||
|
ProviderNotEnabled = The provider: %s is not enabled for the application
|
||||||
|
ProviderNotSupported = The provider type: %s is not supported
|
||||||
|
ProviderNotFound = The provider: %s is not found
|
||||||
|
ProviderNotFoundForCategory = No provider for category: %s is found for application: %s
|
||||||
|
|
||||||
|
[ResourceErr]
|
||||||
|
NotAuthorized = You are not authorized to access this resource
|
||||||
|
UserIsNil = User is nil for tag: /"avatar/"
|
||||||
|
UsernameOrFilePathEmpty = Username or fullFilePath is empty: username = %s, fullFilePath = %s
|
||||||
|
|
||||||
|
[SetPasswordErr]
|
||||||
|
CanNotContainBlank = New password cannot contain blank space.
|
||||||
|
LessThanSixCharacters = New password must have at least 6 characters
|
||||||
|
|
||||||
|
[SignUpErr]
|
||||||
|
DoNotAllowSignUp = The application does not allow to sign up new account
|
||||||
|
SignOutFirst = Please sign out first before signing up
|
||||||
|
|
||||||
|
[StorageErr]
|
||||||
|
ObjectKeyNotAllowed = The objectKey: %s is not allowed
|
||||||
|
|
||||||
|
[TokenErr]
|
||||||
|
EmptyClientID = Empty clientId or clientSecret
|
||||||
|
InvalidToken = Invalid token
|
||||||
|
InvalidAppOrWrongClientSecret = Invalid application or wrong clientSecret
|
||||||
|
InvalidClientId = Invalid client_id
|
||||||
|
RedirectURIDoNotExist = Redirect URI: %s doesn't exist in the allowed Redirect URI list
|
||||||
|
|
||||||
|
[UserErr]
|
||||||
|
AffiliationBlankErr = Affiliation cannot be blank
|
||||||
|
DisplayNameBlankErr = DisplayName cannot be blank
|
||||||
|
DisplayNameInvalid = DisplayName is not valid real name
|
||||||
|
DisplayNameCanNotBeEmpty = Display name cannot be empty
|
||||||
|
DoNotExist = The user: %s doesn't exist
|
||||||
|
DoNotExistInOrg = The user: %s/%s doesn't exist
|
||||||
|
DoNotExistSignUp = the user does not exist, please sign up first
|
||||||
|
FirstNameBlankErr = FirstName cannot be blank
|
||||||
|
FailToImportUsers = Failed to import users
|
||||||
|
LastNameBlankErr = LastName cannot be blank
|
||||||
|
NameLessThanTwoCharacters = Username must have at least 2 characters
|
||||||
|
NameStartWithADigitErr = Username cannot start with a digit
|
||||||
|
NameIsEmailErr = Username cannot be an email address
|
||||||
|
NameCantainWhitSpaceErr = Username cannot contain white spaces
|
||||||
|
NameExistedErr = Username already exists
|
||||||
|
NameEmptyErr = Empty username.
|
||||||
|
NameTooLang = Username is too long (maximum is 39 characters).
|
||||||
|
NameFormatErr = 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.
|
||||||
|
PasswordLessThanSixCharacters = Password must have at least 6 characters
|
||||||
|
InvalidInformation = Invalid information
|
||||||
|
NoWebAuthnCredential = Found no credentials for this user
|
||||||
|
|
138
i18n/languages/locale_ko.ini
Normal file
138
i18n/languages/locale_ko.ini
Normal file
@ -0,0 +1,138 @@
|
|||||||
|
[ApplicationErr]
|
||||||
|
AppNotFound = Application %s not found
|
||||||
|
AppNotFoundForUserID = No application is found for userId: %s
|
||||||
|
GrantTypeNotSupport = Grant_type: %s is not supported in this application
|
||||||
|
HasNoProviders = This application has no providers
|
||||||
|
HasNoProvidersOfType = This application has no providers of type
|
||||||
|
InvalidID = Invalid application id
|
||||||
|
|
||||||
|
[AuthErr]
|
||||||
|
AuthStateWrong = State expected: %s, but got: %s
|
||||||
|
ChallengeMethodErr = Challenge method should be S256
|
||||||
|
CanNotUnlinkUsers = You are not the global admin, you can't unlink other users
|
||||||
|
CanNotLinkMySelf = You can't unlink yourself, you are not a member of any application
|
||||||
|
CallWebAuthnSigninBegin = Please call WebAuthnSigninBegin first
|
||||||
|
NotHuman = Turing test failed.
|
||||||
|
Unauthorized = Unauthorized operation
|
||||||
|
WrongPasswordManyTimes = WrongPasswordManyTimes
|
||||||
|
|
||||||
|
[CasErr]
|
||||||
|
ServiceDoNotMatch = Service %s and %s do not match
|
||||||
|
|
||||||
|
[EmailErr]
|
||||||
|
ExistedErr = Email already exists
|
||||||
|
EmptyErr = Email cannot be empty
|
||||||
|
EmailInvalid = Email is invalid
|
||||||
|
EmailCheckResult = Email: %s
|
||||||
|
EmptyParam = Empty parameters for emailForm: %v
|
||||||
|
InvalidReceivers = Invalid Email receivers: %s
|
||||||
|
UnableGetModifyRule = Unable to get the email modify rule.
|
||||||
|
|
||||||
|
[EnforcerErr]
|
||||||
|
SignInFirst = Please sign in first
|
||||||
|
|
||||||
|
[InitErr]
|
||||||
|
InitScoreFailed = Get init score failed, error: %%w
|
||||||
|
|
||||||
|
[LdapErr]
|
||||||
|
MultipleAccounts = Multiple accounts with same uid, please check your ldap server
|
||||||
|
PasswordWrong = Ldap user name or password incorrect
|
||||||
|
ServerExisted = Ldap server exist
|
||||||
|
|
||||||
|
[LoginErr]
|
||||||
|
AppDoNotExist = The application: %s does not exist
|
||||||
|
AppNotEnableSignUp = The account for provider: %s and username: %s (%s) does not exist and is not allowed to sign up as new account, please contact your IT support
|
||||||
|
AccountDoNotExist = The account does not exist
|
||||||
|
InvalidUserInformation = Failed to create user, user information is invalid: %s
|
||||||
|
LoginFirst = Please login first
|
||||||
|
LoginFail = Failed to login in: %s
|
||||||
|
NoPermission = You don't have the permission to do this
|
||||||
|
OldUser = The account for provider: %s and username: %s (%s) is already linked to another account: %s (%s)
|
||||||
|
ProviderCanNotSignUp = The account for provider: %s and username: %s (%s) does not exist and is not allowed to sign up as new account via %%s, please use another way to sign up
|
||||||
|
SessionOutdated = Session outdated, please login again
|
||||||
|
SignOutFirst = Please sign out first before signing in
|
||||||
|
UserDoNotExist = The user: %s/%s doesn't exist
|
||||||
|
UserIsForbidden = The user is forbidden to sign in, please contact the administrator
|
||||||
|
UnknownAuthentication = Unknown authentication type (not password or provider), form = %s
|
||||||
|
UnsupportedPasswordType = unsupported password type: %s
|
||||||
|
|
||||||
|
[OrgErr]
|
||||||
|
DoNotExist = Organization does not exist
|
||||||
|
Immutable = The %s is immutable.
|
||||||
|
OnlyAdmin = Only admin can modify the %s.
|
||||||
|
UnknownModifyRule = Unknown modify rule %s.
|
||||||
|
|
||||||
|
[ParameterErr]
|
||||||
|
OrgMissingErr = Parameter organization is missing
|
||||||
|
Missing = Missing parameter
|
||||||
|
UnknownType = Unknown type
|
||||||
|
Wrong = Wrong parameter
|
||||||
|
|
||||||
|
[PhoneErr]
|
||||||
|
CodeNotSent = Code has not been sent yet!
|
||||||
|
CodeTimeOut = You should verify your code in %d min!
|
||||||
|
ExistedErr = Phone already exists
|
||||||
|
EmptyErr = Phone cannot be empty
|
||||||
|
InvalidReceivers = Invalid phone receivers: %s
|
||||||
|
NumberInvalid = Phone number is invalid
|
||||||
|
NoPrefix = %s No phone prefix
|
||||||
|
PhoneCheckResult = Phone: %s
|
||||||
|
UnableGetModifyRule = Unable to get the phone modify rule.
|
||||||
|
|
||||||
|
[ProviderErr]
|
||||||
|
CanNotBeUnlinked = This provider can't be unlinked
|
||||||
|
CategoryNotSAML = provider %s's category is not SAML
|
||||||
|
DoNotExist = the provider: %s does not exist
|
||||||
|
InvalidProvider = Invalid captcha provider.
|
||||||
|
LinkFirstErr = Please link first
|
||||||
|
ProviderNotEnabled = The provider: %s is not enabled for the application
|
||||||
|
ProviderNotSupported = The provider type: %s is not supported
|
||||||
|
ProviderNotFound = The provider: %s is not found
|
||||||
|
ProviderNotFoundForCategory = No provider for category: %s is found for application: %s
|
||||||
|
|
||||||
|
[ResourceErr]
|
||||||
|
NotAuthorized = You are not authorized to access this resource
|
||||||
|
UserIsNil = User is nil for tag: /"avatar/"
|
||||||
|
UsernameOrFilePathEmpty = Username or fullFilePath is empty: username = %s, fullFilePath = %s
|
||||||
|
|
||||||
|
[SetPasswordErr]
|
||||||
|
CanNotContainBlank = New password cannot contain blank space.
|
||||||
|
LessThanSixCharacters = New password must have at least 6 characters
|
||||||
|
|
||||||
|
[SignUpErr]
|
||||||
|
DoNotAllowSignUp = The application does not allow to sign up new account
|
||||||
|
SignOutFirst = Please sign out first before signing up
|
||||||
|
|
||||||
|
[StorageErr]
|
||||||
|
ObjectKeyNotAllowed = The objectKey: %s is not allowed
|
||||||
|
|
||||||
|
[TokenErr]
|
||||||
|
EmptyClientID = Empty clientId or clientSecret
|
||||||
|
InvalidToken = Invalid token
|
||||||
|
InvalidAppOrWrongClientSecret = Invalid application or wrong clientSecret
|
||||||
|
InvalidClientId = Invalid client_id
|
||||||
|
RedirectURIDoNotExist = Redirect URI: %s doesn't exist in the allowed Redirect URI list
|
||||||
|
|
||||||
|
[UserErr]
|
||||||
|
AffiliationBlankErr = Affiliation cannot be blank
|
||||||
|
DisplayNameBlankErr = DisplayName cannot be blank
|
||||||
|
DisplayNameInvalid = DisplayName is not valid real name
|
||||||
|
DisplayNameCanNotBeEmpty = Display name cannot be empty
|
||||||
|
DoNotExist = The user: %s doesn't exist
|
||||||
|
DoNotExistInOrg = The user: %s/%s doesn't exist
|
||||||
|
DoNotExistSignUp = the user does not exist, please sign up first
|
||||||
|
FirstNameBlankErr = FirstName cannot be blank
|
||||||
|
FailToImportUsers = Failed to import users
|
||||||
|
LastNameBlankErr = LastName cannot be blank
|
||||||
|
NameLessThanTwoCharacters = Username must have at least 2 characters
|
||||||
|
NameStartWithADigitErr = Username cannot start with a digit
|
||||||
|
NameIsEmailErr = Username cannot be an email address
|
||||||
|
NameCantainWhitSpaceErr = Username cannot contain white spaces
|
||||||
|
NameExistedErr = Username already exists
|
||||||
|
NameEmptyErr = Empty username.
|
||||||
|
NameTooLang = Username is too long (maximum is 39 characters).
|
||||||
|
NameFormatErr = 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.
|
||||||
|
PasswordLessThanSixCharacters = Password must have at least 6 characters
|
||||||
|
InvalidInformation = Invalid information
|
||||||
|
NoWebAuthnCredential = Found no credentials for this user
|
||||||
|
|
138
i18n/languages/locale_ru.ini
Normal file
138
i18n/languages/locale_ru.ini
Normal file
@ -0,0 +1,138 @@
|
|||||||
|
[ApplicationErr]
|
||||||
|
AppNotFound = Application %s not found
|
||||||
|
AppNotFoundForUserID = No application is found for userId: %s
|
||||||
|
GrantTypeNotSupport = Grant_type: %s is not supported in this application
|
||||||
|
HasNoProviders = This application has no providers
|
||||||
|
HasNoProvidersOfType = This application has no providers of type
|
||||||
|
InvalidID = Invalid application id
|
||||||
|
|
||||||
|
[AuthErr]
|
||||||
|
AuthStateWrong = State expected: %s, but got: %s
|
||||||
|
ChallengeMethodErr = Challenge method should be S256
|
||||||
|
CanNotUnlinkUsers = You are not the global admin, you can't unlink other users
|
||||||
|
CanNotLinkMySelf = You can't unlink yourself, you are not a member of any application
|
||||||
|
CallWebAuthnSigninBegin = Please call WebAuthnSigninBegin first
|
||||||
|
NotHuman = Turing test failed.
|
||||||
|
Unauthorized = Unauthorized operation
|
||||||
|
WrongPasswordManyTimes = WrongPasswordManyTimes
|
||||||
|
|
||||||
|
[CasErr]
|
||||||
|
ServiceDoNotMatch = Service %s and %s do not match
|
||||||
|
|
||||||
|
[EmailErr]
|
||||||
|
ExistedErr = Email already exists
|
||||||
|
EmptyErr = Email cannot be empty
|
||||||
|
EmailInvalid = Email is invalid
|
||||||
|
EmailCheckResult = Email: %s
|
||||||
|
EmptyParam = Empty parameters for emailForm: %v
|
||||||
|
InvalidReceivers = Invalid Email receivers: %s
|
||||||
|
UnableGetModifyRule = Unable to get the email modify rule.
|
||||||
|
|
||||||
|
[EnforcerErr]
|
||||||
|
SignInFirst = Please sign in first
|
||||||
|
|
||||||
|
[InitErr]
|
||||||
|
InitScoreFailed = Get init score failed, error: %%w
|
||||||
|
|
||||||
|
[LdapErr]
|
||||||
|
MultipleAccounts = Multiple accounts with same uid, please check your ldap server
|
||||||
|
PasswordWrong = Ldap user name or password incorrect
|
||||||
|
ServerExisted = Ldap server exist
|
||||||
|
|
||||||
|
[LoginErr]
|
||||||
|
AppDoNotExist = The application: %s does not exist
|
||||||
|
AppNotEnableSignUp = The account for provider: %s and username: %s (%s) does not exist and is not allowed to sign up as new account, please contact your IT support
|
||||||
|
AccountDoNotExist = The account does not exist
|
||||||
|
InvalidUserInformation = Failed to create user, user information is invalid: %s
|
||||||
|
LoginFirst = Please login first
|
||||||
|
LoginFail = Failed to login in: %s
|
||||||
|
NoPermission = You don't have the permission to do this
|
||||||
|
OldUser = The account for provider: %s and username: %s (%s) is already linked to another account: %s (%s)
|
||||||
|
ProviderCanNotSignUp = The account for provider: %s and username: %s (%s) does not exist and is not allowed to sign up as new account via %%s, please use another way to sign up
|
||||||
|
SessionOutdated = Session outdated, please login again
|
||||||
|
SignOutFirst = Please sign out first before signing in
|
||||||
|
UserDoNotExist = The user: %s/%s doesn't exist
|
||||||
|
UserIsForbidden = The user is forbidden to sign in, please contact the administrator
|
||||||
|
UnknownAuthentication = Unknown authentication type (not password or provider), form = %s
|
||||||
|
UnsupportedPasswordType = unsupported password type: %s
|
||||||
|
|
||||||
|
[OrgErr]
|
||||||
|
DoNotExist = Organization does not exist
|
||||||
|
Immutable = The %s is immutable.
|
||||||
|
OnlyAdmin = Only admin can modify the %s.
|
||||||
|
UnknownModifyRule = Unknown modify rule %s.
|
||||||
|
|
||||||
|
[ParameterErr]
|
||||||
|
OrgMissingErr = Parameter organization is missing
|
||||||
|
Missing = Missing parameter
|
||||||
|
UnknownType = Unknown type
|
||||||
|
Wrong = Wrong parameter
|
||||||
|
|
||||||
|
[PhoneErr]
|
||||||
|
CodeNotSent = Code has not been sent yet!
|
||||||
|
CodeTimeOut = You should verify your code in %d min!
|
||||||
|
ExistedErr = Phone already exists
|
||||||
|
EmptyErr = Phone cannot be empty
|
||||||
|
InvalidReceivers = Invalid phone receivers: %s
|
||||||
|
NumberInvalid = Phone number is invalid
|
||||||
|
NoPrefix = %s No phone prefix
|
||||||
|
PhoneCheckResult = Phone: %s
|
||||||
|
UnableGetModifyRule = Unable to get the phone modify rule.
|
||||||
|
|
||||||
|
[ProviderErr]
|
||||||
|
CanNotBeUnlinked = This provider can't be unlinked
|
||||||
|
CategoryNotSAML = provider %s's category is not SAML
|
||||||
|
DoNotExist = the provider: %s does not exist
|
||||||
|
InvalidProvider = Invalid captcha provider.
|
||||||
|
LinkFirstErr = Please link first
|
||||||
|
ProviderNotEnabled = The provider: %s is not enabled for the application
|
||||||
|
ProviderNotSupported = The provider type: %s is not supported
|
||||||
|
ProviderNotFound = The provider: %s is not found
|
||||||
|
ProviderNotFoundForCategory = No provider for category: %s is found for application: %s
|
||||||
|
|
||||||
|
[ResourceErr]
|
||||||
|
NotAuthorized = You are not authorized to access this resource
|
||||||
|
UserIsNil = User is nil for tag: /"avatar/"
|
||||||
|
UsernameOrFilePathEmpty = Username or fullFilePath is empty: username = %s, fullFilePath = %s
|
||||||
|
|
||||||
|
[SetPasswordErr]
|
||||||
|
CanNotContainBlank = New password cannot contain blank space.
|
||||||
|
LessThanSixCharacters = New password must have at least 6 characters
|
||||||
|
|
||||||
|
[SignUpErr]
|
||||||
|
DoNotAllowSignUp = The application does not allow to sign up new account
|
||||||
|
SignOutFirst = Please sign out first before signing up
|
||||||
|
|
||||||
|
[StorageErr]
|
||||||
|
ObjectKeyNotAllowed = The objectKey: %s is not allowed
|
||||||
|
|
||||||
|
[TokenErr]
|
||||||
|
EmptyClientID = Empty clientId or clientSecret
|
||||||
|
InvalidToken = Invalid token
|
||||||
|
InvalidAppOrWrongClientSecret = Invalid application or wrong clientSecret
|
||||||
|
InvalidClientId = Invalid client_id
|
||||||
|
RedirectURIDoNotExist = Redirect URI: %s doesn't exist in the allowed Redirect URI list
|
||||||
|
|
||||||
|
[UserErr]
|
||||||
|
AffiliationBlankErr = Affiliation cannot be blank
|
||||||
|
DisplayNameBlankErr = DisplayName cannot be blank
|
||||||
|
DisplayNameInvalid = DisplayName is not valid real name
|
||||||
|
DisplayNameCanNotBeEmpty = Display name cannot be empty
|
||||||
|
DoNotExist = The user: %s doesn't exist
|
||||||
|
DoNotExistInOrg = The user: %s/%s doesn't exist
|
||||||
|
DoNotExistSignUp = the user does not exist, please sign up first
|
||||||
|
FirstNameBlankErr = FirstName cannot be blank
|
||||||
|
FailToImportUsers = Failed to import users
|
||||||
|
LastNameBlankErr = LastName cannot be blank
|
||||||
|
NameLessThanTwoCharacters = Username must have at least 2 characters
|
||||||
|
NameStartWithADigitErr = Username cannot start with a digit
|
||||||
|
NameIsEmailErr = Username cannot be an email address
|
||||||
|
NameCantainWhitSpaceErr = Username cannot contain white spaces
|
||||||
|
NameExistedErr = Username already exists
|
||||||
|
NameEmptyErr = Empty username.
|
||||||
|
NameTooLang = Username is too long (maximum is 39 characters).
|
||||||
|
NameFormatErr = 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.
|
||||||
|
PasswordLessThanSixCharacters = Password must have at least 6 characters
|
||||||
|
InvalidInformation = Invalid information
|
||||||
|
NoWebAuthnCredential = Found no credentials for this user
|
||||||
|
|
138
i18n/languages/locale_zh.ini
Normal file
138
i18n/languages/locale_zh.ini
Normal file
@ -0,0 +1,138 @@
|
|||||||
|
[ApplicationErr]
|
||||||
|
AppNotFound = 应用 %s 未找到
|
||||||
|
AppNotFoundForUserID = 找不到该用户的应用程序 %s
|
||||||
|
GrantTypeNotSupport = 此应用中不支持此授权类型
|
||||||
|
HasNoProviders = 该应用无提供商
|
||||||
|
HasNoProvidersOfType = 应用没有该类型的提供商
|
||||||
|
InvalidID = 无效的Application ID
|
||||||
|
|
||||||
|
[AuthErr]
|
||||||
|
AuthStateWrong = 期望状态位: %s, 实际状态为: %s
|
||||||
|
ChallengeMethodErr = Challenge 方法应该为 S256
|
||||||
|
CanNotUnlinkUsers = 您不是全局管理员,无法取消链接其他用户
|
||||||
|
CanNotLinkMySelf = 您无法取消链接,您不是任何应用程序的成员
|
||||||
|
CallWebAuthnSigninBegin = 请先调用WebAuthnSigninBegin
|
||||||
|
NotHuman = 真人验证失败
|
||||||
|
Unauthorized = 未授权的操作
|
||||||
|
WrongPasswordManyTimes = 输入密码错误次数已达上限,请在 %d 分 %d 秒后重试
|
||||||
|
|
||||||
|
[CasErr]
|
||||||
|
ServiceDoNotMatch = 服务 %s 与 %s 不匹配
|
||||||
|
|
||||||
|
[EmailErr]
|
||||||
|
ExistedErr = 该邮箱已存在
|
||||||
|
EmptyErr = 邮箱不可为空
|
||||||
|
EmailInvalid = 无效邮箱
|
||||||
|
EmailCheckResult = Email: %s
|
||||||
|
EmptyParam = 邮件参数为空: %v
|
||||||
|
InvalidReceivers = 无效的邮箱接收者: %s
|
||||||
|
UnableGetModifyRule = 无法得到Email修改规则
|
||||||
|
|
||||||
|
[EnforcerErr]
|
||||||
|
SignInFirst = 请先登录
|
||||||
|
|
||||||
|
[InitErr]
|
||||||
|
InitScoreFailed = 初始化分数失败: %w
|
||||||
|
|
||||||
|
[LdapErr]
|
||||||
|
MultipleAccounts = 多个帐户具有相同的uid,请检查您的 ldap 服务器
|
||||||
|
PasswordWrong = Ldap密码错误
|
||||||
|
ServerExisted = Ldap服务器已存在
|
||||||
|
|
||||||
|
[LoginErr]
|
||||||
|
AppDoNotExist = 应用不存在: %s
|
||||||
|
AppNotEnableSignUp = 提供商账户: %s 与用户名: %s (%s) 不存在且 不允许注册新账户, 请联系IT支持
|
||||||
|
AccountDoNotExist = 账户不存在
|
||||||
|
InvalidUserInformation = 创建用户失败,用户信息无效: %%s
|
||||||
|
LoginFirst = 请先登录
|
||||||
|
LoginFail = 无法登录: %s
|
||||||
|
NoPermission = 您没有权限执行此操作
|
||||||
|
OldUser = 提供商账户: %s 与用户名: %s (%s) 已经与其他账户绑定: %s (%s)
|
||||||
|
ProviderCanNotSignUp = 提供商账户: %s 与用户名: %s (%s) 不存在且 不允许通过 %s 注册新账户, 请使用其他方式注册
|
||||||
|
SignOutFirst = 请在登录前登出
|
||||||
|
SessionOutdated = Session已过期,请重新登陆
|
||||||
|
UserDoNotExist = 用户不存在: %s/%s
|
||||||
|
UserIsForbidden = 该用户被禁止登陆,请联系管理员
|
||||||
|
UnknownAuthentication = 未知的认证类型 (非密码或提供商认证), form = %s
|
||||||
|
UnsupportedPasswordType = 不支持此密码类型
|
||||||
|
|
||||||
|
[OrgErr]
|
||||||
|
DoNotExist = 组织不存在
|
||||||
|
Immutable = %s是不可变的
|
||||||
|
OnlyAdmin = 只有管理员用户有此权限
|
||||||
|
UnknownModifyRule = 未知的修改规则
|
||||||
|
|
||||||
|
[ParameterErr]
|
||||||
|
Missing = 参数丢失
|
||||||
|
OrgMissingErr = Organization参数丢失
|
||||||
|
UnknownType = 未知类型
|
||||||
|
Wrong = 参数错误
|
||||||
|
|
||||||
|
[PhoneErr]
|
||||||
|
CodeNotSent = 验证码还未发送
|
||||||
|
CodeTimeOut = 验证码过期
|
||||||
|
ExistedErr = 该电话已存在
|
||||||
|
EmptyErr = 电话不可为空
|
||||||
|
InvalidReceivers = 无效的电话接收者: %s
|
||||||
|
NumberInvalid = 无效电话
|
||||||
|
PhoneCheckResult = 电话: %s
|
||||||
|
UnableGetModifyRule = 无法得到电话修改规则
|
||||||
|
NoPrefix = %s 无此电话前缀
|
||||||
|
|
||||||
|
[ProviderErr]
|
||||||
|
CanNotBeUnlinked = 该提供商不可被链接
|
||||||
|
InvalidProvider = 无效的验证码提供商
|
||||||
|
LinkFirstErr = 请先绑定
|
||||||
|
ProviderNotEnabled = 提供商: %s 未被启用
|
||||||
|
ProviderNotSupported = 不支持该类型的提供商: %s
|
||||||
|
ProviderNotFound = 该提供商未找到: %s
|
||||||
|
ProviderNotFoundForCategory = 该类型的提供商: %s 在应用中未找到: %s
|
||||||
|
DoNotExist = 提供商: %s 不存在
|
||||||
|
CategoryNotSAML = 提供商 %s类型不是SAML
|
||||||
|
|
||||||
|
[ResourceErr]
|
||||||
|
NotAuthorized = 您无权获取此资源
|
||||||
|
UserIsNil = 用户头像标签为空
|
||||||
|
UsernameOrFilePathEmpty = username或FilePath为空: username = %s, fullFilePath = %s
|
||||||
|
|
||||||
|
[SetPasswordErr]
|
||||||
|
CanNotContainBlank = 新密码不可以包含空客
|
||||||
|
LessThanSixCharacters = 新密码至少为6位
|
||||||
|
|
||||||
|
[SignUpErr]
|
||||||
|
DoNotAllowSignUp = 该应用不允许注册新账户
|
||||||
|
SignOutFirst = 请在登陆前登出
|
||||||
|
|
||||||
|
[TokenErr]
|
||||||
|
EmptyClientID = clientId或clientSecret为空
|
||||||
|
InvalidAppOrWrongClientSecret = 无效应用或错误的clientSecret
|
||||||
|
InvalidToken = 无效token
|
||||||
|
InvalidClientId = 无效的ClientId
|
||||||
|
RedirectURIDoNotExist = 重定向 URI:%s 在可列表中未找到
|
||||||
|
|
||||||
|
[UserErr]
|
||||||
|
AffiliationBlankErr = 联系方式不可为空
|
||||||
|
DisplayNameBlankErr = 展示名称不可为空
|
||||||
|
DisplayNameInvalid = 展示名称无效
|
||||||
|
DisplayNameCanNotBeEmpty = 展示名称不可为空
|
||||||
|
DoNotExist = 用户不存在: %s
|
||||||
|
DoNotExistInOrg = 用户不存在: %s/%s
|
||||||
|
FirstNameBlankErr = 名不可以为空
|
||||||
|
FailToImportUsers = 导入用户失败
|
||||||
|
LastNameBlankErr = 姓不可以为空
|
||||||
|
NameLessThanTwoCharacters = 用户名至少要有2个字符
|
||||||
|
NameStartWithADigitErr = 用户名禁止使用数字作为第一个字符
|
||||||
|
NameIsEmailErr = 用户名不可以是邮箱地址
|
||||||
|
NameCantainWhitSpaceErr = 用户名不可以包含空格
|
||||||
|
NameExistedErr = 用户名已存在
|
||||||
|
NameEmptyErr = 用户名不可为空
|
||||||
|
NameTooLang = 用户名过长(最大长度为39个字符)
|
||||||
|
NameFormatErr = 用户名只能包含字母数字字符、下划线或连字符,不能有连续的连字符或下划线,也不能以连字符或下划线开头或结尾
|
||||||
|
PasswordLessThanSixCharacters = 密码至少为6字符
|
||||||
|
DoNotExistSignUp = 用户不存在,请先注册
|
||||||
|
InvalidInformation = 无效信息
|
||||||
|
NoWebAuthnCredential = 该用户没有WebAuthn凭据
|
||||||
|
|
||||||
|
[StorageErr]
|
||||||
|
ObjectKeyNotAllowed = object key :%s 不被允许
|
||||||
|
|
22
i18n/util.go
22
i18n/util.go
@ -15,12 +15,19 @@
|
|||||||
package i18n
|
package i18n
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"embed"
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/casdoor/casdoor/util"
|
"github.com/casdoor/casdoor/util"
|
||||||
|
"gopkg.in/ini.v1"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
//go:embed languages/*.ini
|
||||||
|
var f embed.FS
|
||||||
|
|
||||||
|
var langMapConfig = make(map[string]*ini.File)
|
||||||
|
|
||||||
func getI18nFilePath(language string) string {
|
func getI18nFilePath(language string) string {
|
||||||
return fmt.Sprintf("../web/src/locales/%s/data.json", language)
|
return fmt.Sprintf("../web/src/locales/%s/data.json", language)
|
||||||
}
|
}
|
||||||
@ -62,3 +69,18 @@ func applyData(data1 *I18nData, data2 *I18nData) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func Translate(lang string, error string) string {
|
||||||
|
parts := strings.Split(error, ".")
|
||||||
|
if !strings.Contains(error, ".") || len(parts) != 2 {
|
||||||
|
return "Translate Error: " + error
|
||||||
|
}
|
||||||
|
|
||||||
|
if langMapConfig[lang] != nil {
|
||||||
|
return langMapConfig[lang].Section(parts[0]).Key(parts[1]).String()
|
||||||
|
} else {
|
||||||
|
file, _ := f.ReadFile("languages/locale_" + lang + ".ini")
|
||||||
|
langMapConfig[lang], _ = ini.Load(file)
|
||||||
|
return langMapConfig[lang].Section(parts[0]).Key(parts[1]).String()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -15,9 +15,12 @@
|
|||||||
package idp
|
package idp
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
"io/ioutil"
|
||||||
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
@ -167,7 +170,10 @@ func (idp *DingTalkIdProvider) GetUserInfo(token *oauth2.Token) (*UserInfo, erro
|
|||||||
Email: dtUserInfo.Email,
|
Email: dtUserInfo.Email,
|
||||||
AvatarUrl: dtUserInfo.AvatarUrl,
|
AvatarUrl: dtUserInfo.AvatarUrl,
|
||||||
}
|
}
|
||||||
|
isUserInOrg, err := idp.isUserInOrg(userInfo.UnionId)
|
||||||
|
if !isUserInOrg {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
return &userInfo, nil
|
return &userInfo, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -194,3 +200,62 @@ func (idp *DingTalkIdProvider) postWithBody(body interface{}, url string) ([]byt
|
|||||||
|
|
||||||
return data, nil
|
return data, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (idp *DingTalkIdProvider) getInnerAppAccessToken() string {
|
||||||
|
appKey := idp.Config.ClientID
|
||||||
|
appSecret := idp.Config.ClientSecret
|
||||||
|
body := make(map[string]string)
|
||||||
|
body["appKey"] = appKey
|
||||||
|
body["appSecret"] = appSecret
|
||||||
|
bodyData, err := json.Marshal(body)
|
||||||
|
if err != nil {
|
||||||
|
log.Println(err.Error())
|
||||||
|
}
|
||||||
|
reader := bytes.NewReader(bodyData)
|
||||||
|
request, err := http.NewRequest("POST", "https://api.dingtalk.com/v1.0/oauth2/accessToken", reader)
|
||||||
|
request.Header.Set("Content-Type", "application/json;charset=UTF-8")
|
||||||
|
resp, err := idp.Client.Do(request)
|
||||||
|
respBytes, err := ioutil.ReadAll(resp.Body)
|
||||||
|
if err != nil {
|
||||||
|
log.Println(err.Error())
|
||||||
|
}
|
||||||
|
var data struct {
|
||||||
|
ExpireIn int `json:"expireIn"`
|
||||||
|
AccessToken string `json:"accessToken"`
|
||||||
|
}
|
||||||
|
err = json.Unmarshal(respBytes, &data)
|
||||||
|
if err != nil {
|
||||||
|
log.Println(err.Error())
|
||||||
|
}
|
||||||
|
return data.AccessToken
|
||||||
|
}
|
||||||
|
|
||||||
|
func (idp *DingTalkIdProvider) isUserInOrg(unionId string) (bool, error) {
|
||||||
|
body := make(map[string]string)
|
||||||
|
body["unionid"] = unionId
|
||||||
|
bodyData, err := json.Marshal(body)
|
||||||
|
if err != nil {
|
||||||
|
log.Println(err.Error())
|
||||||
|
}
|
||||||
|
reader := bytes.NewReader(bodyData)
|
||||||
|
accessToken := idp.getInnerAppAccessToken()
|
||||||
|
request, _ := http.NewRequest("POST", "https://oapi.dingtalk.com/topapi/user/getbyunionid?access_token="+accessToken, reader)
|
||||||
|
request.Header.Set("Content-Type", "application/json;charset=UTF-8")
|
||||||
|
resp, err := idp.Client.Do(request)
|
||||||
|
respBytes, err := ioutil.ReadAll(resp.Body)
|
||||||
|
if err != nil {
|
||||||
|
log.Println(err.Error())
|
||||||
|
}
|
||||||
|
var data struct {
|
||||||
|
ErrCode int `json:"errcode"`
|
||||||
|
ErrMessage string `json:"errmsg"`
|
||||||
|
}
|
||||||
|
err = json.Unmarshal(respBytes, &data)
|
||||||
|
if err != nil {
|
||||||
|
log.Println(err.Error())
|
||||||
|
}
|
||||||
|
if data.ErrCode == 60121 {
|
||||||
|
return false, fmt.Errorf("the user is not found in the organization where clientId and clientSecret belong")
|
||||||
|
}
|
||||||
|
return true, nil
|
||||||
|
}
|
||||||
|
@ -16,14 +16,17 @@ package idp
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"encoding/base64"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/skip2/go-qrcode"
|
||||||
"golang.org/x/oauth2"
|
"golang.org/x/oauth2"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -191,3 +194,54 @@ func (idp *WeChatIdProvider) GetUserInfo(token *oauth2.Token) (*UserInfo, error)
|
|||||||
}
|
}
|
||||||
return &userInfo, nil
|
return &userInfo, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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)
|
||||||
|
request, err := http.NewRequest("GET", accessTokenUrl, nil)
|
||||||
|
client := new(http.Client)
|
||||||
|
resp, err := client.Do(request)
|
||||||
|
respBytes, err := ioutil.ReadAll(resp.Body)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
var data struct {
|
||||||
|
ExpireIn int `json:"expires_in"`
|
||||||
|
AccessToken string `json:"access_token"`
|
||||||
|
}
|
||||||
|
err = json.Unmarshal(respBytes, &data)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
return data.AccessToken, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetWechatOfficialAccountQRCode(clientId string, clientSecret string) (string, error) {
|
||||||
|
accessToken, err := GetWechatOfficialAccountAccessToken(clientId, clientSecret)
|
||||||
|
client := new(http.Client)
|
||||||
|
params := "{\"action_name\": \"QR_LIMIT_STR_SCENE\", \"action_info\": {\"scene\": {\"scene_str\": \"test\"}}}"
|
||||||
|
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)
|
||||||
|
resp, err := client.Do(requeset)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
respBytes, err := ioutil.ReadAll(resp.Body)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
var data struct {
|
||||||
|
Ticket string `json:"ticket"`
|
||||||
|
ExpireSeconds int `json:"expire_seconds"`
|
||||||
|
URL string `json:"url"`
|
||||||
|
}
|
||||||
|
err = json.Unmarshal(respBytes, &data)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
var png []byte
|
||||||
|
png, err = qrcode.Encode(data.URL, qrcode.Medium, 256)
|
||||||
|
base64Image := base64.StdEncoding.EncodeToString(png)
|
||||||
|
return base64Image, nil
|
||||||
|
}
|
||||||
|
@ -20,6 +20,7 @@ import (
|
|||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/casdoor/casdoor/idp"
|
||||||
"github.com/casdoor/casdoor/util"
|
"github.com/casdoor/casdoor/util"
|
||||||
"xorm.io/core"
|
"xorm.io/core"
|
||||||
)
|
)
|
||||||
@ -70,6 +71,7 @@ type Application struct {
|
|||||||
SigninHtml string `xorm:"mediumtext" json:"signinHtml"`
|
SigninHtml string `xorm:"mediumtext" json:"signinHtml"`
|
||||||
FormCss string `xorm:"text" json:"formCss"`
|
FormCss string `xorm:"text" json:"formCss"`
|
||||||
FormOffset int `json:"formOffset"`
|
FormOffset int `json:"formOffset"`
|
||||||
|
FormSideHtml string `xorm:"mediumtext" json:"formSideHtml"`
|
||||||
FormBackgroundUrl string `xorm:"varchar(200)" json:"formBackgroundUrl"`
|
FormBackgroundUrl string `xorm:"varchar(200)" json:"formBackgroundUrl"`
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -83,6 +85,16 @@ func GetApplicationCount(owner, field, value string) int {
|
|||||||
return int(count)
|
return int(count)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GetOrganizationApplicationCount(owner, Organization, field, value string) int {
|
||||||
|
session := GetSession(owner, -1, -1, field, value, "", "")
|
||||||
|
count, err := session.Count(&Application{Organization: Organization})
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return int(count)
|
||||||
|
}
|
||||||
|
|
||||||
func GetApplications(owner string) []*Application {
|
func GetApplications(owner string) []*Application {
|
||||||
applications := []*Application{}
|
applications := []*Application{}
|
||||||
err := adapter.Engine.Desc("created_time").Find(&applications, &Application{Owner: owner})
|
err := adapter.Engine.Desc("created_time").Find(&applications, &Application{Owner: owner})
|
||||||
@ -93,8 +105,18 @@ func GetApplications(owner string) []*Application {
|
|||||||
return applications
|
return applications
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetPaginationApplications(owner string, offset, limit int, field, value, sortField, sortOrder string) []*Application {
|
func GetOrganizationApplications(owner string, organization string) []*Application {
|
||||||
applications := []*Application{}
|
applications := []*Application{}
|
||||||
|
err := adapter.Engine.Desc("created_time").Find(&applications, &Application{Owner: owner, Organization: organization})
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return applications
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetPaginationApplications(owner string, offset, limit int, field, value, sortField, sortOrder string) []*Application {
|
||||||
|
var applications []*Application
|
||||||
session := GetSession(owner, offset, limit, field, value, sortField, sortOrder)
|
session := GetSession(owner, offset, limit, field, value, sortField, sortOrder)
|
||||||
err := session.Find(&applications)
|
err := session.Find(&applications)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -104,9 +126,10 @@ func GetPaginationApplications(owner string, offset, limit int, field, value, so
|
|||||||
return applications
|
return applications
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetApplicationsByOrganizationName(owner string, organization string) []*Application {
|
func GetPaginationOrganizationApplications(owner, organization string, offset, limit int, field, value, sortField, sortOrder string) []*Application {
|
||||||
applications := []*Application{}
|
applications := []*Application{}
|
||||||
err := adapter.Engine.Desc("created_time").Find(&applications, &Application{Owner: owner, Organization: organization})
|
session := GetSession(owner, offset, limit, field, value, sortField, sortOrder)
|
||||||
|
err := session.Find(&applications, &Application{Owner: owner, Organization: organization})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
@ -118,9 +141,11 @@ func getProviderMap(owner string) map[string]*Provider {
|
|||||||
providers := GetProviders(owner)
|
providers := GetProviders(owner)
|
||||||
m := map[string]*Provider{}
|
m := map[string]*Provider{}
|
||||||
for _, provider := range providers {
|
for _, provider := range providers {
|
||||||
//if provider.Category != "OAuth" {
|
// Get QRCode only once
|
||||||
// continue
|
if provider.Type == "WeChat" && provider.DisableSsl == true && provider.Content == "" {
|
||||||
//}
|
provider.Content, _ = idp.GetWechatOfficialAccountQRCode(provider.ClientId2, provider.ClientSecret2)
|
||||||
|
UpdateProvider(provider.Owner+"/"+provider.Name, provider)
|
||||||
|
}
|
||||||
|
|
||||||
m[provider.Name] = GetMaskedProvider(provider)
|
m[provider.Name] = GetMaskedProvider(provider)
|
||||||
}
|
}
|
||||||
@ -128,7 +153,7 @@ func getProviderMap(owner string) map[string]*Provider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func extendApplicationWithProviders(application *Application) {
|
func extendApplicationWithProviders(application *Application) {
|
||||||
m := getProviderMap(application.Owner)
|
m := getProviderMap(application.Organization)
|
||||||
for _, providerItem := range application.Providers {
|
for _, providerItem := range application.Providers {
|
||||||
if provider, ok := m[providerItem.Name]; ok {
|
if provider, ok := m[providerItem.Name]; ok {
|
||||||
providerItem.Provider = provider
|
providerItem.Provider = provider
|
||||||
@ -269,6 +294,13 @@ func UpdateApplication(id string, application *Application) bool {
|
|||||||
application.Name = name
|
application.Name = name
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if name != application.Name {
|
||||||
|
err := applicationChangeTrigger(name, application.Name)
|
||||||
|
if err != nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for _, providerItem := range application.Providers {
|
for _, providerItem := range application.Providers {
|
||||||
providerItem.Provider = nil
|
providerItem.Provider = nil
|
||||||
}
|
}
|
||||||
@ -370,7 +402,7 @@ func IsAllowOrigin(origin string) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func getApplicationMap(organization string) map[string]*Application {
|
func getApplicationMap(organization string) map[string]*Application {
|
||||||
applications := GetApplicationsByOrganizationName("admin", organization)
|
applications := GetOrganizationApplications("admin", organization)
|
||||||
|
|
||||||
applicationMap := make(map[string]*Application)
|
applicationMap := make(map[string]*Application)
|
||||||
for _, application := range applications {
|
for _, application := range applications {
|
||||||
@ -399,3 +431,55 @@ func ExtendManagedAccountsWithUser(user *User) *User {
|
|||||||
|
|
||||||
return user
|
return user
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func applicationChangeTrigger(oldName string, newName string) error {
|
||||||
|
session := adapter.Engine.NewSession()
|
||||||
|
defer session.Close()
|
||||||
|
|
||||||
|
err := session.Begin()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
organization := new(Organization)
|
||||||
|
organization.DefaultApplication = newName
|
||||||
|
_, err = session.Where("default_application=?", oldName).Update(organization)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
user := new(User)
|
||||||
|
user.SignupApplication = newName
|
||||||
|
_, err = session.Where("signup_application=?", oldName).Update(user)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
resource := new(Resource)
|
||||||
|
resource.Application = newName
|
||||||
|
_, err = session.Where("application=?", oldName).Update(resource)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
var permissions []*Permission
|
||||||
|
err = adapter.Engine.Find(&permissions)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
for i := 0; i < len(permissions); i++ {
|
||||||
|
permissionResoureces := permissions[i].Resources
|
||||||
|
for j := 0; j < len(permissionResoureces); j++ {
|
||||||
|
if permissionResoureces[j] == oldName {
|
||||||
|
permissionResoureces[j] = newName
|
||||||
|
}
|
||||||
|
}
|
||||||
|
permissions[i].Resources = permissionResoureces
|
||||||
|
_, err = session.Where("name=?", permissions[i].Name).Update(permissions[i])
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return session.Commit()
|
||||||
|
}
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
package object
|
package object
|
||||||
|
|
||||||
func (application *Application) GetProviderByCategory(category string) *Provider {
|
func (application *Application) GetProviderByCategory(category string) *Provider {
|
||||||
providers := GetProviders(application.Owner)
|
providers := GetProviders(application.Organization)
|
||||||
m := map[string]*Provider{}
|
m := map[string]*Provider{}
|
||||||
for _, provider := range providers {
|
for _, provider := range providers {
|
||||||
if provider.Category != category {
|
if provider.Category != category {
|
||||||
|
@ -60,7 +60,7 @@ func getPermanentAvatarUrl(organization string, username string, url string, upl
|
|||||||
}
|
}
|
||||||
|
|
||||||
fullFilePath := fmt.Sprintf("/avatar/%s/%s.png", organization, username)
|
fullFilePath := fmt.Sprintf("/avatar/%s/%s.png", organization, username)
|
||||||
uploadedFileUrl, _ := getUploadFileUrl(defaultStorageProvider, fullFilePath, false)
|
uploadedFileUrl, _ := GetUploadFileUrl(defaultStorageProvider, fullFilePath, false)
|
||||||
|
|
||||||
if upload {
|
if upload {
|
||||||
DownloadAndUpload(url, fullFilePath)
|
DownloadAndUpload(url, fullFilePath)
|
||||||
|
@ -22,7 +22,6 @@ import (
|
|||||||
"github.com/casbin/casbin/v2/model"
|
"github.com/casbin/casbin/v2/model"
|
||||||
xormadapter "github.com/casbin/xorm-adapter/v3"
|
xormadapter "github.com/casbin/xorm-adapter/v3"
|
||||||
"github.com/casdoor/casdoor/util"
|
"github.com/casdoor/casdoor/util"
|
||||||
|
|
||||||
"xorm.io/core"
|
"xorm.io/core"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -149,34 +148,7 @@ func (casbinAdapter *CasbinAdapter) getTable() string {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func safeReturn(policy []string, i int) string {
|
func initEnforcer(modelObj *Model, casbinAdapter *CasbinAdapter) (*casbin.Enforcer, error) {
|
||||||
if len(policy) > i {
|
|
||||||
return policy[i]
|
|
||||||
} else {
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func matrixToCasbinRules(pType string, policies [][]string) []*xormadapter.CasbinRule {
|
|
||||||
res := []*xormadapter.CasbinRule{}
|
|
||||||
|
|
||||||
for _, policy := range policies {
|
|
||||||
line := xormadapter.CasbinRule{
|
|
||||||
Ptype: pType,
|
|
||||||
V0: safeReturn(policy, 0),
|
|
||||||
V1: safeReturn(policy, 1),
|
|
||||||
V2: safeReturn(policy, 2),
|
|
||||||
V3: safeReturn(policy, 3),
|
|
||||||
V4: safeReturn(policy, 4),
|
|
||||||
V5: safeReturn(policy, 5),
|
|
||||||
}
|
|
||||||
res = append(res, &line)
|
|
||||||
}
|
|
||||||
|
|
||||||
return res
|
|
||||||
}
|
|
||||||
|
|
||||||
func SyncPolicies(casbinAdapter *CasbinAdapter) []*xormadapter.CasbinRule {
|
|
||||||
// init Adapter
|
// init Adapter
|
||||||
if casbinAdapter.Adapter == nil {
|
if casbinAdapter.Adapter == nil {
|
||||||
var dataSourceName string
|
var dataSourceName string
|
||||||
@ -192,20 +164,60 @@ func SyncPolicies(casbinAdapter *CasbinAdapter) []*xormadapter.CasbinRule {
|
|||||||
dataSourceName = strings.ReplaceAll(dataSourceName, "dbi.", "db.")
|
dataSourceName = strings.ReplaceAll(dataSourceName, "dbi.", "db.")
|
||||||
}
|
}
|
||||||
|
|
||||||
casbinAdapter.Adapter, _ = xormadapter.NewAdapterByEngineWithTableName(NewAdapter(casbinAdapter.DatabaseType, dataSourceName, casbinAdapter.Database).Engine, casbinAdapter.getTable(), "")
|
var err error
|
||||||
|
casbinAdapter.Adapter, err = xormadapter.NewAdapterByEngineWithTableName(NewAdapter(casbinAdapter.DatabaseType, dataSourceName, casbinAdapter.Database).Engine, casbinAdapter.getTable(), "")
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// init Model
|
// init Model
|
||||||
modelObj := getModel(casbinAdapter.Owner, casbinAdapter.Model)
|
|
||||||
m, err := model.NewModelFromString(modelObj.ModelText)
|
m, err := model.NewModelFromString(modelObj.ModelText)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// init Enforcer
|
// init Enforcer
|
||||||
enforcer, err := casbin.NewEnforcer(m, casbinAdapter.Adapter)
|
enforcer, err := casbin.NewEnforcer(m, casbinAdapter.Adapter)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return enforcer, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func safeReturn(policy []string, i int) string {
|
||||||
|
if len(policy) > i {
|
||||||
|
return policy[i]
|
||||||
|
} else {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func matrixToCasbinRules(Ptype string, policies [][]string) []*xormadapter.CasbinRule {
|
||||||
|
res := []*xormadapter.CasbinRule{}
|
||||||
|
|
||||||
|
for _, policy := range policies {
|
||||||
|
line := xormadapter.CasbinRule{
|
||||||
|
Ptype: Ptype,
|
||||||
|
V0: safeReturn(policy, 0),
|
||||||
|
V1: safeReturn(policy, 1),
|
||||||
|
V2: safeReturn(policy, 2),
|
||||||
|
V3: safeReturn(policy, 3),
|
||||||
|
V4: safeReturn(policy, 4),
|
||||||
|
V5: safeReturn(policy, 5),
|
||||||
|
}
|
||||||
|
res = append(res, &line)
|
||||||
|
}
|
||||||
|
|
||||||
|
return res
|
||||||
|
}
|
||||||
|
|
||||||
|
func SyncPolicies(casbinAdapter *CasbinAdapter) ([]*xormadapter.CasbinRule, error) {
|
||||||
|
modelObj := getModel(casbinAdapter.Owner, casbinAdapter.Model)
|
||||||
|
enforcer, err := initEnforcer(modelObj, casbinAdapter)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
policies := matrixToCasbinRules("p", enforcer.GetPolicy())
|
policies := matrixToCasbinRules("p", enforcer.GetPolicy())
|
||||||
@ -213,5 +225,48 @@ func SyncPolicies(casbinAdapter *CasbinAdapter) []*xormadapter.CasbinRule {
|
|||||||
policies = append(policies, matrixToCasbinRules("g", enforcer.GetGroupingPolicy())...)
|
policies = append(policies, matrixToCasbinRules("g", enforcer.GetGroupingPolicy())...)
|
||||||
}
|
}
|
||||||
|
|
||||||
return policies
|
return policies, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func UpdatePolicy(oldPolicy, newPolicy []string, casbinAdapter *CasbinAdapter) (bool, error) {
|
||||||
|
modelObj := getModel(casbinAdapter.Owner, casbinAdapter.Model)
|
||||||
|
enforcer, err := initEnforcer(modelObj, casbinAdapter)
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
|
||||||
|
affected, err := enforcer.UpdatePolicy(oldPolicy, newPolicy)
|
||||||
|
if err != nil {
|
||||||
|
return affected, err
|
||||||
|
}
|
||||||
|
return affected, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func AddPolicy(policy []string, casbinAdapter *CasbinAdapter) (bool, error) {
|
||||||
|
modelObj := getModel(casbinAdapter.Owner, casbinAdapter.Model)
|
||||||
|
enforcer, err := initEnforcer(modelObj, casbinAdapter)
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
|
||||||
|
affected, err := enforcer.AddPolicy(policy)
|
||||||
|
if err != nil {
|
||||||
|
return affected, err
|
||||||
|
}
|
||||||
|
return affected, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func RemovePolicy(policy []string, casbinAdapter *CasbinAdapter) (bool, error) {
|
||||||
|
modelObj := getModel(casbinAdapter.Owner, casbinAdapter.Model)
|
||||||
|
enforcer, err := initEnforcer(modelObj, casbinAdapter)
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
|
||||||
|
affected, err := enforcer.RemovePolicy(policy)
|
||||||
|
if err != nil {
|
||||||
|
return affected, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return affected, nil
|
||||||
}
|
}
|
||||||
|
@ -114,6 +114,12 @@ func UpdateCert(id string, cert *Cert) bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if name != cert.Name {
|
||||||
|
err := certChangeTrigger(name, cert.Name)
|
||||||
|
if err != nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
affected, err := adapter.Engine.ID(core.PK{owner, name}).AllCols().Update(cert)
|
affected, err := adapter.Engine.ID(core.PK{owner, name}).AllCols().Update(cert)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
@ -161,3 +167,22 @@ func getCertByApplication(application *Application) *Cert {
|
|||||||
func GetDefaultCert() *Cert {
|
func GetDefaultCert() *Cert {
|
||||||
return getCert("admin", "cert-built-in")
|
return getCert("admin", "cert-built-in")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func certChangeTrigger(oldName string, newName string) error {
|
||||||
|
session := adapter.Engine.NewSession()
|
||||||
|
defer session.Close()
|
||||||
|
|
||||||
|
err := session.Begin()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
application := new(Application)
|
||||||
|
application.Cert = newName
|
||||||
|
_, err = session.Where("cert=?", oldName).Update(application)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return session.Commit()
|
||||||
|
}
|
||||||
|
113
object/check.go
113
object/check.go
@ -22,6 +22,7 @@ import (
|
|||||||
"unicode"
|
"unicode"
|
||||||
|
|
||||||
"github.com/casdoor/casdoor/cred"
|
"github.com/casdoor/casdoor/cred"
|
||||||
|
"github.com/casdoor/casdoor/i18n"
|
||||||
"github.com/casdoor/casdoor/util"
|
"github.com/casdoor/casdoor/util"
|
||||||
goldap "github.com/go-ldap/ldap/v3"
|
goldap "github.com/go-ldap/ldap/v3"
|
||||||
)
|
)
|
||||||
@ -41,89 +42,89 @@ func init() {
|
|||||||
reFieldWhiteList, _ = regexp.Compile(`^[A-Za-z0-9]+$`)
|
reFieldWhiteList, _ = regexp.Compile(`^[A-Za-z0-9]+$`)
|
||||||
}
|
}
|
||||||
|
|
||||||
func CheckUserSignup(application *Application, organization *Organization, username string, password string, displayName string, firstName string, lastName string, email string, phone string, affiliation string) string {
|
func CheckUserSignup(application *Application, organization *Organization, username string, password string, displayName string, firstName string, lastName string, email string, phone string, affiliation string, lang string) string {
|
||||||
if organization == nil {
|
if organization == nil {
|
||||||
return "organization does not exist"
|
return i18n.Translate(lang, "OrgErr.DoNotExist")
|
||||||
}
|
}
|
||||||
|
|
||||||
if application.IsSignupItemVisible("Username") {
|
if application.IsSignupItemVisible("Username") {
|
||||||
if len(username) <= 1 {
|
if len(username) <= 1 {
|
||||||
return "username must have at least 2 characters"
|
return i18n.Translate(lang, "UserErr.NameLessThanTwoCharacters")
|
||||||
}
|
}
|
||||||
if unicode.IsDigit(rune(username[0])) {
|
if unicode.IsDigit(rune(username[0])) {
|
||||||
return "username cannot start with a digit"
|
return i18n.Translate(lang, "UserErr.NameStartWithADigitErr")
|
||||||
}
|
}
|
||||||
if util.IsEmailValid(username) {
|
if util.IsEmailValid(username) {
|
||||||
return "username cannot be an email address"
|
return i18n.Translate(lang, "UserErr.NameIsEmailErr")
|
||||||
}
|
}
|
||||||
if reWhiteSpace.MatchString(username) {
|
if reWhiteSpace.MatchString(username) {
|
||||||
return "username cannot contain white spaces"
|
return i18n.Translate(lang, "UserErr.NameCantainWhitSpaceErr")
|
||||||
}
|
}
|
||||||
msg := CheckUsername(username)
|
msg := CheckUsername(username, lang)
|
||||||
if msg != "" {
|
if msg != "" {
|
||||||
return msg
|
return msg
|
||||||
}
|
}
|
||||||
|
|
||||||
if HasUserByField(organization.Name, "name", username) {
|
if HasUserByField(organization.Name, "name", username) {
|
||||||
return "username already exists"
|
return i18n.Translate(lang, "UserErr.NameExistedErr")
|
||||||
}
|
}
|
||||||
if HasUserByField(organization.Name, "email", email) {
|
if HasUserByField(organization.Name, "email", email) {
|
||||||
return "email already exists"
|
return i18n.Translate(lang, "EmailErr.ExistedErr")
|
||||||
}
|
}
|
||||||
if HasUserByField(organization.Name, "phone", phone) {
|
if HasUserByField(organization.Name, "phone", phone) {
|
||||||
return "phone already exists"
|
return i18n.Translate(lang, "PhoneErr.ExistedErr")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(password) <= 5 {
|
if len(password) <= 5 {
|
||||||
return "password must have at least 6 characters"
|
return i18n.Translate(lang, "UserErr.PasswordLessThanSixCharacters")
|
||||||
}
|
}
|
||||||
|
|
||||||
if application.IsSignupItemVisible("Email") {
|
if application.IsSignupItemVisible("Email") {
|
||||||
if email == "" {
|
if email == "" {
|
||||||
if application.IsSignupItemRequired("Email") {
|
if application.IsSignupItemRequired("Email") {
|
||||||
return "email cannot be empty"
|
return i18n.Translate(lang, "EmailErr.EmptyErr")
|
||||||
} else {
|
} else {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if HasUserByField(organization.Name, "email", email) {
|
if HasUserByField(organization.Name, "email", email) {
|
||||||
return "email already exists"
|
return i18n.Translate(lang, "EmailErr.ExistedErr")
|
||||||
} else if !util.IsEmailValid(email) {
|
} else if !util.IsEmailValid(email) {
|
||||||
return "email is invalid"
|
return i18n.Translate(lang, "EmailErr.EmailInvalid")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if application.IsSignupItemVisible("Phone") {
|
if application.IsSignupItemVisible("Phone") {
|
||||||
if phone == "" {
|
if phone == "" {
|
||||||
if application.IsSignupItemRequired("Phone") {
|
if application.IsSignupItemRequired("Phone") {
|
||||||
return "phone cannot be empty"
|
return i18n.Translate(lang, "PhoneErr.EmptyErr")
|
||||||
} else {
|
} else {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if HasUserByField(organization.Name, "phone", phone) {
|
if HasUserByField(organization.Name, "phone", phone) {
|
||||||
return "phone already exists"
|
return i18n.Translate(lang, "PhoneErr.ExistedErr")
|
||||||
} else if organization.PhonePrefix == "86" && !util.IsPhoneCnValid(phone) {
|
} else if organization.PhonePrefix == "86" && !util.IsPhoneCnValid(phone) {
|
||||||
return "phone number is invalid"
|
return i18n.Translate(lang, "PhoneErr.NumberInvalid")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if application.IsSignupItemVisible("Display name") {
|
if application.IsSignupItemVisible("Display name") {
|
||||||
if application.GetSignupItemRule("Display name") == "First, last" && (firstName != "" || lastName != "") {
|
if application.GetSignupItemRule("Display name") == "First, last" && (firstName != "" || lastName != "") {
|
||||||
if firstName == "" {
|
if firstName == "" {
|
||||||
return "firstName cannot be blank"
|
return i18n.Translate(lang, "UserErr.FirstNameBlankErr")
|
||||||
} else if lastName == "" {
|
} else if lastName == "" {
|
||||||
return "lastName cannot be blank"
|
return i18n.Translate(lang, "UserErr.LastNameBlankErr")
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if displayName == "" {
|
if displayName == "" {
|
||||||
return "displayName cannot be blank"
|
return i18n.Translate(lang, "UserErr.DisplayNameBlankErr")
|
||||||
} else if application.GetSignupItemRule("Display name") == "Real name" {
|
} else if application.GetSignupItemRule("Display name") == "Real name" {
|
||||||
if !isValidRealName(displayName) {
|
if !isValidRealName(displayName) {
|
||||||
return "displayName is not valid real name"
|
return i18n.Translate(lang, "UserErr.DisplayNameInvalid")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -131,14 +132,14 @@ func CheckUserSignup(application *Application, organization *Organization, usern
|
|||||||
|
|
||||||
if application.IsSignupItemVisible("Affiliation") {
|
if application.IsSignupItemVisible("Affiliation") {
|
||||||
if affiliation == "" {
|
if affiliation == "" {
|
||||||
return "affiliation cannot be blank"
|
return i18n.Translate(lang, "UserErr.AffiliationBlankErr")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
func checkSigninErrorTimes(user *User) string {
|
func checkSigninErrorTimes(user *User, lang string) string {
|
||||||
if user.SigninWrongTimes >= SigninWrongTimesLimit {
|
if user.SigninWrongTimes >= SigninWrongTimesLimit {
|
||||||
lastSignWrongTime, _ := time.Parse(time.RFC3339, user.LastSigninWrongTime)
|
lastSignWrongTime, _ := time.Parse(time.RFC3339, user.LastSigninWrongTime)
|
||||||
passedTime := time.Now().UTC().Sub(lastSignWrongTime)
|
passedTime := time.Now().UTC().Sub(lastSignWrongTime)
|
||||||
@ -146,7 +147,7 @@ func checkSigninErrorTimes(user *User) string {
|
|||||||
|
|
||||||
// deny the login if the error times is greater than the limit and the last login time is less than the duration
|
// deny the login if the error times is greater than the limit and the last login time is less than the duration
|
||||||
if seconds > 0 {
|
if seconds > 0 {
|
||||||
return fmt.Sprintf("You have entered the wrong password too many times, please wait for %d minutes %d seconds and try again", seconds/60, seconds%60)
|
return fmt.Sprintf(i18n.Translate(lang, "AuthErr.WrongPasswordManyTimes"), seconds/60, seconds%60)
|
||||||
}
|
}
|
||||||
|
|
||||||
// reset the error times
|
// reset the error times
|
||||||
@ -158,15 +159,15 @@ func checkSigninErrorTimes(user *User) string {
|
|||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
func CheckPassword(user *User, password string) string {
|
func CheckPassword(user *User, password string, lang string) string {
|
||||||
// check the login error times
|
// check the login error times
|
||||||
if msg := checkSigninErrorTimes(user); msg != "" {
|
if msg := checkSigninErrorTimes(user, lang); msg != "" {
|
||||||
return msg
|
return msg
|
||||||
}
|
}
|
||||||
|
|
||||||
organization := GetOrganizationByUser(user)
|
organization := GetOrganizationByUser(user)
|
||||||
if organization == nil {
|
if organization == nil {
|
||||||
return "organization does not exist"
|
return i18n.Translate(lang, "OrgErr.DoNotExist")
|
||||||
}
|
}
|
||||||
|
|
||||||
credManager := cred.GetCredManager(organization.PasswordType)
|
credManager := cred.GetCredManager(organization.PasswordType)
|
||||||
@ -185,11 +186,11 @@ func CheckPassword(user *User, password string) string {
|
|||||||
|
|
||||||
return recordSigninErrorInfo(user)
|
return recordSigninErrorInfo(user)
|
||||||
} else {
|
} else {
|
||||||
return fmt.Sprintf("unsupported password type: %s", organization.PasswordType)
|
return fmt.Sprintf(i18n.Translate(lang, "LoginErr.UnsupportedPasswordType"), organization.PasswordType)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func checkLdapUserPassword(user *User, password string) (*User, string) {
|
func checkLdapUserPassword(user *User, password string, lang string) (*User, string) {
|
||||||
ldaps := GetLdaps(user.Owner)
|
ldaps := GetLdaps(user.Owner)
|
||||||
ldapLoginSuccess := false
|
ldapLoginSuccess := false
|
||||||
for _, ldapServer := range ldaps {
|
for _, ldapServer := range ldaps {
|
||||||
@ -209,7 +210,7 @@ func checkLdapUserPassword(user *User, password string) (*User, string) {
|
|||||||
if len(searchResult.Entries) == 0 {
|
if len(searchResult.Entries) == 0 {
|
||||||
continue
|
continue
|
||||||
} else if len(searchResult.Entries) > 1 {
|
} else if len(searchResult.Entries) > 1 {
|
||||||
return nil, "Error: multiple accounts with same uid, please check your ldap server"
|
return nil, i18n.Translate(lang, "LdapErr.MultipleAccounts")
|
||||||
}
|
}
|
||||||
|
|
||||||
dn := searchResult.Entries[0].DN
|
dn := searchResult.Entries[0].DN
|
||||||
@ -220,26 +221,26 @@ func checkLdapUserPassword(user *User, password string) (*User, string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if !ldapLoginSuccess {
|
if !ldapLoginSuccess {
|
||||||
return nil, "ldap user name or password incorrect"
|
return nil, i18n.Translate(lang, "LdapErr.PasswordWrong")
|
||||||
}
|
}
|
||||||
return user, ""
|
return user, ""
|
||||||
}
|
}
|
||||||
|
|
||||||
func CheckUserPassword(organization string, username string, password string) (*User, string) {
|
func CheckUserPassword(organization string, username string, password string, lang string) (*User, string) {
|
||||||
user := GetUserByFields(organization, username)
|
user := GetUserByFields(organization, username)
|
||||||
if user == nil || user.IsDeleted == true {
|
if user == nil || user.IsDeleted == true {
|
||||||
return nil, "the user does not exist, please sign up first"
|
return nil, i18n.Translate(lang, "UserErr.DoNotExistSignUp")
|
||||||
}
|
}
|
||||||
|
|
||||||
if user.IsForbidden {
|
if user.IsForbidden {
|
||||||
return nil, "the user is forbidden to sign in, please contact the administrator"
|
return nil, i18n.Translate(lang, "LoginErr.UserIsForbidden")
|
||||||
}
|
}
|
||||||
|
|
||||||
if user.Ldap != "" {
|
if user.Ldap != "" {
|
||||||
// ONLY for ldap users
|
// ONLY for ldap users
|
||||||
return checkLdapUserPassword(user, password)
|
return checkLdapUserPassword(user, password, lang)
|
||||||
} else {
|
} else {
|
||||||
msg := CheckPassword(user, password)
|
msg := CheckPassword(user, password, lang)
|
||||||
if msg != "" {
|
if msg != "" {
|
||||||
return nil, msg
|
return nil, msg
|
||||||
}
|
}
|
||||||
@ -251,15 +252,15 @@ func filterField(field string) bool {
|
|||||||
return reFieldWhiteList.MatchString(field)
|
return reFieldWhiteList.MatchString(field)
|
||||||
}
|
}
|
||||||
|
|
||||||
func CheckUserPermission(requestUserId, userId, userOwner string, strict bool) (bool, error) {
|
func CheckUserPermission(requestUserId, userId, userOwner string, strict bool, lang string) (bool, error) {
|
||||||
if requestUserId == "" {
|
if requestUserId == "" {
|
||||||
return false, fmt.Errorf("please login first")
|
return false, fmt.Errorf(i18n.Translate(lang, "LoginErr.LoginFirst"))
|
||||||
}
|
}
|
||||||
|
|
||||||
if userId != "" {
|
if userId != "" {
|
||||||
targetUser := GetUser(userId)
|
targetUser := GetUser(userId)
|
||||||
if targetUser == nil {
|
if targetUser == nil {
|
||||||
return false, fmt.Errorf("the user: %s doesn't exist", userId)
|
return false, fmt.Errorf(i18n.Translate(lang, "UserErr.DoNotExist"), userId)
|
||||||
}
|
}
|
||||||
|
|
||||||
userOwner = targetUser.Owner
|
userOwner = targetUser.Owner
|
||||||
@ -271,7 +272,7 @@ func CheckUserPermission(requestUserId, userId, userOwner string, strict bool) (
|
|||||||
} else {
|
} else {
|
||||||
requestUser := GetUser(requestUserId)
|
requestUser := GetUser(requestUserId)
|
||||||
if requestUser == nil {
|
if requestUser == nil {
|
||||||
return false, fmt.Errorf("session outdated, please login again")
|
return false, fmt.Errorf(i18n.Translate(lang, "LoginErr.SessionOutdated"))
|
||||||
}
|
}
|
||||||
if requestUser.IsGlobalAdmin {
|
if requestUser.IsGlobalAdmin {
|
||||||
hasPermission = true
|
hasPermission = true
|
||||||
@ -286,7 +287,7 @@ func CheckUserPermission(requestUserId, userId, userOwner string, strict bool) (
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return hasPermission, fmt.Errorf("you don't have the permission to do this")
|
return hasPermission, fmt.Errorf(i18n.Translate(lang, "LoginErr.NoPermission"))
|
||||||
}
|
}
|
||||||
|
|
||||||
func CheckAccessPermission(userId string, application *Application) (bool, error) {
|
func CheckAccessPermission(userId string, application *Application) (bool, error) {
|
||||||
@ -319,18 +320,40 @@ func CheckAccessPermission(userId string, application *Application) (bool, error
|
|||||||
return allowed, err
|
return allowed, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func CheckUsername(username string) string {
|
func CheckUsername(username string, lang string) string {
|
||||||
if username == "" {
|
if username == "" {
|
||||||
return "Empty username."
|
return i18n.Translate(lang, "UserErr.NameEmptyErr")
|
||||||
} else if len(username) > 39 {
|
} else if len(username) > 39 {
|
||||||
return "Username is too long (maximum is 39 characters)."
|
return i18n.Translate(lang, "UserErr.NameTooLang")
|
||||||
|
}
|
||||||
|
|
||||||
|
exclude, _ := regexp.Compile("^[\u0021-\u007E]+$")
|
||||||
|
if !exclude.MatchString(username) {
|
||||||
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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]+))*$")
|
re, _ := regexp.Compile("^[a-zA-Z0-9]+((?:-[a-zA-Z0-9]+)|(?:_[a-zA-Z0-9]+))*$")
|
||||||
if !re.MatchString(username) {
|
if !re.MatchString(username) {
|
||||||
return "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, "UserErr.NameFormatErr")
|
||||||
}
|
}
|
||||||
|
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func CheckToEnableCaptcha(application *Application) bool {
|
||||||
|
if len(application.Providers) == 0 {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, providerItem := range application.Providers {
|
||||||
|
if providerItem.Provider == nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if providerItem.Provider.Category == "Captcha" && providerItem.Provider.Type == "Default" {
|
||||||
|
return providerItem.Rule == "Always"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
@ -58,6 +58,7 @@ func initBuiltInOrganization() bool {
|
|||||||
PhonePrefix: "86",
|
PhonePrefix: "86",
|
||||||
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", "ja", "ko", "ru"},
|
||||||
AccountItems: []*AccountItem{
|
AccountItems: []*AccountItem{
|
||||||
{Name: "Organization", Visible: true, ViewRule: "Public", ModifyRule: "Admin"},
|
{Name: "Organization", Visible: true, ViewRule: "Public", ModifyRule: "Admin"},
|
||||||
{Name: "ID", Visible: true, ViewRule: "Public", ModifyRule: "Immutable"},
|
{Name: "ID", Visible: true, ViewRule: "Public", ModifyRule: "Immutable"},
|
||||||
@ -143,7 +144,7 @@ func initBuiltInApplication() {
|
|||||||
EnablePassword: true,
|
EnablePassword: true,
|
||||||
EnableSignUp: true,
|
EnableSignUp: true,
|
||||||
Providers: []*ProviderItem{
|
Providers: []*ProviderItem{
|
||||||
{Name: "provider_captcha_default", CanSignUp: false, CanSignIn: false, CanUnlink: false, Prompted: false, AlertType: "None", Provider: nil},
|
{Name: "provider_captcha_default", CanSignUp: false, CanSignIn: false, CanUnlink: false, Prompted: false, AlertType: "None", Rule: "None", Provider: nil},
|
||||||
},
|
},
|
||||||
SignupItems: []*SignupItem{
|
SignupItems: []*SignupItem{
|
||||||
{Name: "ID", Visible: false, Required: true, Prompted: false, Rule: "Random"},
|
{Name: "ID", Visible: false, Required: true, Prompted: false, Rule: "Random"},
|
||||||
@ -157,7 +158,7 @@ func initBuiltInApplication() {
|
|||||||
},
|
},
|
||||||
RedirectUris: []string{},
|
RedirectUris: []string{},
|
||||||
ExpireInHours: 168,
|
ExpireInHours: 168,
|
||||||
FormOffset: 8,
|
FormOffset: 2,
|
||||||
}
|
}
|
||||||
AddApplication(application)
|
AddApplication(application)
|
||||||
}
|
}
|
||||||
@ -221,7 +222,7 @@ func initBuiltInLdap() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func initBuiltInProvider() {
|
func initBuiltInProvider() {
|
||||||
provider := GetProvider("admin/provider_captcha_default")
|
provider := GetProvider(util.GetId("admin", "provider_captcha_default"))
|
||||||
if provider != nil {
|
if provider != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -56,12 +56,40 @@ func readInitDataFromFile(filePath string) *InitData {
|
|||||||
|
|
||||||
s := util.ReadStringFromPath(filePath)
|
s := util.ReadStringFromPath(filePath)
|
||||||
|
|
||||||
data := &InitData{}
|
data := &InitData{
|
||||||
|
Organizations: []*Organization{},
|
||||||
|
Applications: []*Application{},
|
||||||
|
Users: []*User{},
|
||||||
|
Certs: []*Cert{},
|
||||||
|
Providers: []*Provider{},
|
||||||
|
Ldaps: []*Ldap{},
|
||||||
|
}
|
||||||
err := util.JsonToStruct(s, data)
|
err := util.JsonToStruct(s, data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// transform nil slice to empty slice
|
||||||
|
for _, organization := range data.Organizations {
|
||||||
|
if organization.Tags == nil {
|
||||||
|
organization.Tags = []string{}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for _, application := range data.Applications {
|
||||||
|
if application.Providers == nil {
|
||||||
|
application.Providers = []*ProviderItem{}
|
||||||
|
}
|
||||||
|
if application.SignupItems == nil {
|
||||||
|
application.SignupItems = []*SignupItem{}
|
||||||
|
}
|
||||||
|
if application.GrantTypes == nil {
|
||||||
|
application.GrantTypes = []string{}
|
||||||
|
}
|
||||||
|
if application.RedirectUris == nil {
|
||||||
|
application.RedirectUris = []string{}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return data
|
return data
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -140,7 +168,7 @@ func initDefinedLdap(ldap *Ldap) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func initDefinedProvider(provider *Provider) {
|
func initDefinedProvider(provider *Provider) {
|
||||||
existed := GetProvider(provider.GetId())
|
existed := GetProvider(util.GetId("admin", provider.Name))
|
||||||
if existed != nil {
|
if existed != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -62,7 +62,7 @@ func GetFilteredUsers(m *ldapserver.Message, name, org string) ([]*User, int) {
|
|||||||
return nil, ldapserver.LDAPResultInsufficientAccessRights
|
return nil, ldapserver.LDAPResultInsufficientAccessRights
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
hasPermission, err := CheckUserPermission(fmt.Sprintf("%s/%s", m.Client.OrgName, m.Client.UserName), fmt.Sprintf("%s/%s", org, name), org, true)
|
hasPermission, err := CheckUserPermission(fmt.Sprintf("%s/%s", m.Client.OrgName, m.Client.UserName), fmt.Sprintf("%s/%s", org, name), org, true, "en")
|
||||||
if !hasPermission {
|
if !hasPermission {
|
||||||
log.Printf("ErrMsg = %v", err.Error())
|
log.Printf("ErrMsg = %v", err.Error())
|
||||||
return nil, ldapserver.LDAPResultInsufficientAccessRights
|
return nil, ldapserver.LDAPResultInsufficientAccessRights
|
||||||
|
@ -92,6 +92,12 @@ func UpdateModel(id string, modelObj *Model) bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if name != modelObj.Name {
|
||||||
|
err := modelChangeTrigger(name, modelObj.Name)
|
||||||
|
if err != nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
// check model grammar
|
// check model grammar
|
||||||
_, err := model.NewModelFromString(modelObj.ModelText)
|
_, err := model.NewModelFromString(modelObj.ModelText)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -127,3 +133,22 @@ func DeleteModel(model *Model) bool {
|
|||||||
func (model *Model) GetId() string {
|
func (model *Model) GetId() string {
|
||||||
return fmt.Sprintf("%s/%s", model.Owner, model.Name)
|
return fmt.Sprintf("%s/%s", model.Owner, model.Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func modelChangeTrigger(oldName string, newName string) error {
|
||||||
|
session := adapter.Engine.NewSession()
|
||||||
|
defer session.Close()
|
||||||
|
|
||||||
|
err := session.Begin()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
permission := new(Permission)
|
||||||
|
permission.Model = newName
|
||||||
|
_, err = session.Where("model=?", oldName).Update(permission)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return session.Commit()
|
||||||
|
}
|
||||||
|
@ -16,8 +16,10 @@ package object
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/casdoor/casdoor/cred"
|
"github.com/casdoor/casdoor/cred"
|
||||||
|
"github.com/casdoor/casdoor/i18n"
|
||||||
"github.com/casdoor/casdoor/util"
|
"github.com/casdoor/casdoor/util"
|
||||||
"xorm.io/core"
|
"xorm.io/core"
|
||||||
)
|
)
|
||||||
@ -43,6 +45,7 @@ type Organization struct {
|
|||||||
DefaultAvatar string `xorm:"varchar(100)" json:"defaultAvatar"`
|
DefaultAvatar string `xorm:"varchar(100)" json:"defaultAvatar"`
|
||||||
DefaultApplication string `xorm:"varchar(100)" json:"defaultApplication"`
|
DefaultApplication string `xorm:"varchar(100)" json:"defaultApplication"`
|
||||||
Tags []string `xorm:"mediumtext" json:"tags"`
|
Tags []string `xorm:"mediumtext" json:"tags"`
|
||||||
|
Languages []string `xorm:"varchar(255)" json:"languages"`
|
||||||
MasterPassword string `xorm:"varchar(100)" json:"masterPassword"`
|
MasterPassword string `xorm:"varchar(100)" json:"masterPassword"`
|
||||||
EnableSoftDeletion bool `json:"enableSoftDeletion"`
|
EnableSoftDeletion bool `json:"enableSoftDeletion"`
|
||||||
IsProfilePublic bool `json:"isProfilePublic"`
|
IsProfilePublic bool `json:"isProfilePublic"`
|
||||||
@ -133,15 +136,10 @@ func UpdateOrganization(id string, organization *Organization) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if name != organization.Name {
|
if name != organization.Name {
|
||||||
go func() {
|
err := organizationChangeTrigger(name, organization.Name)
|
||||||
application := new(Application)
|
if err != nil {
|
||||||
application.Organization = organization.Name
|
return false
|
||||||
_, _ = adapter.Engine.Where("organization=?", name).Update(application)
|
}
|
||||||
|
|
||||||
user := new(User)
|
|
||||||
user.Owner = organization.Name
|
|
||||||
_, _ = adapter.Engine.Where("owner=?", name).Update(user)
|
|
||||||
}()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if organization.MasterPassword != "" && organization.MasterPassword != "***" {
|
if organization.MasterPassword != "" && organization.MasterPassword != "***" {
|
||||||
@ -202,18 +200,18 @@ func GetAccountItemByName(name string, organization *Organization) *AccountItem
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func CheckAccountItemModifyRule(accountItem *AccountItem, user *User) (bool, string) {
|
func CheckAccountItemModifyRule(accountItem *AccountItem, user *User, lang string) (bool, string) {
|
||||||
switch accountItem.ModifyRule {
|
switch accountItem.ModifyRule {
|
||||||
case "Admin":
|
case "Admin":
|
||||||
if !(user.IsAdmin || user.IsGlobalAdmin) {
|
if !(user.IsAdmin || user.IsGlobalAdmin) {
|
||||||
return false, fmt.Sprintf("Only admin can modify the %s.", accountItem.Name)
|
return false, fmt.Sprintf(i18n.Translate(lang, "OrgErr.OnlyAdmin"), accountItem.Name)
|
||||||
}
|
}
|
||||||
case "Immutable":
|
case "Immutable":
|
||||||
return false, fmt.Sprintf("The %s is immutable.", accountItem.Name)
|
return false, fmt.Sprintf(i18n.Translate(lang, "OrgErr.Immutable"), accountItem.Name)
|
||||||
case "Self":
|
case "Self":
|
||||||
break
|
break
|
||||||
default:
|
default:
|
||||||
return false, fmt.Sprintf("Unknown modify rule %s.", accountItem.ModifyRule)
|
return false, fmt.Sprintf(i18n.Translate(lang, "OrgErr.UnknownModifyRule"), accountItem.ModifyRule)
|
||||||
}
|
}
|
||||||
return true, ""
|
return true, ""
|
||||||
}
|
}
|
||||||
@ -225,7 +223,12 @@ func GetDefaultApplication(id string) (*Application, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if organization.DefaultApplication != "" {
|
if organization.DefaultApplication != "" {
|
||||||
return getApplication("admin", organization.DefaultApplication), fmt.Errorf("The default application: %s does not exist", organization.DefaultApplication)
|
defaultApplication := getApplication("admin", organization.DefaultApplication)
|
||||||
|
if defaultApplication == nil {
|
||||||
|
return nil, fmt.Errorf("The default application: %s does not exist", organization.DefaultApplication)
|
||||||
|
} else {
|
||||||
|
return defaultApplication, nil
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
applications := []*Application{}
|
applications := []*Application{}
|
||||||
@ -251,3 +254,148 @@ func GetDefaultApplication(id string) (*Application, error) {
|
|||||||
|
|
||||||
return defaultApplication, nil
|
return defaultApplication, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func organizationChangeTrigger(oldName string, newName string) error {
|
||||||
|
session := adapter.Engine.NewSession()
|
||||||
|
defer session.Close()
|
||||||
|
|
||||||
|
err := session.Begin()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
application := new(Application)
|
||||||
|
application.Organization = newName
|
||||||
|
_, err = session.Where("organization=?", oldName).Update(application)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
user := new(User)
|
||||||
|
user.Owner = newName
|
||||||
|
_, err = session.Where("owner=?", oldName).Update(user)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
role := new(Role)
|
||||||
|
_, err = adapter.Engine.Where("owner=?", oldName).Get(role)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
for i, u := range role.Users {
|
||||||
|
// u = organization/username
|
||||||
|
split := strings.Split(u, "/")
|
||||||
|
if split[0] == oldName {
|
||||||
|
split[0] = newName
|
||||||
|
role.Users[i] = split[0] + "/" + split[1]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for i, u := range role.Roles {
|
||||||
|
// u = organization/username
|
||||||
|
split := strings.Split(u, "/")
|
||||||
|
if split[0] == oldName {
|
||||||
|
split[0] = newName
|
||||||
|
role.Roles[i] = split[0] + "/" + split[1]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
role.Owner = newName
|
||||||
|
_, err = session.Where("owner=?", oldName).Update(role)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
permission := new(Permission)
|
||||||
|
_, err = adapter.Engine.Where("owner=?", oldName).Get(permission)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
for i, u := range permission.Users {
|
||||||
|
// u = organization/username
|
||||||
|
split := strings.Split(u, "/")
|
||||||
|
if split[0] == oldName {
|
||||||
|
split[0] = newName
|
||||||
|
permission.Users[i] = split[0] + "/" + split[1]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for i, u := range permission.Roles {
|
||||||
|
// u = organization/username
|
||||||
|
split := strings.Split(u, "/")
|
||||||
|
if split[0] == oldName {
|
||||||
|
split[0] = newName
|
||||||
|
permission.Roles[i] = split[0] + "/" + split[1]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
permission.Owner = newName
|
||||||
|
_, err = session.Where("owner=?", oldName).Update(permission)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
casbinAdapter := new(CasbinAdapter)
|
||||||
|
casbinAdapter.Owner = newName
|
||||||
|
casbinAdapter.Organization = newName
|
||||||
|
_, err = session.Where("owner=?", oldName).Update(casbinAdapter)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
ldap := new(Ldap)
|
||||||
|
ldap.Owner = newName
|
||||||
|
_, err = session.Where("owner=?", oldName).Update(ldap)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
model := new(Model)
|
||||||
|
model.Owner = newName
|
||||||
|
_, err = session.Where("owner=?", oldName).Update(model)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
payment := new(Payment)
|
||||||
|
payment.Organization = newName
|
||||||
|
_, err = session.Where("organization=?", oldName).Update(payment)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
record := new(Record)
|
||||||
|
record.Owner = newName
|
||||||
|
record.Organization = newName
|
||||||
|
_, err = session.Where("organization=?", oldName).Update(record)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
resource := new(Resource)
|
||||||
|
resource.Owner = newName
|
||||||
|
_, err = session.Where("owner=?", oldName).Update(resource)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
syncer := new(Syncer)
|
||||||
|
syncer.Organization = newName
|
||||||
|
_, err = session.Where("organization=?", oldName).Update(syncer)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
token := new(Token)
|
||||||
|
token.Organization = newName
|
||||||
|
_, err = session.Where("organization=?", oldName).Update(token)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
webhook := new(Webhook)
|
||||||
|
webhook.Organization = newName
|
||||||
|
_, err = session.Where("organization=?", oldName).Update(webhook)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return session.Commit()
|
||||||
|
}
|
||||||
|
@ -111,7 +111,27 @@ func GetPermission(id string) *Permission {
|
|||||||
return getPermission(owner, name)
|
return getPermission(owner, name)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// checkPermissionValid verifies if the permission is valid
|
||||||
|
func checkPermissionValid(permission *Permission) {
|
||||||
|
enforcer := getEnforcer(permission)
|
||||||
|
enforcer.EnableAutoSave(false)
|
||||||
|
policies, groupingPolicies := getPolicies(permission)
|
||||||
|
|
||||||
|
if len(groupingPolicies) > 0 {
|
||||||
|
_, err := enforcer.AddGroupingPolicies(groupingPolicies)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err := enforcer.AddPolicies(policies)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func UpdatePermission(id string, permission *Permission) bool {
|
func UpdatePermission(id string, permission *Permission) bool {
|
||||||
|
checkPermissionValid(permission)
|
||||||
owner, name := util.GetOwnerAndNameFromId(id)
|
owner, name := util.GetOwnerAndNameFromId(id)
|
||||||
oldPermission := getPermission(owner, name)
|
oldPermission := getPermission(owner, name)
|
||||||
if oldPermission == nil {
|
if oldPermission == nil {
|
||||||
|
@ -29,7 +29,9 @@ func getEnforcer(permission *Permission) *casbin.Enforcer {
|
|||||||
tableName = permission.Adapter
|
tableName = permission.Adapter
|
||||||
}
|
}
|
||||||
tableNamePrefix := conf.GetConfigString("tableNamePrefix")
|
tableNamePrefix := conf.GetConfigString("tableNamePrefix")
|
||||||
adapter, err := xormadapter.NewAdapterWithTableName(conf.GetConfigString("driverName"), conf.GetConfigDataSourceName()+conf.GetConfigString("dbName"), tableName, tableNamePrefix, true)
|
driverName := conf.GetConfigString("driverName")
|
||||||
|
dataSourceName := conf.GetConfigRealDataSourceName(driverName)
|
||||||
|
adapter, err := xormadapter.NewAdapterWithTableName(driverName, dataSourceName, tableName, tableNamePrefix, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
@ -63,22 +65,27 @@ m = g(r.sub, p.sub) && r.obj == p.obj && r.act == p.act`
|
|||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// load Policy with a specific Permission
|
||||||
|
enforcer.LoadFilteredPolicy(xormadapter.Filter{
|
||||||
|
V5: []string{permission.Owner + "/" + permission.Name},
|
||||||
|
})
|
||||||
return enforcer
|
return enforcer
|
||||||
}
|
}
|
||||||
|
|
||||||
func getPolicies(permission *Permission) ([][]string, [][]string) {
|
func getPolicies(permission *Permission) ([][]string, [][]string) {
|
||||||
var policies [][]string
|
var policies [][]string
|
||||||
var groupingPolicies [][]string
|
var groupingPolicies [][]string
|
||||||
|
permissionId := permission.Owner + "/" + permission.Name
|
||||||
domainExist := len(permission.Domains) > 0
|
domainExist := len(permission.Domains) > 0
|
||||||
for _, user := range permission.Users {
|
for _, user := range permission.Users {
|
||||||
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)})
|
policies = append(policies, []string{user, domain, resource, strings.ToLower(action), "", permissionId})
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
policies = append(policies, []string{user, resource, strings.ToLower(action)})
|
policies = append(policies, []string{user, resource, strings.ToLower(action), "", "", permissionId})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -88,29 +95,29 @@ func getPolicies(permission *Permission) ([][]string, [][]string) {
|
|||||||
for _, subUser := range roleObj.Users {
|
for _, subUser := range roleObj.Users {
|
||||||
if domainExist {
|
if domainExist {
|
||||||
for _, domain := range permission.Domains {
|
for _, domain := range permission.Domains {
|
||||||
groupingPolicies = append(groupingPolicies, []string{subUser, domain, role})
|
groupingPolicies = append(groupingPolicies, []string{subUser, domain, role, "", "", permissionId})
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
groupingPolicies = append(groupingPolicies, []string{subUser, role})
|
groupingPolicies = append(groupingPolicies, []string{subUser, role, "", "", "", permissionId})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for _, subRole := range roleObj.Roles {
|
for _, subRole := range roleObj.Roles {
|
||||||
if domainExist {
|
if domainExist {
|
||||||
for _, domain := range permission.Domains {
|
for _, domain := range permission.Domains {
|
||||||
groupingPolicies = append(groupingPolicies, []string{subRole, domain, role})
|
groupingPolicies = append(groupingPolicies, []string{subRole, domain, role, "", "", permissionId})
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
groupingPolicies = append(groupingPolicies, []string{subRole, role})
|
groupingPolicies = append(groupingPolicies, []string{subRole, role, "", "", "", permissionId})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
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{role, domain, resource, strings.ToLower(action)})
|
policies = append(policies, []string{role, domain, resource, strings.ToLower(action), "", permissionId})
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
policies = append(policies, []string{role, resource, strings.ToLower(action)})
|
policies = append(policies, []string{role, resource, strings.ToLower(action), "", "", permissionId})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -152,20 +159,29 @@ func removePolicies(permission *Permission) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func Enforce(userId string, permissionRule *PermissionRule) bool {
|
func Enforce(permissionRule *PermissionRule) bool {
|
||||||
permission := GetPermission(permissionRule.Id)
|
permission := GetPermission(permissionRule.Id)
|
||||||
enforcer := getEnforcer(permission)
|
enforcer := getEnforcer(permission)
|
||||||
allow, err := enforcer.Enforce(userId, permissionRule.V1, permissionRule.V2)
|
|
||||||
|
request := []interface{}{permissionRule.V0, permissionRule.V1, permissionRule.V2}
|
||||||
|
if permissionRule.V3 != "" {
|
||||||
|
request = append(request, permissionRule.V3)
|
||||||
|
}
|
||||||
|
allow, err := enforcer.Enforce(request...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
return allow
|
return allow
|
||||||
}
|
}
|
||||||
|
|
||||||
func BatchEnforce(userId string, permissionRules []PermissionRule) []bool {
|
func BatchEnforce(permissionRules []PermissionRule) []bool {
|
||||||
var requests [][]interface{}
|
var requests [][]interface{}
|
||||||
for _, permissionRule := range permissionRules {
|
for _, permissionRule := range permissionRules {
|
||||||
requests = append(requests, []interface{}{userId, permissionRule.V1, permissionRule.V2})
|
if permissionRule.V3 != "" {
|
||||||
|
requests = append(requests, []interface{}{permissionRule.V0, permissionRule.V1, permissionRule.V2, permissionRule.V3})
|
||||||
|
} else {
|
||||||
|
requests = append(requests, []interface{}{permissionRule.V0, permissionRule.V1, permissionRule.V2})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
permission := GetPermission(permissionRules[0].Id)
|
permission := GetPermission(permissionRules[0].Id)
|
||||||
enforcer := getEnforcer(permission)
|
enforcer := getEnforcer(permission)
|
||||||
|
@ -17,6 +17,7 @@ package object
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/casdoor/casdoor/i18n"
|
||||||
"github.com/casdoor/casdoor/pp"
|
"github.com/casdoor/casdoor/pp"
|
||||||
"github.com/casdoor/casdoor/util"
|
"github.com/casdoor/casdoor/util"
|
||||||
"xorm.io/core"
|
"xorm.io/core"
|
||||||
@ -24,7 +25,7 @@ import (
|
|||||||
|
|
||||||
type Provider struct {
|
type Provider struct {
|
||||||
Owner string `xorm:"varchar(100) notnull pk" json:"owner"`
|
Owner string `xorm:"varchar(100) notnull pk" json:"owner"`
|
||||||
Name string `xorm:"varchar(100) notnull pk" 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"`
|
||||||
@ -45,9 +46,9 @@ type Provider struct {
|
|||||||
|
|
||||||
Host string `xorm:"varchar(100)" json:"host"`
|
Host string `xorm:"varchar(100)" json:"host"`
|
||||||
Port int `json:"port"`
|
Port int `json:"port"`
|
||||||
DisableSsl bool `json:"disableSsl"`
|
DisableSsl bool `json:"disableSsl"` // If the provider type is WeChat, DisableSsl means EnableQRCode
|
||||||
Title string `xorm:"varchar(100)" json:"title"`
|
Title string `xorm:"varchar(100)" json:"title"`
|
||||||
Content string `xorm:"varchar(1000)" json:"content"`
|
Content string `xorm:"varchar(1000)" json:"content"` // If provider type is WeChat, Content means QRCode string by Base64 encoding
|
||||||
Receiver string `xorm:"varchar(100)" json:"receiver"`
|
Receiver string `xorm:"varchar(100)" json:"receiver"`
|
||||||
|
|
||||||
RegionId string `xorm:"varchar(100)" json:"regionId"`
|
RegionId string `xorm:"varchar(100)" json:"regionId"`
|
||||||
@ -59,6 +60,7 @@ type Provider struct {
|
|||||||
IntranetEndpoint string `xorm:"varchar(100)" json:"intranetEndpoint"`
|
IntranetEndpoint string `xorm:"varchar(100)" json:"intranetEndpoint"`
|
||||||
Domain string `xorm:"varchar(100)" json:"domain"`
|
Domain string `xorm:"varchar(100)" json:"domain"`
|
||||||
Bucket string `xorm:"varchar(100)" json:"bucket"`
|
Bucket string `xorm:"varchar(100)" json:"bucket"`
|
||||||
|
PathPrefix string `xorm:"varchar(100)" json:"pathPrefix"`
|
||||||
|
|
||||||
Metadata string `xorm:"mediumtext" json:"metadata"`
|
Metadata string `xorm:"mediumtext" json:"metadata"`
|
||||||
IdP string `xorm:"mediumtext" json:"idP"`
|
IdP string `xorm:"mediumtext" json:"idP"`
|
||||||
@ -91,7 +93,17 @@ func GetMaskedProviders(providers []*Provider) []*Provider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func GetProviderCount(owner, field, value string) int {
|
func GetProviderCount(owner, field, value string) int {
|
||||||
session := GetSession(owner, -1, -1, field, value, "", "")
|
session := GetSession("", -1, -1, field, value, "", "")
|
||||||
|
count, err := session.Where("owner = ? or owner = ? ", "admin", owner).Count(&Provider{})
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return int(count)
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetGlobalProviderCount(field, value string) int {
|
||||||
|
session := GetSession("", -1, -1, field, value, "", "")
|
||||||
count, err := session.Count(&Provider{})
|
count, err := session.Count(&Provider{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
@ -102,7 +114,17 @@ func GetProviderCount(owner, field, value string) int {
|
|||||||
|
|
||||||
func GetProviders(owner string) []*Provider {
|
func GetProviders(owner string) []*Provider {
|
||||||
providers := []*Provider{}
|
providers := []*Provider{}
|
||||||
err := adapter.Engine.Desc("created_time").Find(&providers, &Provider{Owner: owner})
|
err := adapter.Engine.Where("owner = ? or owner = ? ", "admin", owner).Desc("created_time").Find(&providers, &Provider{})
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return providers
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetGlobalProviders() []*Provider {
|
||||||
|
providers := []*Provider{}
|
||||||
|
err := adapter.Engine.Desc("created_time").Find(&providers)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
@ -112,7 +134,18 @@ func GetProviders(owner string) []*Provider {
|
|||||||
|
|
||||||
func GetPaginationProviders(owner string, offset, limit int, field, value, sortField, sortOrder string) []*Provider {
|
func GetPaginationProviders(owner string, offset, limit int, field, value, sortField, sortOrder string) []*Provider {
|
||||||
providers := []*Provider{}
|
providers := []*Provider{}
|
||||||
session := GetSession(owner, offset, limit, field, value, sortField, sortOrder)
|
session := GetSession("", offset, limit, field, value, sortField, sortOrder)
|
||||||
|
err := session.Where("owner = ? or owner = ? ", "admin", owner).Find(&providers)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return providers
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetPaginationGlobalProviders(offset, limit int, field, value, sortField, sortOrder string) []*Provider {
|
||||||
|
providers := []*Provider{}
|
||||||
|
session := GetSession("", offset, limit, field, value, sortField, sortOrder)
|
||||||
err := session.Find(&providers)
|
err := session.Find(&providers)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
@ -126,7 +159,7 @@ func getProvider(owner string, name string) *Provider {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
provider := Provider{Owner: owner, Name: name}
|
provider := Provider{Name: name}
|
||||||
existed, err := adapter.Engine.Get(&provider)
|
existed, err := adapter.Engine.Get(&provider)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
@ -174,6 +207,13 @@ func UpdateProvider(id string, provider *Provider) bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if name != provider.Name {
|
||||||
|
err := providerChangeTrigger(name, provider.Name)
|
||||||
|
if err != nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
session := adapter.Engine.ID(core.PK{owner, name}).AllCols()
|
session := adapter.Engine.ID(core.PK{owner, name}).AllCols()
|
||||||
if provider.ClientSecret == "***" {
|
if provider.ClientSecret == "***" {
|
||||||
session = session.Omit("client_secret")
|
session = session.Omit("client_secret")
|
||||||
@ -228,7 +268,7 @@ func (p *Provider) GetId() string {
|
|||||||
return fmt.Sprintf("%s/%s", p.Owner, p.Name)
|
return fmt.Sprintf("%s/%s", p.Owner, p.Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetCaptchaProviderByOwnerName(applicationId string) (*Provider, error) {
|
func GetCaptchaProviderByOwnerName(applicationId, lang string) (*Provider, error) {
|
||||||
owner, name := util.GetOwnerAndNameFromId(applicationId)
|
owner, name := util.GetOwnerAndNameFromId(applicationId)
|
||||||
provider := Provider{Owner: owner, Name: name, Category: "Captcha"}
|
provider := Provider{Owner: owner, Name: name, Category: "Captcha"}
|
||||||
existed, err := adapter.Engine.Get(&provider)
|
existed, err := adapter.Engine.Get(&provider)
|
||||||
@ -237,27 +277,65 @@ func GetCaptchaProviderByOwnerName(applicationId string) (*Provider, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if !existed {
|
if !existed {
|
||||||
return nil, fmt.Errorf("the provider: %s does not exist", applicationId)
|
return nil, fmt.Errorf(i18n.Translate(lang, "ProviderErr.DoNotExist"), applicationId)
|
||||||
}
|
}
|
||||||
|
|
||||||
return &provider, nil
|
return &provider, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetCaptchaProviderByApplication(applicationId, isCurrentProvider string) (*Provider, error) {
|
func GetCaptchaProviderByApplication(applicationId, isCurrentProvider, lang string) (*Provider, error) {
|
||||||
if isCurrentProvider == "true" {
|
if isCurrentProvider == "true" {
|
||||||
return GetCaptchaProviderByOwnerName(applicationId)
|
return GetCaptchaProviderByOwnerName(applicationId, lang)
|
||||||
}
|
}
|
||||||
application := GetApplication(applicationId)
|
application := GetApplication(applicationId)
|
||||||
if application == nil || len(application.Providers) == 0 {
|
if application == nil || len(application.Providers) == 0 {
|
||||||
return nil, fmt.Errorf("invalid application id")
|
return nil, fmt.Errorf(i18n.Translate(lang, "ApplicationErr.InvalidID"))
|
||||||
}
|
}
|
||||||
for _, provider := range application.Providers {
|
for _, provider := range application.Providers {
|
||||||
if provider.Provider == nil {
|
if provider.Provider == nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if provider.Provider.Category == "Captcha" {
|
if provider.Provider.Category == "Captcha" {
|
||||||
return GetCaptchaProviderByOwnerName(fmt.Sprintf("%s/%s", provider.Provider.Owner, provider.Provider.Name))
|
return GetCaptchaProviderByOwnerName(fmt.Sprintf("%s/%s", provider.Provider.Owner, provider.Provider.Name), lang)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func providerChangeTrigger(oldName string, newName string) error {
|
||||||
|
session := adapter.Engine.NewSession()
|
||||||
|
defer session.Close()
|
||||||
|
|
||||||
|
err := session.Begin()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
var applications []*Application
|
||||||
|
err = adapter.Engine.Find(&applications)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
for i := 0; i < len(applications); i++ {
|
||||||
|
providers := applications[i].Providers
|
||||||
|
for j := 0; j < len(providers); j++ {
|
||||||
|
if providers[j].Name == oldName {
|
||||||
|
providers[j].Name = newName
|
||||||
|
}
|
||||||
|
}
|
||||||
|
applications[i].Providers = providers
|
||||||
|
_, err = session.Where("name=?", applications[i].Name).Update(applications[i])
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
resource := new(Resource)
|
||||||
|
resource.Provider = newName
|
||||||
|
_, err = session.Where("provider=?", oldName).Update(resource)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return session.Commit()
|
||||||
|
}
|
||||||
|
@ -15,12 +15,15 @@
|
|||||||
package object
|
package object
|
||||||
|
|
||||||
type ProviderItem struct {
|
type ProviderItem struct {
|
||||||
Name string `json:"name"`
|
Owner string `json:"owner"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
|
||||||
CanSignUp bool `json:"canSignUp"`
|
CanSignUp bool `json:"canSignUp"`
|
||||||
CanSignIn bool `json:"canSignIn"`
|
CanSignIn bool `json:"canSignIn"`
|
||||||
CanUnlink bool `json:"canUnlink"`
|
CanUnlink bool `json:"canUnlink"`
|
||||||
Prompted bool `json:"prompted"`
|
Prompted bool `json:"prompted"`
|
||||||
AlertType string `json:"alertType"`
|
AlertType string `json:"alertType"`
|
||||||
|
Rule string `json:"rule"`
|
||||||
Provider *Provider `json:"provider"`
|
Provider *Provider `json:"provider"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,7 +23,7 @@ import (
|
|||||||
|
|
||||||
type Resource struct {
|
type Resource struct {
|
||||||
Owner string `xorm:"varchar(100) notnull pk" json:"owner"`
|
Owner string `xorm:"varchar(100) notnull pk" json:"owner"`
|
||||||
Name string `xorm:"varchar(250) notnull pk" json:"name"`
|
Name string `xorm:"varchar(100) notnull pk" json:"name"`
|
||||||
CreatedTime string `xorm:"varchar(100)" json:"createdTime"`
|
CreatedTime string `xorm:"varchar(100)" json:"createdTime"`
|
||||||
|
|
||||||
User string `xorm:"varchar(100)" json:"user"`
|
User string `xorm:"varchar(100)" json:"user"`
|
||||||
@ -31,12 +31,12 @@ type Resource struct {
|
|||||||
Application string `xorm:"varchar(100)" json:"application"`
|
Application string `xorm:"varchar(100)" json:"application"`
|
||||||
Tag string `xorm:"varchar(100)" json:"tag"`
|
Tag string `xorm:"varchar(100)" json:"tag"`
|
||||||
Parent string `xorm:"varchar(100)" json:"parent"`
|
Parent string `xorm:"varchar(100)" json:"parent"`
|
||||||
FileName string `xorm:"varchar(1000)" json:"fileName"`
|
FileName string `xorm:"varchar(255)" json:"fileName"`
|
||||||
FileType string `xorm:"varchar(100)" json:"fileType"`
|
FileType string `xorm:"varchar(100)" json:"fileType"`
|
||||||
FileFormat string `xorm:"varchar(100)" json:"fileFormat"`
|
FileFormat string `xorm:"varchar(100)" json:"fileFormat"`
|
||||||
FileSize int `json:"fileSize"`
|
FileSize int `json:"fileSize"`
|
||||||
Url string `xorm:"varchar(1000)" json:"url"`
|
Url string `xorm:"varchar(255)" json:"url"`
|
||||||
Description string `xorm:"varchar(1000)" json:"description"`
|
Description string `xorm:"varchar(255)" json:"description"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetResourceCount(owner, user, field, value string) int {
|
func GetResourceCount(owner, user, field, value string) int {
|
||||||
|
@ -16,6 +16,7 @@ package object
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/casdoor/casdoor/util"
|
"github.com/casdoor/casdoor/util"
|
||||||
"xorm.io/core"
|
"xorm.io/core"
|
||||||
@ -94,6 +95,13 @@ func UpdateRole(id string, role *Role) bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if name != role.Name {
|
||||||
|
err := roleChangeTrigger(name, role.Name)
|
||||||
|
if err != nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
affected, err := adapter.Engine.ID(core.PK{owner, name}).AllCols().Update(role)
|
affected, err := adapter.Engine.ID(core.PK{owner, name}).AllCols().Update(role)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
@ -133,3 +141,54 @@ func GetRolesByUser(userId string) []*Role {
|
|||||||
|
|
||||||
return roles
|
return roles
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func roleChangeTrigger(oldName string, newName string) error {
|
||||||
|
session := adapter.Engine.NewSession()
|
||||||
|
defer session.Close()
|
||||||
|
|
||||||
|
err := session.Begin()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
var roles []*Role
|
||||||
|
err = adapter.Engine.Find(&roles)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
for _, role := range roles {
|
||||||
|
for j, u := range role.Roles {
|
||||||
|
split := strings.Split(u, "/")
|
||||||
|
if split[1] == oldName {
|
||||||
|
split[1] = newName
|
||||||
|
role.Roles[j] = split[0] + "/" + split[1]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_, err = session.Where("name=?", role.Name).Update(role)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var permissions []*Permission
|
||||||
|
err = adapter.Engine.Find(&permissions)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
for _, permission := range permissions {
|
||||||
|
for j, u := range permission.Roles {
|
||||||
|
// u = organization/username
|
||||||
|
split := strings.Split(u, "/")
|
||||||
|
if split[1] == oldName {
|
||||||
|
split[1] = newName
|
||||||
|
permission.Roles[j] = split[0] + "/" + split[1]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_, err = session.Where("name=?", permission.Name).Update(permission)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return session.Commit()
|
||||||
|
}
|
||||||
|
@ -24,6 +24,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/casdoor/casdoor/conf"
|
"github.com/casdoor/casdoor/conf"
|
||||||
|
"github.com/casdoor/casdoor/i18n"
|
||||||
saml2 "github.com/russellhaering/gosaml2"
|
saml2 "github.com/russellhaering/gosaml2"
|
||||||
dsig "github.com/russellhaering/goxmldsig"
|
dsig "github.com/russellhaering/goxmldsig"
|
||||||
)
|
)
|
||||||
@ -41,10 +42,10 @@ func ParseSamlResponse(samlResponse string, providerType string) (string, error)
|
|||||||
return assertionInfo.NameID, nil
|
return assertionInfo.NameID, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func GenerateSamlLoginUrl(id, relayState string) (string, string, error) {
|
func GenerateSamlLoginUrl(id, relayState, lang string) (string, string, error) {
|
||||||
provider := GetProvider(id)
|
provider := GetProvider(id)
|
||||||
if provider.Category != "SAML" {
|
if provider.Category != "SAML" {
|
||||||
return "", "", fmt.Errorf("provider %s's category is not SAML", provider.Name)
|
return "", "", fmt.Errorf(i18n.Translate(lang, "ProviderErr.CategoryNotSAML"), provider.Name)
|
||||||
}
|
}
|
||||||
sp, err := buildSp(provider, "")
|
sp, err := buildSp(provider, "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -21,6 +21,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/casdoor/casdoor/conf"
|
"github.com/casdoor/casdoor/conf"
|
||||||
|
"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"
|
||||||
)
|
)
|
||||||
@ -53,8 +54,8 @@ func escapePath(path string) string {
|
|||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
|
|
||||||
func getUploadFileUrl(provider *Provider, fullFilePath string, hasTimestamp bool) (string, string) {
|
func GetUploadFileUrl(provider *Provider, fullFilePath string, hasTimestamp bool) (string, string) {
|
||||||
escapedPath := escapePath(fullFilePath)
|
escapedPath := util.UrlJoin(provider.PathPrefix, escapePath(fullFilePath))
|
||||||
objectKey := util.UrlJoin(util.GetUrlPath(provider.Domain), escapedPath)
|
objectKey := util.UrlJoin(util.GetUrlPath(provider.Domain), escapedPath)
|
||||||
|
|
||||||
host := ""
|
host := ""
|
||||||
@ -69,7 +70,7 @@ func getUploadFileUrl(provider *Provider, fullFilePath string, hasTimestamp bool
|
|||||||
host = util.UrlJoin(provider.Domain, "/files")
|
host = util.UrlJoin(provider.Domain, "/files")
|
||||||
}
|
}
|
||||||
if provider.Type == "Azure Blob" {
|
if provider.Type == "Azure Blob" {
|
||||||
host = fmt.Sprintf("%s/%s", host, provider.Bucket)
|
host = util.UrlJoin(host, provider.Bucket)
|
||||||
}
|
}
|
||||||
|
|
||||||
fileUrl := util.UrlJoin(host, escapePath(objectKey))
|
fileUrl := util.UrlJoin(host, escapePath(objectKey))
|
||||||
@ -92,7 +93,7 @@ func uploadFile(provider *Provider, fullFilePath string, fileBuffer *bytes.Buffe
|
|||||||
UpdateProvider(provider.GetId(), provider)
|
UpdateProvider(provider.GetId(), provider)
|
||||||
}
|
}
|
||||||
|
|
||||||
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 {
|
||||||
@ -126,16 +127,16 @@ func UploadFileSafe(provider *Provider, fullFilePath string, fileBuffer *bytes.B
|
|||||||
return fileUrl, objectKey, nil
|
return fileUrl, objectKey, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func DeleteFile(provider *Provider, objectKey string) error {
|
func DeleteFile(provider *Provider, objectKey string, lang string) error {
|
||||||
// check fullFilePath is there security issue
|
// check fullFilePath is there security issue
|
||||||
if strings.Contains(objectKey, "..") {
|
if strings.Contains(objectKey, "..") {
|
||||||
return fmt.Errorf("the objectKey: %s is not allowed", objectKey)
|
return fmt.Errorf(i18n.Translate(lang, "StorageErr.ObjectKeyNotAllowed"), objectKey)
|
||||||
}
|
}
|
||||||
|
|
||||||
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("the provider type: %s is not supported", provider.Type)
|
return fmt.Errorf(i18n.Translate(lang, "ProviderErr.ProviderNotSupported"), provider.Type)
|
||||||
}
|
}
|
||||||
|
|
||||||
if provider.Domain == "" {
|
if provider.Domain == "" {
|
||||||
|
@ -37,7 +37,16 @@ func (syncer *Syncer) getOriginalUsers() ([]*OriginalUser, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return syncer.getOriginalUsersFromMap(results), nil
|
// Memory leak problem handling
|
||||||
|
// https://github.com/casdoor/casdoor/issues/1256
|
||||||
|
users := syncer.getOriginalUsersFromMap(results)
|
||||||
|
for _, m := range results {
|
||||||
|
for k := range m {
|
||||||
|
delete(m, k)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return users, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (syncer *Syncer) getOriginalUserMap() ([]*OriginalUser, map[string]*OriginalUser, error) {
|
func (syncer *Syncer) getOriginalUserMap() ([]*OriginalUser, map[string]*OriginalUser, error) {
|
||||||
|
@ -21,6 +21,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/casdoor/casdoor/i18n"
|
||||||
"github.com/casdoor/casdoor/idp"
|
"github.com/casdoor/casdoor/idp"
|
||||||
"github.com/casdoor/casdoor/util"
|
"github.com/casdoor/casdoor/util"
|
||||||
"xorm.io/core"
|
"xorm.io/core"
|
||||||
@ -238,14 +239,14 @@ func GetTokenByTokenAndApplication(token string, application string) *Token {
|
|||||||
return &tokenResult
|
return &tokenResult
|
||||||
}
|
}
|
||||||
|
|
||||||
func CheckOAuthLogin(clientId string, responseType string, redirectUri string, scope string, state string) (string, *Application) {
|
func CheckOAuthLogin(clientId string, responseType string, redirectUri string, scope string, state string, lang string) (string, *Application) {
|
||||||
if responseType != "code" && responseType != "token" && responseType != "id_token" {
|
if responseType != "code" && responseType != "token" && responseType != "id_token" {
|
||||||
return fmt.Sprintf("error: grant_type: %s is not supported in this application", responseType), nil
|
return fmt.Sprintf(i18n.Translate(lang, "ApplicationErr.GrantTypeNotSupport"), responseType), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
application := GetApplicationByClientId(clientId)
|
application := GetApplicationByClientId(clientId)
|
||||||
if application == nil {
|
if application == nil {
|
||||||
return "Invalid client_id", nil
|
return i18n.Translate(lang, "TokenErr.InvalidClientId"), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
validUri := false
|
validUri := false
|
||||||
@ -256,7 +257,7 @@ func CheckOAuthLogin(clientId string, responseType string, redirectUri string, s
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if !validUri {
|
if !validUri {
|
||||||
return fmt.Sprintf("Redirect URI: \"%s\" doesn't exist in the allowed Redirect URI list", redirectUri), application
|
return fmt.Sprintf(i18n.Translate(lang, "TokenErr.RedirectURIDoNotExist"), redirectUri), application
|
||||||
}
|
}
|
||||||
|
|
||||||
// Mask application for /api/get-app-login
|
// Mask application for /api/get-app-login
|
||||||
@ -264,7 +265,7 @@ func CheckOAuthLogin(clientId string, responseType string, redirectUri string, s
|
|||||||
return "", application
|
return "", application
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetOAuthCode(userId string, clientId string, responseType string, redirectUri string, scope string, state string, nonce string, challenge string, host string) *Code {
|
func GetOAuthCode(userId string, clientId string, responseType string, redirectUri string, scope string, state string, nonce string, challenge string, host string, lang string) *Code {
|
||||||
user := GetUser(userId)
|
user := GetUser(userId)
|
||||||
if user == nil {
|
if user == nil {
|
||||||
return &Code{
|
return &Code{
|
||||||
@ -279,7 +280,7 @@ func GetOAuthCode(userId string, clientId string, responseType string, redirectU
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
msg, application := CheckOAuthLogin(clientId, responseType, redirectUri, scope, state)
|
msg, application := CheckOAuthLogin(clientId, responseType, redirectUri, scope, state, lang)
|
||||||
if msg != "" {
|
if msg != "" {
|
||||||
return &Code{
|
return &Code{
|
||||||
Message: msg,
|
Message: msg,
|
||||||
@ -322,7 +323,7 @@ func GetOAuthCode(userId string, clientId string, responseType string, redirectU
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetOAuthToken(grantType string, clientId string, clientSecret string, code string, verifier string, scope string, username string, password string, host string, tag string, avatar string) interface{} {
|
func GetOAuthToken(grantType string, clientId string, clientSecret string, code string, verifier string, scope string, username string, password string, host string, tag string, avatar string, lang string) interface{} {
|
||||||
application := GetApplicationByClientId(clientId)
|
application := GetApplicationByClientId(clientId)
|
||||||
if application == nil {
|
if application == nil {
|
||||||
return &TokenError{
|
return &TokenError{
|
||||||
@ -353,7 +354,7 @@ func GetOAuthToken(grantType string, clientId string, clientSecret string, code
|
|||||||
|
|
||||||
if tag == "wechat_miniprogram" {
|
if tag == "wechat_miniprogram" {
|
||||||
// Wechat Mini Program
|
// Wechat Mini Program
|
||||||
token, tokenError = GetWechatMiniProgramToken(application, code, host, username, avatar)
|
token, tokenError = GetWechatMiniProgramToken(application, code, host, username, avatar, lang)
|
||||||
}
|
}
|
||||||
|
|
||||||
if tokenError != nil {
|
if tokenError != nil {
|
||||||
@ -559,7 +560,7 @@ func GetPasswordToken(application *Application, username string, password string
|
|||||||
ErrorDescription: "the user does not exist",
|
ErrorDescription: "the user does not exist",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
msg := CheckPassword(user, password)
|
msg := CheckPassword(user, password, "en")
|
||||||
if msg != "" {
|
if msg != "" {
|
||||||
return nil, &TokenError{
|
return nil, &TokenError{
|
||||||
Error: InvalidGrant,
|
Error: InvalidGrant,
|
||||||
@ -669,7 +670,7 @@ func GetTokenByUser(application *Application, user *User, scope string, host str
|
|||||||
|
|
||||||
// GetWechatMiniProgramToken
|
// GetWechatMiniProgramToken
|
||||||
// Wechat Mini Program flow
|
// Wechat Mini Program flow
|
||||||
func GetWechatMiniProgramToken(application *Application, code string, host string, username string, avatar string) (*Token, *TokenError) {
|
func GetWechatMiniProgramToken(application *Application, code string, host string, username string, avatar string, lang string) (*Token, *TokenError) {
|
||||||
mpProvider := GetWechatMiniProgramProvider(application)
|
mpProvider := GetWechatMiniProgramProvider(application)
|
||||||
if mpProvider == nil {
|
if mpProvider == nil {
|
||||||
return nil, &TokenError{
|
return nil, &TokenError{
|
||||||
@ -677,7 +678,7 @@ func GetWechatMiniProgramToken(application *Application, code string, host strin
|
|||||||
ErrorDescription: "the application does not support wechat mini program",
|
ErrorDescription: "the application does not support wechat mini program",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
provider := GetProvider(util.GetId(mpProvider.Name))
|
provider := GetProvider(util.GetId("admin", mpProvider.Name))
|
||||||
mpIdp := idp.NewWeChatMiniProgramIdProvider(provider.ClientId, provider.ClientSecret)
|
mpIdp := idp.NewWeChatMiniProgramIdProvider(provider.ClientId, provider.ClientSecret)
|
||||||
session, err := mpIdp.GetSessionByCode(code)
|
session, err := mpIdp.GetSessionByCode(code)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -703,7 +704,7 @@ func GetWechatMiniProgramToken(application *Application, code string, host strin
|
|||||||
}
|
}
|
||||||
// Add new user
|
// Add new user
|
||||||
var name string
|
var name string
|
||||||
if CheckUsername(username) == "" {
|
if CheckUsername(username, lang) == "" {
|
||||||
name = username
|
name = username
|
||||||
} else {
|
} else {
|
||||||
name = fmt.Sprintf("wechat-%s", openId)
|
name = fmt.Sprintf("wechat-%s", openId)
|
||||||
|
@ -24,9 +24,10 @@ import (
|
|||||||
|
|
||||||
type Claims struct {
|
type Claims struct {
|
||||||
*User
|
*User
|
||||||
Nonce string `json:"nonce,omitempty"`
|
TokenType string `json:"tokenType,omitempty"`
|
||||||
Tag string `json:"tag,omitempty"`
|
Nonce string `json:"nonce,omitempty"`
|
||||||
Scope string `json:"scope,omitempty"`
|
Tag string `json:"tag,omitempty"`
|
||||||
|
Scope string `json:"scope,omitempty"`
|
||||||
jwt.RegisteredClaims
|
jwt.RegisteredClaims
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -37,8 +38,9 @@ type UserShort struct {
|
|||||||
|
|
||||||
type ClaimsShort struct {
|
type ClaimsShort struct {
|
||||||
*UserShort
|
*UserShort
|
||||||
Nonce string `json:"nonce,omitempty"`
|
TokenType string `json:"tokenType,omitempty"`
|
||||||
Scope string `json:"scope,omitempty"`
|
Nonce string `json:"nonce,omitempty"`
|
||||||
|
Scope string `json:"scope,omitempty"`
|
||||||
jwt.RegisteredClaims
|
jwt.RegisteredClaims
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -53,6 +55,7 @@ func getShortUser(user *User) *UserShort {
|
|||||||
func getShortClaims(claims Claims) ClaimsShort {
|
func getShortClaims(claims Claims) ClaimsShort {
|
||||||
res := ClaimsShort{
|
res := ClaimsShort{
|
||||||
UserShort: getShortUser(claims.User),
|
UserShort: getShortUser(claims.User),
|
||||||
|
TokenType: claims.TokenType,
|
||||||
Nonce: claims.Nonce,
|
Nonce: claims.Nonce,
|
||||||
Scope: claims.Scope,
|
Scope: claims.Scope,
|
||||||
RegisteredClaims: claims.RegisteredClaims,
|
RegisteredClaims: claims.RegisteredClaims,
|
||||||
@ -72,8 +75,9 @@ func generateJwtToken(application *Application, user *User, nonce string, scope
|
|||||||
jti := fmt.Sprintf("%s/%s", application.Owner, name)
|
jti := fmt.Sprintf("%s/%s", application.Owner, name)
|
||||||
|
|
||||||
claims := Claims{
|
claims := Claims{
|
||||||
User: user,
|
User: user,
|
||||||
Nonce: nonce,
|
TokenType: "access-token",
|
||||||
|
Nonce: nonce,
|
||||||
// FIXME: A workaround for custom claim by reusing `tag` in user info
|
// FIXME: A workaround for custom claim by reusing `tag` in user info
|
||||||
Tag: user.Tag,
|
Tag: user.Tag,
|
||||||
Scope: scope,
|
Scope: scope,
|
||||||
@ -97,10 +101,12 @@ func generateJwtToken(application *Application, user *User, nonce string, scope
|
|||||||
|
|
||||||
token = jwt.NewWithClaims(jwt.SigningMethodRS256, claimsShort)
|
token = jwt.NewWithClaims(jwt.SigningMethodRS256, claimsShort)
|
||||||
claimsShort.ExpiresAt = jwt.NewNumericDate(refreshExpireTime)
|
claimsShort.ExpiresAt = jwt.NewNumericDate(refreshExpireTime)
|
||||||
|
claimsShort.TokenType = "refresh-token"
|
||||||
refreshToken = jwt.NewWithClaims(jwt.SigningMethodRS256, claimsShort)
|
refreshToken = jwt.NewWithClaims(jwt.SigningMethodRS256, claimsShort)
|
||||||
} else {
|
} else {
|
||||||
token = jwt.NewWithClaims(jwt.SigningMethodRS256, claims)
|
token = jwt.NewWithClaims(jwt.SigningMethodRS256, claims)
|
||||||
claims.ExpiresAt = jwt.NewNumericDate(refreshExpireTime)
|
claims.ExpiresAt = jwt.NewNumericDate(refreshExpireTime)
|
||||||
|
claims.TokenType = "refresh-token"
|
||||||
refreshToken = jwt.NewWithClaims(jwt.SigningMethodRS256, claims)
|
refreshToken = jwt.NewWithClaims(jwt.SigningMethodRS256, claims)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,7 +37,7 @@ func generateRsaKeys(bitSize int, expireInYears int, commonName string, organiza
|
|||||||
// Encode private key to PKCS#1 ASN.1 PEM.
|
// Encode private key to PKCS#1 ASN.1 PEM.
|
||||||
privateKeyPem := pem.EncodeToMemory(
|
privateKeyPem := pem.EncodeToMemory(
|
||||||
&pem.Block{
|
&pem.Block{
|
||||||
Type: "PRIVATE KEY",
|
Type: "RSA PRIVATE KEY",
|
||||||
Bytes: x509.MarshalPKCS1PrivateKey(key),
|
Bytes: x509.MarshalPKCS1PrivateKey(key),
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
@ -380,6 +380,13 @@ func UpdateUser(id string, user *User, columns []string, isGlobalAdmin bool) boo
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if name != user.Name {
|
||||||
|
err := userChangeTrigger(name, user.Name)
|
||||||
|
if err != nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if user.Password == "***" {
|
if user.Password == "***" {
|
||||||
user.Password = oldUser.Password
|
user.Password = oldUser.Password
|
||||||
}
|
}
|
||||||
@ -416,6 +423,13 @@ func UpdateUserForAllFields(id string, user *User) bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if name != user.Name {
|
||||||
|
err := userChangeTrigger(name, user.Name)
|
||||||
|
if err != nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
user.UpdateUserHash()
|
user.UpdateUserHash()
|
||||||
|
|
||||||
if user.Avatar != oldUser.Avatar && user.Avatar != "" {
|
if user.Avatar != oldUser.Avatar && user.Avatar != "" {
|
||||||
@ -567,3 +581,62 @@ func ExtendUserWithRolesAndPermissions(user *User) {
|
|||||||
user.Roles = GetRolesByUser(user.GetId())
|
user.Roles = GetRolesByUser(user.GetId())
|
||||||
user.Permissions = GetPermissionsByUser(user.GetId())
|
user.Permissions = GetPermissionsByUser(user.GetId())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func userChangeTrigger(oldName string, newName string) error {
|
||||||
|
session := adapter.Engine.NewSession()
|
||||||
|
defer session.Close()
|
||||||
|
|
||||||
|
err := session.Begin()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
var roles []*Role
|
||||||
|
err = adapter.Engine.Find(&roles)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
for _, role := range roles {
|
||||||
|
for j, u := range role.Users {
|
||||||
|
// u = organization/username
|
||||||
|
split := strings.Split(u, "/")
|
||||||
|
if split[1] == oldName {
|
||||||
|
split[1] = newName
|
||||||
|
role.Users[j] = split[0] + "/" + split[1]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_, err = session.Where("name=?", role.Name).Update(role)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var permissions []*Permission
|
||||||
|
err = adapter.Engine.Find(&permissions)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
for _, permission := range permissions {
|
||||||
|
for j, u := range permission.Users {
|
||||||
|
// u = organization/username
|
||||||
|
split := strings.Split(u, "/")
|
||||||
|
if split[1] == oldName {
|
||||||
|
split[1] = newName
|
||||||
|
permission.Users[j] = split[0] + "/" + split[1]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_, err = session.Where("name=?", permission.Name).Update(permission)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
resource := new(Resource)
|
||||||
|
resource.User = newName
|
||||||
|
_, err = session.Where("user=?", oldName).Update(resource)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return session.Commit()
|
||||||
|
}
|
||||||
|
@ -21,6 +21,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/casdoor/casdoor/conf"
|
"github.com/casdoor/casdoor/conf"
|
||||||
|
"github.com/casdoor/casdoor/i18n"
|
||||||
"github.com/casdoor/casdoor/util"
|
"github.com/casdoor/casdoor/util"
|
||||||
"xorm.io/core"
|
"xorm.io/core"
|
||||||
)
|
)
|
||||||
@ -40,38 +41,7 @@ type VerificationRecord struct {
|
|||||||
IsUsed bool
|
IsUsed bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func SendVerificationCodeToEmail(organization *Organization, user *User, provider *Provider, remoteAddr string, dest string) error {
|
func IsAllowSend(user *User, remoteAddr, recordType string) error {
|
||||||
if provider == nil {
|
|
||||||
return fmt.Errorf("please set an Email provider first")
|
|
||||||
}
|
|
||||||
|
|
||||||
sender := organization.DisplayName
|
|
||||||
title := provider.Title
|
|
||||||
code := getRandomCode(6)
|
|
||||||
// "You have requested a verification code at Casdoor. Here is your code: %s, please enter in 5 minutes."
|
|
||||||
content := fmt.Sprintf(provider.Content, code)
|
|
||||||
|
|
||||||
if err := SendEmail(provider, title, content, dest, sender); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return AddToVerificationRecord(user, provider, remoteAddr, provider.Category, dest, code)
|
|
||||||
}
|
|
||||||
|
|
||||||
func SendVerificationCodeToPhone(organization *Organization, user *User, provider *Provider, remoteAddr string, dest string) error {
|
|
||||||
if provider == nil {
|
|
||||||
return errors.New("please set a SMS provider first")
|
|
||||||
}
|
|
||||||
|
|
||||||
code := getRandomCode(6)
|
|
||||||
if err := SendSms(provider, code, dest); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return AddToVerificationRecord(user, provider, remoteAddr, provider.Category, dest, code)
|
|
||||||
}
|
|
||||||
|
|
||||||
func AddToVerificationRecord(user *User, provider *Provider, remoteAddr, recordType, dest, code string) error {
|
|
||||||
var record VerificationRecord
|
var record VerificationRecord
|
||||||
record.RemoteAddr = remoteAddr
|
record.RemoteAddr = remoteAddr
|
||||||
record.Type = recordType
|
record.Type = recordType
|
||||||
@ -88,6 +58,63 @@ func AddToVerificationRecord(user *User, provider *Provider, remoteAddr, recordT
|
|||||||
return errors.New("you can only send one code in 60s")
|
return errors.New("you can only send one code in 60s")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func SendVerificationCodeToEmail(organization *Organization, user *User, provider *Provider, remoteAddr string, dest string) error {
|
||||||
|
if provider == nil {
|
||||||
|
return fmt.Errorf("please set an Email provider first")
|
||||||
|
}
|
||||||
|
|
||||||
|
sender := organization.DisplayName
|
||||||
|
title := provider.Title
|
||||||
|
code := getRandomCode(6)
|
||||||
|
// "You have requested a verification code at Casdoor. Here is your code: %s, please enter in 5 minutes."
|
||||||
|
content := fmt.Sprintf(provider.Content, code)
|
||||||
|
|
||||||
|
if err := IsAllowSend(user, remoteAddr, provider.Category); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := SendEmail(provider, title, content, dest, sender); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := AddToVerificationRecord(user, provider, remoteAddr, provider.Category, dest, code); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func SendVerificationCodeToPhone(organization *Organization, user *User, provider *Provider, remoteAddr string, dest string) error {
|
||||||
|
if provider == nil {
|
||||||
|
return errors.New("please set a SMS provider first")
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := IsAllowSend(user, remoteAddr, provider.Category); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
code := getRandomCode(6)
|
||||||
|
if err := SendSms(provider, code, dest); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := AddToVerificationRecord(user, provider, remoteAddr, provider.Category, dest, code); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func AddToVerificationRecord(user *User, provider *Provider, remoteAddr, recordType, dest, code string) error {
|
||||||
|
var record VerificationRecord
|
||||||
|
record.RemoteAddr = remoteAddr
|
||||||
|
record.Type = recordType
|
||||||
|
if user != nil {
|
||||||
|
record.User = user.GetId()
|
||||||
|
}
|
||||||
record.Owner = provider.Owner
|
record.Owner = provider.Owner
|
||||||
record.Name = util.GenerateId()
|
record.Name = util.GenerateId()
|
||||||
record.CreatedTime = util.GetCurrentTime()
|
record.CreatedTime = util.GetCurrentTime()
|
||||||
@ -98,10 +125,10 @@ func AddToVerificationRecord(user *User, provider *Provider, remoteAddr, recordT
|
|||||||
|
|
||||||
record.Receiver = dest
|
record.Receiver = dest
|
||||||
record.Code = code
|
record.Code = code
|
||||||
record.Time = now
|
record.Time = time.Now().Unix()
|
||||||
record.IsUsed = false
|
record.IsUsed = false
|
||||||
|
|
||||||
_, err = adapter.Engine.Insert(record)
|
_, err := adapter.Engine.Insert(record)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -122,11 +149,11 @@ func getVerificationRecord(dest string) *VerificationRecord {
|
|||||||
return &record
|
return &record
|
||||||
}
|
}
|
||||||
|
|
||||||
func CheckVerificationCode(dest, code string) string {
|
func CheckVerificationCode(dest, code, lang string) string {
|
||||||
record := getVerificationRecord(dest)
|
record := getVerificationRecord(dest)
|
||||||
|
|
||||||
if record == nil {
|
if record == nil {
|
||||||
return "Code has not been sent yet!"
|
return i18n.Translate(lang, "PhoneErr.CodeNotSent")
|
||||||
}
|
}
|
||||||
|
|
||||||
timeout, err := conf.GetConfigInt64("verificationCodeTimeout")
|
timeout, err := conf.GetConfigInt64("verificationCodeTimeout")
|
||||||
@ -136,7 +163,7 @@ func CheckVerificationCode(dest, code string) string {
|
|||||||
|
|
||||||
now := time.Now().Unix()
|
now := time.Now().Unix()
|
||||||
if now-record.Time > timeout*60 {
|
if now-record.Time > timeout*60 {
|
||||||
return fmt.Sprintf("You should verify your code in %d min!", timeout)
|
return fmt.Sprintf(i18n.Translate(lang, "PhoneErr.CodeTimeOut"), timeout)
|
||||||
}
|
}
|
||||||
|
|
||||||
if record.Code != code {
|
if record.Code != code {
|
||||||
|
@ -37,7 +37,7 @@ type Webhook struct {
|
|||||||
Method string `xorm:"varchar(100)" json:"method"`
|
Method string `xorm:"varchar(100)" json:"method"`
|
||||||
ContentType string `xorm:"varchar(100)" json:"contentType"`
|
ContentType string `xorm:"varchar(100)" json:"contentType"`
|
||||||
Headers []*Header `xorm:"mediumtext" json:"headers"`
|
Headers []*Header `xorm:"mediumtext" json:"headers"`
|
||||||
Events []string `xorm:"varchar(100)" json:"events"`
|
Events []string `xorm:"varchar(1000)" json:"events"`
|
||||||
IsUserExtended bool `json:"isUserExtended"`
|
IsUserExtended bool `json:"isUserExtended"`
|
||||||
IsEnabled bool `json:"isEnabled"`
|
IsEnabled bool `json:"isEnabled"`
|
||||||
}
|
}
|
||||||
|
@ -62,7 +62,7 @@ func AutoSigninFilter(ctx *context.Context) {
|
|||||||
password := ctx.Input.Query("password")
|
password := ctx.Input.Query("password")
|
||||||
if userId != "" && password != "" && ctx.Input.Query("grant_type") == "" {
|
if userId != "" && password != "" && ctx.Input.Query("grant_type") == "" {
|
||||||
owner, name := util.GetOwnerAndNameFromId(userId)
|
owner, name := util.GetOwnerAndNameFromId(userId)
|
||||||
_, msg := object.CheckUserPassword(owner, name, password)
|
_, msg := object.CheckUserPassword(owner, name, password, "en")
|
||||||
if msg != "" {
|
if msg != "" {
|
||||||
responseError(ctx, msg)
|
responseError(ctx, msg)
|
||||||
return
|
return
|
||||||
|
@ -54,6 +54,8 @@ func initAPI() {
|
|||||||
beego.Router("/api/get-saml-login", &controllers.ApiController{}, "GET:GetSamlLogin")
|
beego.Router("/api/get-saml-login", &controllers.ApiController{}, "GET:GetSamlLogin")
|
||||||
beego.Router("/api/acs", &controllers.ApiController{}, "POST:HandleSamlLogin")
|
beego.Router("/api/acs", &controllers.ApiController{}, "POST:HandleSamlLogin")
|
||||||
beego.Router("/api/saml/metadata", &controllers.ApiController{}, "GET:GetSamlMeta")
|
beego.Router("/api/saml/metadata", &controllers.ApiController{}, "GET:GetSamlMeta")
|
||||||
|
beego.Router("/api/webhook", &controllers.ApiController{}, "POST:HandleOfficialAccountEvent")
|
||||||
|
beego.Router("/api/get-webhook-event", &controllers.ApiController{}, "GET:GetWebhookEventType")
|
||||||
|
|
||||||
beego.Router("/api/get-organizations", &controllers.ApiController{}, "GET:GetOrganizations")
|
beego.Router("/api/get-organizations", &controllers.ApiController{}, "GET:GetOrganizations")
|
||||||
beego.Router("/api/get-organization", &controllers.ApiController{}, "GET:GetOrganization")
|
beego.Router("/api/get-organization", &controllers.ApiController{}, "GET:GetOrganization")
|
||||||
@ -80,6 +82,7 @@ func initAPI() {
|
|||||||
|
|
||||||
beego.Router("/api/get-permissions", &controllers.ApiController{}, "GET:GetPermissions")
|
beego.Router("/api/get-permissions", &controllers.ApiController{}, "GET:GetPermissions")
|
||||||
beego.Router("/api/get-permissions-by-submitter", &controllers.ApiController{}, "GET:GetPermissionsBySubmitter")
|
beego.Router("/api/get-permissions-by-submitter", &controllers.ApiController{}, "GET:GetPermissionsBySubmitter")
|
||||||
|
beego.Router("/api/get-permissions-by-role", &controllers.ApiController{}, "GET:GetPermissionsByRole")
|
||||||
beego.Router("/api/get-permission", &controllers.ApiController{}, "GET:GetPermission")
|
beego.Router("/api/get-permission", &controllers.ApiController{}, "GET:GetPermission")
|
||||||
beego.Router("/api/update-permission", &controllers.ApiController{}, "POST:UpdatePermission")
|
beego.Router("/api/update-permission", &controllers.ApiController{}, "POST:UpdatePermission")
|
||||||
beego.Router("/api/add-permission", &controllers.ApiController{}, "POST:AddPermission")
|
beego.Router("/api/add-permission", &controllers.ApiController{}, "POST:AddPermission")
|
||||||
@ -103,6 +106,9 @@ func initAPI() {
|
|||||||
beego.Router("/api/add-adapter", &controllers.ApiController{}, "POST:AddCasbinAdapter")
|
beego.Router("/api/add-adapter", &controllers.ApiController{}, "POST:AddCasbinAdapter")
|
||||||
beego.Router("/api/delete-adapter", &controllers.ApiController{}, "POST:DeleteCasbinAdapter")
|
beego.Router("/api/delete-adapter", &controllers.ApiController{}, "POST:DeleteCasbinAdapter")
|
||||||
beego.Router("/api/sync-policies", &controllers.ApiController{}, "GET:SyncPolicies")
|
beego.Router("/api/sync-policies", &controllers.ApiController{}, "GET:SyncPolicies")
|
||||||
|
beego.Router("/api/update-policy", &controllers.ApiController{}, "POST:UpdatePolicy")
|
||||||
|
beego.Router("/api/add-policy", &controllers.ApiController{}, "POST:AddPolicy")
|
||||||
|
beego.Router("/api/remove-policy", &controllers.ApiController{}, "POST:RemovePolicy")
|
||||||
|
|
||||||
beego.Router("/api/set-password", &controllers.ApiController{}, "POST:SetPassword")
|
beego.Router("/api/set-password", &controllers.ApiController{}, "POST:SetPassword")
|
||||||
beego.Router("/api/check-user-password", &controllers.ApiController{}, "POST:CheckUserPassword")
|
beego.Router("/api/check-user-password", &controllers.ApiController{}, "POST:CheckUserPassword")
|
||||||
@ -123,6 +129,7 @@ func initAPI() {
|
|||||||
|
|
||||||
beego.Router("/api/get-providers", &controllers.ApiController{}, "GET:GetProviders")
|
beego.Router("/api/get-providers", &controllers.ApiController{}, "GET:GetProviders")
|
||||||
beego.Router("/api/get-provider", &controllers.ApiController{}, "GET:GetProvider")
|
beego.Router("/api/get-provider", &controllers.ApiController{}, "GET:GetProvider")
|
||||||
|
beego.Router("/api/get-global-providers", &controllers.ApiController{}, "GET:GetGlobalProviders")
|
||||||
beego.Router("/api/update-provider", &controllers.ApiController{}, "POST:UpdateProvider")
|
beego.Router("/api/update-provider", &controllers.ApiController{}, "POST:UpdateProvider")
|
||||||
beego.Router("/api/add-provider", &controllers.ApiController{}, "POST:AddProvider")
|
beego.Router("/api/add-provider", &controllers.ApiController{}, "POST:AddProvider")
|
||||||
beego.Router("/api/delete-provider", &controllers.ApiController{}, "POST:DeleteProvider")
|
beego.Router("/api/delete-provider", &controllers.ApiController{}, "POST:DeleteProvider")
|
||||||
|
@ -123,8 +123,8 @@ func GenerateSimpleTimeId() string {
|
|||||||
return t
|
return t
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetId(name string) string {
|
func GetId(owner, name string) string {
|
||||||
return fmt.Sprintf("admin/%s", name)
|
return fmt.Sprintf("%s/%s", owner, name)
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetMd5Hash(text string) string {
|
func GetMd5Hash(text string) string {
|
||||||
|
@ -137,16 +137,16 @@ func TestGenerateId(t *testing.T) {
|
|||||||
func TestGetId(t *testing.T) {
|
func TestGetId(t *testing.T) {
|
||||||
scenarios := []struct {
|
scenarios := []struct {
|
||||||
description string
|
description string
|
||||||
input string
|
input []string
|
||||||
expected interface{}
|
expected interface{}
|
||||||
}{
|
}{
|
||||||
{"Scenery one", "casdoor", "admin/casdoor"},
|
{"Scenery one", []string{"admin", "casdoor"}, "admin/casdoor"},
|
||||||
{"Scenery two", "casbin", "admin/casbin"},
|
{"Scenery two", []string{"admin", "casbin"}, "admin/casbin"},
|
||||||
{"Scenery three", "lorem ipsum", "admin/lorem ipsum"},
|
{"Scenery three", []string{"test", "lorem ipsum"}, "test/lorem ipsum"},
|
||||||
}
|
}
|
||||||
for _, scenery := range scenarios {
|
for _, scenery := range scenarios {
|
||||||
t.Run(scenery.description, func(t *testing.T) {
|
t.Run(scenery.description, func(t *testing.T) {
|
||||||
actual := GetId(scenery.input)
|
actual := GetId(scenery.input[0], scenery.input[1])
|
||||||
assert.Equal(t, scenery.expected, actual, "This not is a valid MD5")
|
assert.Equal(t, scenery.expected, actual, "This not is a valid MD5")
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
29
util/struct.go
Normal file
29
util/struct.go
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
// Copyright 2022 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 util
|
||||||
|
|
||||||
|
import xormadapter "github.com/casbin/xorm-adapter/v3"
|
||||||
|
|
||||||
|
func CasbinToSlice(casbinRule xormadapter.CasbinRule) []string {
|
||||||
|
s := []string{
|
||||||
|
casbinRule.V0,
|
||||||
|
casbinRule.V1,
|
||||||
|
casbinRule.V2,
|
||||||
|
casbinRule.V3,
|
||||||
|
casbinRule.V4,
|
||||||
|
casbinRule.V5,
|
||||||
|
}
|
||||||
|
return s
|
||||||
|
}
|
@ -9,7 +9,7 @@
|
|||||||
"@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": "^4.22.8",
|
"antd": "5.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",
|
||||||
@ -70,6 +70,7 @@
|
|||||||
"eslint-plugin-react": "^7.31.1",
|
"eslint-plugin-react": "^7.31.1",
|
||||||
"husky": "^4.3.8",
|
"husky": "^4.3.8",
|
||||||
"lint-staged": "^13.0.3",
|
"lint-staged": "^13.0.3",
|
||||||
|
"path-browserify": "^1.0.1",
|
||||||
"stylelint": "^14.11.0",
|
"stylelint": "^14.11.0",
|
||||||
"stylelint-config-recommended-less": "^1.0.4",
|
"stylelint-config-recommended-less": "^1.0.4",
|
||||||
"stylelint-config-standard": "^28.0.0"
|
"stylelint-config-standard": "^28.0.0"
|
||||||
|
@ -120,7 +120,7 @@ class AccountTable extends React.Component {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: i18next.t("provider:visible"),
|
title: i18next.t("organization:Visible"),
|
||||||
dataIndex: "visible",
|
dataIndex: "visible",
|
||||||
key: "visible",
|
key: "visible",
|
||||||
width: "120px",
|
width: "120px",
|
||||||
@ -133,7 +133,7 @@ class AccountTable extends React.Component {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: i18next.t("organization:viewRule"),
|
title: i18next.t("organization:View rule"),
|
||||||
dataIndex: "viewRule",
|
dataIndex: "viewRule",
|
||||||
key: "viewRule",
|
key: "viewRule",
|
||||||
width: "155px",
|
width: "155px",
|
||||||
@ -160,7 +160,7 @@ class AccountTable extends React.Component {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: i18next.t("organization:modifyRule"),
|
title: i18next.t("organization:Modify rule"),
|
||||||
dataIndex: "modifyRule",
|
dataIndex: "modifyRule",
|
||||||
key: "modifyRule",
|
key: "modifyRule",
|
||||||
width: "155px",
|
width: "155px",
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import {Button, Card, Col, Input, InputNumber, Row, Select, Switch, Table, Tooltip} from "antd";
|
import {Button, Card, Col, Input, InputNumber, Row, Select, Switch} from "antd";
|
||||||
import * as AdapterBackend from "./backend/AdapterBackend";
|
import * as AdapterBackend from "./backend/AdapterBackend";
|
||||||
import * as OrganizationBackend from "./backend/OrganizationBackend";
|
import * as OrganizationBackend from "./backend/OrganizationBackend";
|
||||||
import * as Setting from "./Setting";
|
import * as Setting from "./Setting";
|
||||||
@ -21,7 +21,7 @@ import i18next from "i18next";
|
|||||||
|
|
||||||
import "codemirror/lib/codemirror.css";
|
import "codemirror/lib/codemirror.css";
|
||||||
import * as ModelBackend from "./backend/ModelBackend";
|
import * as ModelBackend from "./backend/ModelBackend";
|
||||||
import {EditOutlined, MinusOutlined} from "@ant-design/icons";
|
import PolicyTable from "./common/PoliciyTable";
|
||||||
require("codemirror/theme/material-darker.css");
|
require("codemirror/theme/material-darker.css");
|
||||||
require("codemirror/mode/javascript/javascript");
|
require("codemirror/mode/javascript/javascript");
|
||||||
|
|
||||||
@ -32,12 +32,11 @@ class AdapterEditPage extends React.Component {
|
|||||||
super(props);
|
super(props);
|
||||||
this.state = {
|
this.state = {
|
||||||
classes: props,
|
classes: props,
|
||||||
organizationName: props.organizationName !== undefined ? props.organizationName : props.match.params.organizationName,
|
owner: props.organizationName !== undefined ? props.organizationName : props.match.params.organizationName,
|
||||||
adapterName: props.match.params.adapterName,
|
adapterName: props.match.params.adapterName,
|
||||||
adapter: null,
|
adapter: null,
|
||||||
organizations: [],
|
organizations: [],
|
||||||
models: [],
|
models: [],
|
||||||
policyLists: [],
|
|
||||||
mode: props.location.mode !== undefined ? props.location.mode : "edit",
|
mode: props.location.mode !== undefined ? props.location.mode : "edit",
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -48,7 +47,7 @@ class AdapterEditPage extends React.Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getAdapter() {
|
getAdapter() {
|
||||||
AdapterBackend.getAdapter(this.state.organizationName, this.state.adapterName)
|
AdapterBackend.getAdapter(this.state.owner, this.state.adapterName)
|
||||||
.then((adapter) => {
|
.then((adapter) => {
|
||||||
this.setState({
|
this.setState({
|
||||||
adapter: adapter,
|
adapter: adapter,
|
||||||
@ -59,7 +58,7 @@ class AdapterEditPage extends React.Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getOrganizations() {
|
getOrganizations() {
|
||||||
OrganizationBackend.getOrganizations(this.state.organizationName)
|
OrganizationBackend.getOrganizations("admin")
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
this.setState({
|
this.setState({
|
||||||
organizations: (res.msg === undefined) ? res : [],
|
organizations: (res.msg === undefined) ? res : [],
|
||||||
@ -93,93 +92,6 @@ class AdapterEditPage extends React.Component {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
synPolicies() {
|
|
||||||
this.setState({loading: true});
|
|
||||||
AdapterBackend.syncPolicies(this.state.adapter.owner, this.state.adapter.name)
|
|
||||||
.then((res) => {
|
|
||||||
this.setState({loading: false, policyLists: res});
|
|
||||||
})
|
|
||||||
.catch(error => {
|
|
||||||
this.setState({loading: false});
|
|
||||||
Setting.showMessage("error", `Adapter failed to get policies: ${error}`);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
renderTable(table) {
|
|
||||||
const columns = [
|
|
||||||
{
|
|
||||||
title: "Rule Type",
|
|
||||||
dataIndex: "PType",
|
|
||||||
key: "PType",
|
|
||||||
width: "100px",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
title: "V0",
|
|
||||||
dataIndex: "V0",
|
|
||||||
key: "V0",
|
|
||||||
width: "100px",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
title: "V1",
|
|
||||||
dataIndex: "V1",
|
|
||||||
key: "V1",
|
|
||||||
width: "100px",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
title: "V2",
|
|
||||||
dataIndex: "V2",
|
|
||||||
key: "V2",
|
|
||||||
width: "100px",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
title: "V3",
|
|
||||||
dataIndex: "V3",
|
|
||||||
key: "V3",
|
|
||||||
width: "100px",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
title: "V4",
|
|
||||||
dataIndex: "V4",
|
|
||||||
key: "V4",
|
|
||||||
width: "100px",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
title: "V5",
|
|
||||||
dataIndex: "V5",
|
|
||||||
key: "V5",
|
|
||||||
width: "100px",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
title: "Option",
|
|
||||||
key: "option",
|
|
||||||
width: "100px",
|
|
||||||
render: (text, record, index) => {
|
|
||||||
return (
|
|
||||||
<div>
|
|
||||||
<Tooltip placement="topLeft" title="Edit">
|
|
||||||
<Button style={{marginRight: "0.5rem"}} icon={<EditOutlined />} size="small" />
|
|
||||||
</Tooltip>
|
|
||||||
<Tooltip placement="topLeft" title="Delete">
|
|
||||||
<Button icon={<MinusOutlined />} size="small" />
|
|
||||||
</Tooltip>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
},
|
|
||||||
}];
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div>
|
|
||||||
<Table
|
|
||||||
pagination={{
|
|
||||||
defaultPageSize: 10,
|
|
||||||
}}
|
|
||||||
columns={columns} dataSource={table} rowKey="name" size="middle" bordered
|
|
||||||
loading={this.state.loading}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
renderAdapter() {
|
renderAdapter() {
|
||||||
return (
|
return (
|
||||||
<Card size="small" title={
|
<Card size="small" title={
|
||||||
@ -195,7 +107,7 @@ class AdapterEditPage extends React.Component {
|
|||||||
{Setting.getLabel(i18next.t("general:Organization"), i18next.t("general:Organization - Tooltip"))} :
|
{Setting.getLabel(i18next.t("general:Organization"), i18next.t("general:Organization - Tooltip"))} :
|
||||||
</Col>
|
</Col>
|
||||||
<Col span={22} >
|
<Col span={22} >
|
||||||
<Select virtual={false} style={{width: "100%"}} value={this.state.adapter.organization} onChange={(value => {this.updateadapterField("organization", value);})}>
|
<Select virtual={false} style={{width: "100%"}} value={this.state.adapter.organization} onChange={(value => {this.updateAdapterField("organization", value);})}>
|
||||||
{
|
{
|
||||||
this.state.organizations.map((organization, index) => <Option key={index} value={organization.name}>{organization.name}</Option>)
|
this.state.organizations.map((organization, index) => <Option key={index} value={organization.name}>{organization.name}</Option>)
|
||||||
}
|
}
|
||||||
@ -329,19 +241,8 @@ class AdapterEditPage extends React.Component {
|
|||||||
<Col style={{marginTop: "5px"}} span={(Setting.isMobile()) ? 22 : 2}>
|
<Col style={{marginTop: "5px"}} span={(Setting.isMobile()) ? 22 : 2}>
|
||||||
{Setting.getLabel(i18next.t("adapter:Policies"), i18next.t("adapter:Policies - Tooltip"))} :
|
{Setting.getLabel(i18next.t("adapter:Policies"), i18next.t("adapter:Policies - Tooltip"))} :
|
||||||
</Col>
|
</Col>
|
||||||
<Col span={2}>
|
<Col span={22}>
|
||||||
<Button type="primary" onClick={() => {this.synPolicies();}}>
|
<PolicyTable owner={this.state.owner} name={this.state.adapterName} mode={this.state.mode} />
|
||||||
{i18next.t("adapter:Sync")}
|
|
||||||
</Button>
|
|
||||||
</Col>
|
|
||||||
</Row>
|
|
||||||
<Row style={{marginTop: "20px"}} >
|
|
||||||
<Col style={{marginTop: "5px"}} span={(Setting.isMobile()) ? 22 : 2}>
|
|
||||||
</Col>
|
|
||||||
<Col span={22} >
|
|
||||||
{
|
|
||||||
this.renderTable(this.state.policyLists)
|
|
||||||
}
|
|
||||||
</Col>
|
</Col>
|
||||||
</Row>
|
</Row>
|
||||||
<Row style={{marginTop: "20px"}} >
|
<Row style={{marginTop: "20px"}} >
|
||||||
@ -362,8 +263,8 @@ class AdapterEditPage extends React.Component {
|
|||||||
const adapter = Setting.deepCopy(this.state.adapter);
|
const adapter = Setting.deepCopy(this.state.adapter);
|
||||||
AdapterBackend.updateAdapter(this.state.adapter.owner, this.state.adapterName, adapter)
|
AdapterBackend.updateAdapter(this.state.adapter.owner, this.state.adapterName, adapter)
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
if (res.msg === "") {
|
if (res.status === "ok") {
|
||||||
Setting.showMessage("success", "Successfully saved");
|
Setting.showMessage("success", i18next.t("general:Successfully saved"));
|
||||||
this.setState({
|
this.setState({
|
||||||
adapterName: this.state.adapter.name,
|
adapterName: this.state.adapter.name,
|
||||||
});
|
});
|
||||||
@ -371,25 +272,29 @@ class AdapterEditPage extends React.Component {
|
|||||||
if (willExist) {
|
if (willExist) {
|
||||||
this.props.history.push("/adapters");
|
this.props.history.push("/adapters");
|
||||||
} else {
|
} else {
|
||||||
this.props.history.push(`/adapters/${this.state.adapter.name}`);
|
this.props.history.push(`/adapters/${this.state.owner}/${this.state.adapter.name}`);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Setting.showMessage("error", res.msg);
|
Setting.showMessage("error", `${i18next.t("general:Failed to save")}: ${res.msg}`);
|
||||||
this.updateAdapterField("name", this.state.adapterName);
|
this.updateAdapterField("name", this.state.adapterName);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
Setting.showMessage("error", `Failed to connect to server: ${error}`);
|
Setting.showMessage("error", `${i18next.t("general:Failed to connect to server")}: ${error}`);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
deleteAdapter() {
|
deleteAdapter() {
|
||||||
AdapterBackend.deleteAdapter(this.state.adapter)
|
AdapterBackend.deleteAdapter(this.state.adapter)
|
||||||
.then(() => {
|
.then((res) => {
|
||||||
this.props.history.push("/adapters");
|
if (res.status === "ok") {
|
||||||
|
this.props.history.push("/adapters");
|
||||||
|
} else {
|
||||||
|
Setting.showMessage("error", `${i18next.t("general:Failed to delete")}: ${res.msg}`);
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
Setting.showMessage("error", `adapter failed to delete: ${error}`);
|
Setting.showMessage("error", `${i18next.t("general:Failed to connect to server")}: ${error}`);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -45,46 +45,38 @@ class AdapterListPage extends BaseListPage {
|
|||||||
const newAdapter = this.newAdapter();
|
const newAdapter = this.newAdapter();
|
||||||
AdapterBackend.addAdapter(newAdapter)
|
AdapterBackend.addAdapter(newAdapter)
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
this.props.history.push({pathname: `/adapters/${newAdapter.owner}/${newAdapter.name}`, mode: "add"});
|
if (res.status === "ok") {
|
||||||
}
|
this.props.history.push({pathname: `/adapters/${newAdapter.organization}/${newAdapter.name}`, mode: "add"});
|
||||||
)
|
Setting.showMessage("success", i18next.t("general:Successfully added"));
|
||||||
|
} else {
|
||||||
|
Setting.showMessage("error", `${i18next.t("general:Failed to add")}: ${res.msg}`);
|
||||||
|
}
|
||||||
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
Setting.showMessage("error", `Adapter failed to add: ${error}`);
|
Setting.showMessage("error", `${i18next.t("general:Failed to connect to server")}: ${error}`);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
deleteAdapter(i) {
|
deleteAdapter(i) {
|
||||||
AdapterBackend.deleteAdapter(this.state.data[i])
|
AdapterBackend.deleteAdapter(this.state.data[i])
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
Setting.showMessage("success", "Adapter deleted successfully");
|
if (res.status === "ok") {
|
||||||
this.setState({
|
Setting.showMessage("success", i18next.t("general:Successfully deleted"));
|
||||||
data: Setting.deleteRow(this.state.data, i),
|
this.setState({
|
||||||
pagination: {total: this.state.pagination.total - 1},
|
data: Setting.deleteRow(this.state.data, i),
|
||||||
});
|
pagination: {total: this.state.pagination.total - 1},
|
||||||
}
|
});
|
||||||
)
|
} else {
|
||||||
|
Setting.showMessage("error", `${i18next.t("general:Failed to delete")}: ${res.msg}`);
|
||||||
|
}
|
||||||
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
Setting.showMessage("error", `Adapter failed to delete: ${error}`);
|
Setting.showMessage("error", `${i18next.t("general:Failed to connect to server")}: ${error}`);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
renderTable(adapters) {
|
renderTable(adapters) {
|
||||||
const columns = [
|
const columns = [
|
||||||
{
|
|
||||||
title: i18next.t("general:Organization"),
|
|
||||||
dataIndex: "organization",
|
|
||||||
key: "organization",
|
|
||||||
width: "120px",
|
|
||||||
sorter: true,
|
|
||||||
...this.getColumnSearchProps("organization"),
|
|
||||||
render: (text, record, index) => {
|
|
||||||
return (
|
|
||||||
<Link to={`/organizations/${text}`}>
|
|
||||||
{text}
|
|
||||||
</Link>
|
|
||||||
);
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
title: i18next.t("general:Name"),
|
title: i18next.t("general:Name"),
|
||||||
dataIndex: "name",
|
dataIndex: "name",
|
||||||
@ -101,6 +93,21 @@ class AdapterListPage extends BaseListPage {
|
|||||||
);
|
);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
title: i18next.t("general:Organization"),
|
||||||
|
dataIndex: "organization",
|
||||||
|
key: "organization",
|
||||||
|
width: "120px",
|
||||||
|
sorter: true,
|
||||||
|
...this.getColumnSearchProps("organization"),
|
||||||
|
render: (text, record, index) => {
|
||||||
|
return (
|
||||||
|
<Link to={`/organizations/${text}`}>
|
||||||
|
{text}
|
||||||
|
</Link>
|
||||||
|
);
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
title: i18next.t("general:Created time"),
|
title: i18next.t("general:Created time"),
|
||||||
dataIndex: "createdTime",
|
dataIndex: "createdTime",
|
||||||
@ -201,7 +208,7 @@ class AdapterListPage extends BaseListPage {
|
|||||||
title={`Sure to delete adapter: ${record.name} ?`}
|
title={`Sure to delete adapter: ${record.name} ?`}
|
||||||
onConfirm={() => this.deleteAdapter(index)}
|
onConfirm={() => this.deleteAdapter(index)}
|
||||||
>
|
>
|
||||||
<Button style={{marginBottom: "10px"}} type="danger">{i18next.t("general:Delete")}</Button>
|
<Button style={{marginBottom: "10px"}} type="primary" danger>{i18next.t("general:Delete")}</Button>
|
||||||
</Popconfirm>
|
</Popconfirm>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
414
web/src/App.js
414
web/src/App.js
@ -17,7 +17,7 @@ import "./App.less";
|
|||||||
import {Helmet} from "react-helmet";
|
import {Helmet} from "react-helmet";
|
||||||
import * as Setting from "./Setting";
|
import * as Setting from "./Setting";
|
||||||
import {BarsOutlined, DownOutlined, LogoutOutlined, SettingOutlined} from "@ant-design/icons";
|
import {BarsOutlined, DownOutlined, LogoutOutlined, SettingOutlined} from "@ant-design/icons";
|
||||||
import {Avatar, BackTop, Button, Card, Drawer, Dropdown, Layout, Menu, Result} from "antd";
|
import {Avatar, Button, Card, ConfigProvider, Drawer, Dropdown, FloatButton, Layout, Menu, Result} from "antd";
|
||||||
import {Link, Redirect, Route, Switch, withRouter} from "react-router-dom";
|
import {Link, Redirect, Route, Switch, withRouter} from "react-router-dom";
|
||||||
import OrganizationListPage from "./OrganizationListPage";
|
import OrganizationListPage from "./OrganizationListPage";
|
||||||
import OrganizationEditPage from "./OrganizationEditPage";
|
import OrganizationEditPage from "./OrganizationEditPage";
|
||||||
@ -76,7 +76,7 @@ import AdapterListPage from "./AdapterListPage";
|
|||||||
import AdapterEditPage from "./AdapterEditPage";
|
import AdapterEditPage from "./AdapterEditPage";
|
||||||
import {withTranslation} from "react-i18next";
|
import {withTranslation} from "react-i18next";
|
||||||
|
|
||||||
const {Header, Footer} = Layout;
|
const {Header, Footer, Content} = Layout;
|
||||||
|
|
||||||
class App extends Component {
|
class App extends Component {
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
@ -221,10 +221,9 @@ class App extends Component {
|
|||||||
if (res.status === "ok") {
|
if (res.status === "ok") {
|
||||||
account = res.data;
|
account = res.data;
|
||||||
account.organization = res.data2;
|
account.organization = res.data2;
|
||||||
|
|
||||||
this.setLanguage(account);
|
this.setLanguage(account);
|
||||||
} else {
|
} else {
|
||||||
if (res.msg !== "Please sign in first") {
|
if (res.data !== "Please login first") {
|
||||||
Setting.showMessage("error", `Failed to sign in: ${res.msg}`);
|
Setting.showMessage("error", `Failed to sign in: ${res.msg}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -296,23 +295,16 @@ class App extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
renderRightDropdown() {
|
renderRightDropdown() {
|
||||||
const menu = (
|
const items = [];
|
||||||
<Menu onClick={this.handleRightDropdownClick.bind(this)}>
|
items.push(Setting.getItem(<><SettingOutlined /> {i18next.t("account:My Account")}</>,
|
||||||
<Menu.Item key="/account">
|
"/account"
|
||||||
<SettingOutlined />
|
));
|
||||||
|
items.push(Setting.getItem(<><LogoutOutlined /> {i18next.t("account:Logout")}</>,
|
||||||
{i18next.t("account:My Account")}
|
"/logout"));
|
||||||
</Menu.Item>
|
const onClick = this.handleRightDropdownClick.bind(this);
|
||||||
<Menu.Item key="/logout">
|
|
||||||
<LogoutOutlined />
|
|
||||||
|
|
||||||
{i18next.t("account:Logout")}
|
|
||||||
</Menu.Item>
|
|
||||||
</Menu>
|
|
||||||
);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Dropdown key="/rightDropDown" overlay={menu} className="rightDropDown">
|
<Dropdown key="/rightDropDown" menu={{items, onClick}} className="rightDropDown">
|
||||||
<div className="ant-dropdown-link" style={{float: "right", cursor: "pointer"}}>
|
<div className="ant-dropdown-link" style={{float: "right", cursor: "pointer"}}>
|
||||||
|
|
||||||
|
|
||||||
@ -364,156 +356,89 @@ class App extends Component {
|
|||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
res.push(
|
res.push(Setting.getItem(<Link to="/">{i18next.t("general:Home")}</Link>, "/"));
|
||||||
<Menu.Item key="/">
|
|
||||||
<Link to="/">
|
|
||||||
{i18next.t("general:Home")}
|
|
||||||
</Link>
|
|
||||||
</Menu.Item>
|
|
||||||
);
|
|
||||||
|
|
||||||
if (Setting.isAdminUser(this.state.account)) {
|
if (Setting.isAdminUser(this.state.account)) {
|
||||||
res.push(
|
res.push(Setting.getItem(<Link to="/organizations">{i18next.t("general:Organizations")}</Link>,
|
||||||
<Menu.Item key="/organizations">
|
"/organizations"));
|
||||||
<Link to="/organizations">
|
|
||||||
{i18next.t("general:Organizations")}
|
|
||||||
</Link>
|
|
||||||
</Menu.Item>
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Setting.isLocalAdminUser(this.state.account)) {
|
if (Setting.isLocalAdminUser(this.state.account)) {
|
||||||
res.push(
|
res.push(Setting.getItem(<Link to="/users">{i18next.t("general:Users")}</Link>,
|
||||||
<Menu.Item key="/users">
|
"/users"
|
||||||
<Link to="/users">
|
));
|
||||||
{i18next.t("general:Users")}
|
|
||||||
</Link>
|
res.push(Setting.getItem(<Link to="/roles">{i18next.t("general:Roles")}</Link>,
|
||||||
</Menu.Item>
|
"/roles"
|
||||||
);
|
));
|
||||||
res.push(
|
|
||||||
<Menu.Item key="/roles">
|
res.push(Setting.getItem(<Link to="/permissions">{i18next.t("general:Permissions")}</Link>,
|
||||||
<Link to="/roles">
|
"/permissions"
|
||||||
{i18next.t("general:Roles")}
|
));
|
||||||
</Link>
|
|
||||||
</Menu.Item>
|
|
||||||
);
|
|
||||||
res.push(
|
|
||||||
<Menu.Item key="/permissions">
|
|
||||||
<Link to="/permissions">
|
|
||||||
{i18next.t("general:Permissions")}
|
|
||||||
</Link>
|
|
||||||
</Menu.Item>
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Setting.isAdminUser(this.state.account)) {
|
if (Setting.isAdminUser(this.state.account)) {
|
||||||
res.push(
|
res.push(Setting.getItem(<Link to="/models">{i18next.t("general:Models")}</Link>,
|
||||||
<Menu.Item key="/models">
|
"/models"
|
||||||
<Link to="/models">
|
));
|
||||||
{i18next.t("general:Models")}
|
|
||||||
</Link>
|
res.push(Setting.getItem(<Link to="/adapters">{i18next.t("general:Adapters")}</Link>,
|
||||||
</Menu.Item>
|
"/adapters"
|
||||||
);
|
));
|
||||||
res.push(
|
|
||||||
<Menu.Item key="/adapters">
|
|
||||||
<Link to="/adapters">
|
|
||||||
{i18next.t("general:Adapters")}
|
|
||||||
</Link>
|
|
||||||
</Menu.Item>
|
|
||||||
);
|
|
||||||
res.push(
|
|
||||||
<Menu.Item key="/providers">
|
|
||||||
<Link to="/providers">
|
|
||||||
{i18next.t("general:Providers")}
|
|
||||||
</Link>
|
|
||||||
</Menu.Item>
|
|
||||||
);
|
|
||||||
res.push(
|
|
||||||
<Menu.Item key="/applications">
|
|
||||||
<Link to="/applications">
|
|
||||||
{i18next.t("general:Applications")}
|
|
||||||
</Link>
|
|
||||||
</Menu.Item>
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Setting.isLocalAdminUser(this.state.account)) {
|
if (Setting.isLocalAdminUser(this.state.account)) {
|
||||||
res.push(
|
res.push(Setting.getItem(<Link to="/applications">{i18next.t("general:Applications")}</Link>,
|
||||||
<Menu.Item key="/resources">
|
"/applications"
|
||||||
<Link to="/resources">
|
));
|
||||||
{i18next.t("general:Resources")}
|
|
||||||
</Link>
|
res.push(Setting.getItem(<Link to="/providers">{i18next.t("general:Providers")}</Link>,
|
||||||
</Menu.Item>
|
"/providers"
|
||||||
);
|
));
|
||||||
res.push(
|
|
||||||
<Menu.Item key="/records">
|
res.push(Setting.getItem(<Link to="/resources">{i18next.t("general:Resources")}</Link>,
|
||||||
<Link to="/records">
|
"/resources"
|
||||||
{i18next.t("general:Records")}
|
));
|
||||||
</Link>
|
|
||||||
</Menu.Item>
|
res.push(Setting.getItem(<Link to="/records">{i18next.t("general:Records")}</Link>,
|
||||||
);
|
"/records"
|
||||||
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Setting.isAdminUser(this.state.account)) {
|
if (Setting.isAdminUser(this.state.account)) {
|
||||||
res.push(
|
res.push(Setting.getItem(<Link to="/tokens">{i18next.t("general:Tokens")}</Link>,
|
||||||
<Menu.Item key="/tokens">
|
"/tokens"
|
||||||
<Link to="/tokens">
|
));
|
||||||
{i18next.t("general:Tokens")}
|
|
||||||
</Link>
|
res.push(Setting.getItem(<Link to="/webhooks">{i18next.t("general:Webhooks")}</Link>,
|
||||||
</Menu.Item>
|
"/webhooks"
|
||||||
);
|
));
|
||||||
res.push(
|
|
||||||
<Menu.Item key="/webhooks">
|
res.push(Setting.getItem(<Link to="/syncers">{i18next.t("general:Syncers")}</Link>,
|
||||||
<Link to="/webhooks">
|
"/syncers"
|
||||||
{i18next.t("general:Webhooks")}
|
));
|
||||||
</Link>
|
|
||||||
</Menu.Item>
|
res.push(Setting.getItem(<Link to="/certs">{i18next.t("general:Certs")}</Link>,
|
||||||
);
|
"/certs"
|
||||||
res.push(
|
));
|
||||||
<Menu.Item key="/syncers">
|
|
||||||
<Link to="/syncers">
|
|
||||||
{i18next.t("general:Syncers")}
|
|
||||||
</Link>
|
|
||||||
</Menu.Item>
|
|
||||||
);
|
|
||||||
res.push(
|
|
||||||
<Menu.Item key="/certs">
|
|
||||||
<Link to="/certs">
|
|
||||||
{i18next.t("general:Certs")}
|
|
||||||
</Link>
|
|
||||||
</Menu.Item>
|
|
||||||
);
|
|
||||||
|
|
||||||
if (Conf.EnableExtraPages) {
|
if (Conf.EnableExtraPages) {
|
||||||
res.push(
|
res.push(Setting.getItem(<Link to="/products">{i18next.t("general:Products")}</Link>,
|
||||||
<Menu.Item key="/products">
|
"/products"
|
||||||
<Link to="/products">
|
));
|
||||||
{i18next.t("general:Products")}
|
|
||||||
</Link>
|
res.push(Setting.getItem(<Link to="/payments">{i18next.t("general:Payments")}</Link>,
|
||||||
</Menu.Item>
|
"/payments"
|
||||||
);
|
));
|
||||||
res.push(
|
|
||||||
<Menu.Item key="/payments">
|
res.push(Setting.getItem(<Link to="/sysinfo">{i18next.t("general:SysInfo")}</Link>,
|
||||||
<Link to="/payments">
|
"/sysinfo"
|
||||||
{i18next.t("general:Payments")}
|
));
|
||||||
</Link>
|
|
||||||
</Menu.Item>
|
|
||||||
);
|
|
||||||
res.push(
|
|
||||||
<Menu.Item key="/sysinfo">
|
|
||||||
<Link to="/sysinfo">
|
|
||||||
{i18next.t("general:SysInfo")}
|
|
||||||
</Link>
|
|
||||||
</Menu.Item>
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
res.push(
|
res.push(Setting.getItem(<a target="_blank" rel="noreferrer"
|
||||||
<Menu.Item key="/swagger">
|
href={Setting.isLocalhost() ? `${Setting.ServerUrl}/swagger` : "/swagger"}>{i18next.t("general:Swagger")}</a>,
|
||||||
<a target="_blank" rel="noreferrer" href={Setting.isLocalhost() ? `${Setting.ServerUrl}/swagger` : "/swagger"}>
|
"/swagger"
|
||||||
{i18next.t("general:Swagger")}
|
));
|
||||||
</a>
|
|
||||||
</Menu.Item>
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
@ -566,9 +491,9 @@ class App extends Component {
|
|||||||
<Route exact path="/adapters" render={(props) => this.renderLoginIfNotLoggedIn(<AdapterListPage account={this.state.account} {...props} />)} />
|
<Route exact path="/adapters" render={(props) => this.renderLoginIfNotLoggedIn(<AdapterListPage account={this.state.account} {...props} />)} />
|
||||||
<Route exact path="/adapters/:organizationName/:adapterName" render={(props) => this.renderLoginIfNotLoggedIn(<AdapterEditPage account={this.state.account} {...props} />)} />
|
<Route exact path="/adapters/:organizationName/:adapterName" render={(props) => this.renderLoginIfNotLoggedIn(<AdapterEditPage account={this.state.account} {...props} />)} />
|
||||||
<Route exact path="/providers" render={(props) => this.renderLoginIfNotLoggedIn(<ProviderListPage account={this.state.account} {...props} />)} />
|
<Route exact path="/providers" render={(props) => this.renderLoginIfNotLoggedIn(<ProviderListPage account={this.state.account} {...props} />)} />
|
||||||
<Route exact path="/providers/:providerName" render={(props) => this.renderLoginIfNotLoggedIn(<ProviderEditPage account={this.state.account} {...props} />)} />
|
<Route exact path="/providers/:organizationName/:providerName" render={(props) => this.renderLoginIfNotLoggedIn(<ProviderEditPage account={this.state.account} {...props} />)} />
|
||||||
<Route exact path="/applications" render={(props) => this.renderLoginIfNotLoggedIn(<ApplicationListPage account={this.state.account} {...props} />)} />
|
<Route exact path="/applications" render={(props) => this.renderLoginIfNotLoggedIn(<ApplicationListPage account={this.state.account} {...props} />)} />
|
||||||
<Route exact path="/applications/:applicationName" render={(props) => this.renderLoginIfNotLoggedIn(<ApplicationEditPage account={this.state.account} {...props} />)} />
|
<Route exact path="/applications/:organizationName/:applicationName" render={(props) => this.renderLoginIfNotLoggedIn(<ApplicationEditPage account={this.state.account} {...props} />)} />
|
||||||
<Route exact path="/resources" render={(props) => this.renderLoginIfNotLoggedIn(<ResourceListPage account={this.state.account} {...props} />)} />
|
<Route exact path="/resources" render={(props) => this.renderLoginIfNotLoggedIn(<ResourceListPage account={this.state.account} {...props} />)} />
|
||||||
{/* <Route exact path="/resources/:resourceName" render={(props) => this.renderLoginIfNotLoggedIn(<ResourceEditPage account={this.state.account} {...props} />)}/>*/}
|
{/* <Route exact path="/resources/:resourceName" render={(props) => this.renderLoginIfNotLoggedIn(<ResourceEditPage account={this.state.account} {...props} />)}/>*/}
|
||||||
<Route exact path="/ldap/:ldapId" render={(props) => this.renderLoginIfNotLoggedIn(<LdapEditPage account={this.state.account} {...props} />)} />
|
<Route exact path="/ldap/:ldapId" render={(props) => this.renderLoginIfNotLoggedIn(<LdapEditPage account={this.state.account} {...props} />)} />
|
||||||
@ -612,46 +537,45 @@ class App extends Component {
|
|||||||
renderContent() {
|
renderContent() {
|
||||||
if (!Setting.isMobile()) {
|
if (!Setting.isMobile()) {
|
||||||
return (
|
return (
|
||||||
<div style={{display: "flex", flex: "auto", width: "100%", flexDirection: "column"}}>
|
<Layout id="parent-area">
|
||||||
<Layout style={{display: "flex", alignItems: "stretch"}}>
|
<Header style={{marginBottom: "3px", paddingInline: 0}}>
|
||||||
<Header style={{padding: "0", marginBottom: "3px"}}>
|
{
|
||||||
|
Setting.isMobile() ? null : (
|
||||||
|
<Link to={"/"}>
|
||||||
|
<div className="logo" />
|
||||||
|
</Link>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
<div>
|
||||||
|
<Menu
|
||||||
|
// theme="dark"
|
||||||
|
items={this.renderMenu()}
|
||||||
|
mode={(Setting.isMobile() && this.isStartPages()) ? "inline" : "horizontal"}
|
||||||
|
selectedKeys={[`${this.state.selectedMenuKey}`]}
|
||||||
|
style={{lineHeight: "64px", position: "absolute", left: "145px", right: "200px"}}
|
||||||
|
>
|
||||||
|
</Menu>
|
||||||
{
|
{
|
||||||
Setting.isMobile() ? null : (
|
this.renderAccount()
|
||||||
<Link to={"/"}>
|
|
||||||
<div className="logo" />
|
|
||||||
</Link>
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
<div>
|
{this.state.account && <SelectLanguageBox languages={this.state.account.organization.languages} />}
|
||||||
<Menu
|
</div>
|
||||||
// theme="dark"
|
</Header>
|
||||||
mode={(Setting.isMobile() && this.isStartPages()) ? "inline" : "horizontal"}
|
<Content style={{backgroundColor: "#f5f5f5", alignItems: "stretch", display: "flex", flexDirection: "column"}}>
|
||||||
selectedKeys={[`${this.state.selectedMenuKey}`]}
|
<Card className="content-warp-card">
|
||||||
style={{lineHeight: "64px", position: "absolute", left: "145px", right: "200px"}}
|
{
|
||||||
>
|
this.renderRouter()
|
||||||
{
|
}
|
||||||
this.renderMenu()
|
</Card>
|
||||||
}
|
</Content>
|
||||||
</Menu>
|
{
|
||||||
{
|
this.renderFooter()
|
||||||
this.renderAccount()
|
}
|
||||||
}
|
</Layout>
|
||||||
<SelectLanguageBox />
|
|
||||||
</div>
|
|
||||||
</Header>
|
|
||||||
<Layout style={{backgroundColor: "#f5f5f5", alignItems: "stretch"}}>
|
|
||||||
<Card className="content-warp-card">
|
|
||||||
{
|
|
||||||
this.renderRouter()
|
|
||||||
}
|
|
||||||
</Card>
|
|
||||||
</Layout>
|
|
||||||
</Layout>
|
|
||||||
</div>
|
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
return (
|
return (
|
||||||
<div>
|
<Layout>
|
||||||
<Header style={{padding: "0", marginBottom: "3px"}}>
|
<Header style={{padding: "0", marginBottom: "3px"}}>
|
||||||
{
|
{
|
||||||
Setting.isMobile() ? null : (
|
Setting.isMobile() ? null : (
|
||||||
@ -663,14 +587,12 @@ class App extends Component {
|
|||||||
<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
|
||||||
// theme="dark"
|
// theme="dark"
|
||||||
|
items={this.renderMenu()}
|
||||||
mode={(Setting.isMobile()) ? "inline" : "horizontal"}
|
mode={(Setting.isMobile()) ? "inline" : "horizontal"}
|
||||||
selectedKeys={[`${this.state.selectedMenuKey}`]}
|
selectedKeys={[`${this.state.selectedMenuKey}`]}
|
||||||
style={{lineHeight: "64px"}}
|
style={{lineHeight: "64px"}}
|
||||||
onClick={this.onClose}
|
onClick={this.onClose}
|
||||||
>
|
>
|
||||||
{
|
|
||||||
this.renderMenu()
|
|
||||||
}
|
|
||||||
</Menu>
|
</Menu>
|
||||||
</Drawer>
|
</Drawer>
|
||||||
<Button icon={<BarsOutlined />} onClick={this.showMenu} type="text">
|
<Button icon={<BarsOutlined />} onClick={this.showMenu} type="text">
|
||||||
@ -680,13 +602,14 @@ class App extends Component {
|
|||||||
{
|
{
|
||||||
this.renderAccount()
|
this.renderAccount()
|
||||||
}
|
}
|
||||||
<SelectLanguageBox />
|
{this.state.account && <SelectLanguageBox languages={this.state.account.organization.languages} />}
|
||||||
</div>
|
</div>
|
||||||
</Header>
|
</Header>
|
||||||
{
|
<Content style={{display: "flex", flexDirection: "column"}} >{
|
||||||
this.renderRouter()
|
this.renderRouter()}
|
||||||
}
|
</Content>
|
||||||
</div>
|
{this.renderFooter()}
|
||||||
|
</Layout>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -723,50 +646,47 @@ class App extends Component {
|
|||||||
renderPage() {
|
renderPage() {
|
||||||
if (this.isDoorPages()) {
|
if (this.isDoorPages()) {
|
||||||
return (
|
return (
|
||||||
<div style={{display: "flex", flexDirection: "column", height: "100%"}}>
|
<>
|
||||||
<div id="login-content-wrap" style={{flexDirection: "column"}}>
|
<Layout id="parent-area">
|
||||||
<Switch>
|
<Content style={{display: "flex", justifyContent: "center"}}>
|
||||||
<Route exact path="/signup" render={(props) => this.renderHomeIfLoggedIn(<SignupPage account={this.state.account} {...props} />)} />
|
<Switch>
|
||||||
<Route exact path="/signup/:applicationName" render={(props) => this.renderHomeIfLoggedIn(<SignupPage account={this.state.account} {...props} onUpdateAccount={(account) => {this.onUpdateAccount(account);}} />)} />
|
<Route exact path="/signup" render={(props) => this.renderHomeIfLoggedIn(<SignupPage account={this.state.account} {...props} />)} />
|
||||||
<Route exact path="/login" render={(props) => this.renderHomeIfLoggedIn(<SelfLoginPage account={this.state.account} {...props} />)} />
|
<Route exact path="/signup/:applicationName" render={(props) => this.renderHomeIfLoggedIn(<SignupPage account={this.state.account} {...props} onUpdateAccount={(account) => {this.onUpdateAccount(account);}} />)} />
|
||||||
<Route exact path="/login/:owner" render={(props) => this.renderHomeIfLoggedIn(<SelfLoginPage account={this.state.account} {...props} />)} />
|
<Route exact path="/login" render={(props) => this.renderHomeIfLoggedIn(<SelfLoginPage account={this.state.account} {...props} />)} />
|
||||||
<Route exact path="/auto-signup/oauth/authorize" render={(props) => <LoginPage account={this.state.account} type={"code"} mode={"signup"} {...props} onUpdateAccount={(account) => {this.onUpdateAccount(account);}} />} />
|
<Route exact path="/login/:owner" render={(props) => this.renderHomeIfLoggedIn(<SelfLoginPage account={this.state.account} {...props} />)} />
|
||||||
<Route exact path="/signup/oauth/authorize" render={(props) => <SignupPage account={this.state.account} {...props} onUpdateAccount={(account) => {this.onUpdateAccount(account);}} />} />
|
<Route exact path="/auto-signup/oauth/authorize" render={(props) => <LoginPage account={this.state.account} type={"code"} mode={"signup"} {...props} onUpdateAccount={(account) => {this.onUpdateAccount(account);}} />} />
|
||||||
<Route exact path="/login/oauth/authorize" render={(props) => <LoginPage account={this.state.account} type={"code"} mode={"signin"} {...props} onUpdateAccount={(account) => {this.onUpdateAccount(account);}} />} />
|
<Route exact path="/signup/oauth/authorize" render={(props) => <SignupPage account={this.state.account} {...props} onUpdateAccount={(account) => {this.onUpdateAccount(account);}} />} />
|
||||||
<Route exact path="/login/saml/authorize/:owner/:applicationName" render={(props) => <LoginPage account={this.state.account} type={"saml"} mode={"signin"} {...props} onUpdateAccount={(account) => {this.onUpdateAccount(account);}} />} />
|
<Route exact path="/login/oauth/authorize" render={(props) => <LoginPage account={this.state.account} type={"code"} mode={"signin"} {...props} onUpdateAccount={(account) => {this.onUpdateAccount(account);}} />} />
|
||||||
<Route exact path="/cas/:owner/:casApplicationName/logout" render={(props) => this.renderHomeIfLoggedIn(<CasLogout clearAccount={() => this.setState({account: null})} {...props} />)} />
|
<Route exact path="/login/saml/authorize/:owner/:applicationName" render={(props) => <LoginPage account={this.state.account} type={"saml"} mode={"signin"} {...props} onUpdateAccount={(account) => {this.onUpdateAccount(account);}} />} />
|
||||||
<Route exact path="/cas/:owner/:casApplicationName/login" render={(props) => {return (<LoginPage type={"cas"} mode={"signup"} account={this.state.account} {...props} />);}} />
|
<Route exact path="/cas/:owner/:casApplicationName/logout" render={(props) => this.renderHomeIfLoggedIn(<CasLogout clearAccount={() => this.setState({account: null})} {...props} />)} />
|
||||||
<Route exact path="/callback" component={AuthCallback} />
|
<Route exact path="/cas/:owner/:casApplicationName/login" render={(props) => {return (<LoginPage type={"cas"} mode={"signup"} account={this.state.account} {...props} />);}} />
|
||||||
<Route exact path="/callback/saml" component={SamlCallback} />
|
<Route exact path="/callback" component={AuthCallback} />
|
||||||
<Route exact path="/forget" render={(props) => this.renderHomeIfLoggedIn(<SelfForgetPage {...props} />)} />
|
<Route exact path="/callback/saml" component={SamlCallback} />
|
||||||
<Route exact path="/forget/:applicationName" render={(props) => this.renderHomeIfLoggedIn(<ForgetPage {...props} />)} />
|
<Route exact path="/forget" render={(props) => this.renderHomeIfLoggedIn(<SelfForgetPage {...props} />)} />
|
||||||
<Route exact path="/prompt" render={(props) => this.renderLoginIfNotLoggedIn(<PromptPage account={this.state.account} {...props} />)} />
|
<Route exact path="/forget/:applicationName" render={(props) => this.renderHomeIfLoggedIn(<ForgetPage {...props} />)} />
|
||||||
<Route exact path="/prompt/:applicationName" render={(props) => this.renderLoginIfNotLoggedIn(<PromptPage account={this.state.account} onUpdateAccount={(account) => {this.onUpdateAccount(account);}} {...props} />)} />
|
<Route exact path="/prompt" render={(props) => this.renderLoginIfNotLoggedIn(<PromptPage account={this.state.account} {...props} />)} />
|
||||||
<Route exact path="/sysinfo" render={(props) => this.renderLoginIfNotLoggedIn(<SystemInfo {...props} />)} />
|
<Route exact path="/prompt/:applicationName" render={(props) => this.renderLoginIfNotLoggedIn(<PromptPage account={this.state.account} onUpdateAccount={(account) => {this.onUpdateAccount(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 exact path="/sysinfo" render={(props) => this.renderLoginIfNotLoggedIn(<SystemInfo {...props} />)} />
|
||||||
extra={<a href="/"><Button type="primary">{i18next.t("general:Back Home")}</Button></a>} />} />
|
<Route path="" render={() => <Result status="404" title="404 NOT FOUND" subTitle={i18next.t("general:Sorry, the page you visited does not exist.")}
|
||||||
</Switch>
|
extra={<a href="/"><Button type="primary">{i18next.t("general:Back Home")}</Button></a>} />} />
|
||||||
</div>
|
</Switch>
|
||||||
{
|
</Content>
|
||||||
this.renderFooter()
|
{
|
||||||
}
|
this.renderFooter()
|
||||||
</div>
|
}
|
||||||
|
</Layout>
|
||||||
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div id="parent-area">
|
<>
|
||||||
<BackTop />
|
<FloatButton.BackTop />
|
||||||
<CustomGithubCorner />
|
<CustomGithubCorner />
|
||||||
<div id="content-wrap" style={{flexDirection: "column"}}>
|
|
||||||
{
|
|
||||||
this.renderContent()
|
|
||||||
}
|
|
||||||
</div>
|
|
||||||
{
|
{
|
||||||
this.renderFooter()
|
this.renderContent()
|
||||||
}
|
}
|
||||||
</div>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -777,9 +697,16 @@ class App extends Component {
|
|||||||
<Helmet>
|
<Helmet>
|
||||||
<link rel="icon" href={"https://cdn.casdoor.com/static/favicon.png"} />
|
<link rel="icon" href={"https://cdn.casdoor.com/static/favicon.png"} />
|
||||||
</Helmet>
|
</Helmet>
|
||||||
{
|
<ConfigProvider theme={{
|
||||||
this.renderPage()
|
token: {
|
||||||
}
|
colorPrimary: "rgb(89,54,213)",
|
||||||
|
colorInfo: "rgb(89,54,213)",
|
||||||
|
},
|
||||||
|
}}>
|
||||||
|
{
|
||||||
|
this.renderPage()
|
||||||
|
}
|
||||||
|
</ConfigProvider>
|
||||||
</React.Fragment>
|
</React.Fragment>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -791,9 +718,16 @@ class App extends Component {
|
|||||||
<title>{organization.displayName}</title>
|
<title>{organization.displayName}</title>
|
||||||
<link rel="icon" href={organization.favicon} />
|
<link rel="icon" href={organization.favicon} />
|
||||||
</Helmet>
|
</Helmet>
|
||||||
{
|
<ConfigProvider theme={{
|
||||||
this.renderPage()
|
token: {
|
||||||
}
|
colorPrimary: "rgb(89,54,213)",
|
||||||
|
colorInfo: "rgb(89,54,213)",
|
||||||
|
},
|
||||||
|
}}>
|
||||||
|
{
|
||||||
|
this.renderPage()
|
||||||
|
}
|
||||||
|
</ConfigProvider>
|
||||||
</React.Fragment>
|
</React.Fragment>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
/* stylelint-disable at-rule-name-case */
|
/* stylelint-disable at-rule-name-case */
|
||||||
/* stylelint-disable selector-class-pattern */
|
/* stylelint-disable selector-class-pattern */
|
||||||
@import "~antd/dist/antd.less";
|
|
||||||
|
|
||||||
@StaticBaseUrl: "https://cdn.casbin.org";
|
@StaticBaseUrl: "https://cdn.casbin.org";
|
||||||
|
|
||||||
@ -28,6 +27,11 @@
|
|||||||
color: #61dafb;
|
color: #61dafb;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
img {
|
||||||
|
border-style: none;
|
||||||
|
vertical-align: middle;
|
||||||
|
}
|
||||||
|
|
||||||
#root {
|
#root {
|
||||||
height: 100%;
|
height: 100%;
|
||||||
}
|
}
|
||||||
@ -40,29 +44,8 @@
|
|||||||
background-color: #f5f5f5;
|
background-color: #f5f5f5;
|
||||||
}
|
}
|
||||||
|
|
||||||
#content-wrap {
|
.panel-logo {
|
||||||
display: flex;
|
margin-bottom: 30px;
|
||||||
flex: 1 1 0;
|
|
||||||
align-items: stretch;
|
|
||||||
width: 100%;
|
|
||||||
}
|
|
||||||
|
|
||||||
#login-content-wrap {
|
|
||||||
display: flex;
|
|
||||||
flex: 1 1 0;
|
|
||||||
width: 100%;
|
|
||||||
}
|
|
||||||
|
|
||||||
#footer {
|
|
||||||
bottom: 0;
|
|
||||||
width: 100%;
|
|
||||||
height: 70px; /* Footer height */
|
|
||||||
}
|
|
||||||
|
|
||||||
#language-box-corner {
|
|
||||||
position: absolute;
|
|
||||||
top: 75px;
|
|
||||||
right: 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.language-box {
|
.language-box {
|
||||||
@ -94,6 +77,39 @@
|
|||||||
align-items: stretch;
|
align-items: stretch;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.side-image {
|
||||||
|
display: none;
|
||||||
|
|
||||||
|
@media screen and (min-width: 1100px) {
|
||||||
|
display: block;
|
||||||
|
position: relative;
|
||||||
|
width: 500px;
|
||||||
|
border-right: 0.5px solid rgb(196 203 215);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.forget-content {
|
||||||
|
padding: 10px 100px 20px;
|
||||||
|
margin: 30px auto;
|
||||||
|
border: 2px solid #fff;
|
||||||
|
border-radius: 7px;
|
||||||
|
background-color: rgb(255 255 255);
|
||||||
|
box-shadow: 0 0 20px rgb(0 0 0 / 20%);
|
||||||
|
}
|
||||||
|
|
||||||
|
.login-panel {
|
||||||
|
margin-top: 50px;
|
||||||
|
margin-bottom: 50px;
|
||||||
|
display: flex;
|
||||||
|
background-color: rgb(255 255 255);
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
.login-form {
|
||||||
|
text-align: center;
|
||||||
|
padding: 30px;
|
||||||
|
}
|
||||||
|
|
||||||
.login-content {
|
.login-content {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: row;
|
flex-direction: row;
|
||||||
@ -105,7 +121,9 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.loginBackground {
|
.loginBackground {
|
||||||
height: 100%;
|
flex: auto;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
background: #fff no-repeat;
|
background: #fff no-repeat;
|
||||||
background-size: 100% 100%;
|
background-size: 100% 100%;
|
||||||
background-attachment: fixed;
|
background-attachment: fixed;
|
||||||
|
@ -32,6 +32,7 @@ import copy from "copy-to-clipboard";
|
|||||||
|
|
||||||
import {Controlled as CodeMirror} from "react-codemirror2";
|
import {Controlled as CodeMirror} from "react-codemirror2";
|
||||||
import "codemirror/lib/codemirror.css";
|
import "codemirror/lib/codemirror.css";
|
||||||
|
|
||||||
require("codemirror/theme/material-darker.css");
|
require("codemirror/theme/material-darker.css");
|
||||||
require("codemirror/mode/htmlmixed/htmlmixed");
|
require("codemirror/mode/htmlmixed/htmlmixed");
|
||||||
require("codemirror/mode/xml/xml");
|
require("codemirror/mode/xml/xml");
|
||||||
@ -39,19 +40,61 @@ require("codemirror/mode/css/css");
|
|||||||
|
|
||||||
const {Option} = Select;
|
const {Option} = Select;
|
||||||
|
|
||||||
const template = {
|
const template = `<style>
|
||||||
padding: "30px",
|
.login-panel{
|
||||||
border: "2px solid #ffffff",
|
padding: 40px 70px 0 70px;
|
||||||
borderRadius: "7px",
|
border-radius: 10px;
|
||||||
backgroundColor: "#ffffff",
|
background-color: #ffffff;
|
||||||
boxShadow: " 0px 0px 20px rgba(0, 0, 0, 0.20)",
|
box-shadow: 0 0 30px 20px rgba(0, 0, 0, 0.20);
|
||||||
};
|
}
|
||||||
|
</style>`;
|
||||||
|
|
||||||
|
const previewGrid = Setting.isMobile() ? 22 : 11;
|
||||||
|
const previewWidth = Setting.isMobile() ? "110%" : "90%";
|
||||||
|
|
||||||
|
const sideTemplate = `<style>
|
||||||
|
.left-model{
|
||||||
|
text-align: center;
|
||||||
|
padding: 30px;
|
||||||
|
background-color: #8ca0ed;
|
||||||
|
position: absolute;
|
||||||
|
transform: none;
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
}
|
||||||
|
.side-logo{
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
.side-logo span {
|
||||||
|
font-family: Montserrat, sans-serif;
|
||||||
|
font-weight: 900;
|
||||||
|
font-size: 2.4rem;
|
||||||
|
line-height: 1.3;
|
||||||
|
margin-left: 16px;
|
||||||
|
color: #404040;
|
||||||
|
}
|
||||||
|
.img{
|
||||||
|
max-width: none;
|
||||||
|
margin: 41px 0 13px;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
<div class="left-model">
|
||||||
|
<span class="side-logo"> <img src="https://cdn.casbin.org/img/casdoor-logo_1185x256.png" alt="Casdoor" style="width: 120px">
|
||||||
|
<span>SSO</span>
|
||||||
|
</span>
|
||||||
|
<div class="img">
|
||||||
|
<img src="https://cdn.casbin.org/img/casbin.svg" alt="Casdoor"/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
|
||||||
class ApplicationEditPage extends React.Component {
|
class ApplicationEditPage extends React.Component {
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props);
|
super(props);
|
||||||
this.state = {
|
this.state = {
|
||||||
classes: props,
|
classes: props,
|
||||||
|
owner: props.organizationName !== undefined ? props.organizationName : props.match.params.organizationName,
|
||||||
applicationName: props.match.params.applicationName,
|
applicationName: props.match.params.applicationName,
|
||||||
application: null,
|
application: null,
|
||||||
organizations: [],
|
organizations: [],
|
||||||
@ -102,12 +145,11 @@ class ApplicationEditPage extends React.Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getProviders() {
|
getProviders() {
|
||||||
ProviderBackend.getProviders("admin")
|
ProviderBackend.getProviders(this.state.owner).then((res => {
|
||||||
.then((res) => {
|
this.setState({
|
||||||
this.setState({
|
providers: res,
|
||||||
providers: res,
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
getSamlMetadata() {
|
getSamlMetadata() {
|
||||||
@ -149,7 +191,7 @@ class ApplicationEditPage extends React.Component {
|
|||||||
Setting.showMessage("success", i18next.t("application:File uploaded successfully"));
|
Setting.showMessage("success", i18next.t("application:File uploaded successfully"));
|
||||||
this.updateApplicationField("termsOfUse", res.data);
|
this.updateApplicationField("termsOfUse", res.data);
|
||||||
} else {
|
} else {
|
||||||
Setting.showMessage("error", res.msg);
|
Setting.showMessage("error", `${i18next.t("general:Failed to save")}: ${res.msg}`);
|
||||||
}
|
}
|
||||||
}).finally(() => {
|
}).finally(() => {
|
||||||
this.setState({uploading: false});
|
this.setState({uploading: false});
|
||||||
@ -157,7 +199,6 @@ class ApplicationEditPage extends React.Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
renderApplication() {
|
renderApplication() {
|
||||||
const preview = JSON.stringify(template, null, 2);
|
|
||||||
return (
|
return (
|
||||||
<Card size="small" title={
|
<Card size="small" title={
|
||||||
<div>
|
<div>
|
||||||
@ -239,7 +280,7 @@ class ApplicationEditPage extends React.Component {
|
|||||||
{Setting.getLabel(i18next.t("general:Organization"), i18next.t("general:Organization - Tooltip"))} :
|
{Setting.getLabel(i18next.t("general:Organization"), i18next.t("general:Organization - Tooltip"))} :
|
||||||
</Col>
|
</Col>
|
||||||
<Col span={22} >
|
<Col span={22} >
|
||||||
<Select virtual={false} style={{width: "100%"}} value={this.state.application.organization} onChange={(value => {this.updateApplicationField("organization", value);})}>
|
<Select virtual={false} style={{width: "100%"}} disabled={!Setting.isAdminUser(this.props.account)} value={this.state.application.organization} onChange={(value => {this.updateApplicationField("organization", value);})}>
|
||||||
{
|
{
|
||||||
this.state.organizations.map((organization, index) => <Option key={index} value={organization.name}>{organization.name}</Option>)
|
this.state.organizations.map((organization, index) => <Option key={index} value={organization.name}>{organization.name}</Option>)
|
||||||
}
|
}
|
||||||
@ -562,10 +603,10 @@ class ApplicationEditPage extends React.Component {
|
|||||||
</Col>
|
</Col>
|
||||||
<Col span={22} style={(Setting.isMobile()) ? {maxWidth: "100%"} : {}}>
|
<Col span={22} style={(Setting.isMobile()) ? {maxWidth: "100%"} : {}}>
|
||||||
<Row style={{marginTop: "20px"}} >
|
<Row style={{marginTop: "20px"}} >
|
||||||
<Col style={{marginTop: "5px"}} span={(Setting.isMobile()) ? 22 : 1}>
|
<Col style={{marginTop: "5px"}} span={(Setting.isMobile()) ? 22 : 2}>
|
||||||
{Setting.getLabel(i18next.t("general:URL"), i18next.t("general:URL - Tooltip"))} :
|
{Setting.getLabel(i18next.t("general:URL"), i18next.t("general:URL - Tooltip"))} :
|
||||||
</Col>
|
</Col>
|
||||||
<Col span={23} >
|
<Col span={22} >
|
||||||
<Input prefix={<LinkOutlined />} value={this.state.application.formBackgroundUrl} onChange={e => {
|
<Input prefix={<LinkOutlined />} value={this.state.application.formBackgroundUrl} onChange={e => {
|
||||||
this.updateApplicationField("formBackgroundUrl", e.target.value);
|
this.updateApplicationField("formBackgroundUrl", e.target.value);
|
||||||
}} />
|
}} />
|
||||||
@ -590,7 +631,7 @@ class ApplicationEditPage extends React.Component {
|
|||||||
<Col span={22}>
|
<Col span={22}>
|
||||||
<Popover placement="right" content={
|
<Popover placement="right" content={
|
||||||
<div style={{width: "900px", height: "300px"}} >
|
<div style={{width: "900px", height: "300px"}} >
|
||||||
<CodeMirror value={this.state.application.formCss === "" ? preview : this.state.application.formCss}
|
<CodeMirror value={this.state.application.formCss === "" ? template : this.state.application.formCss}
|
||||||
options={{mode: "css", theme: "material-darker"}}
|
options={{mode: "css", theme: "material-darker"}}
|
||||||
onBeforeChange={(editor, data, value) => {
|
onBeforeChange={(editor, data, value) => {
|
||||||
this.updateApplicationField("formCss", value);
|
this.updateApplicationField("formCss", value);
|
||||||
@ -606,14 +647,42 @@ class ApplicationEditPage extends React.Component {
|
|||||||
</Row>
|
</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("application:From position"), i18next.t("application:From position - Tooltip"))} :
|
{Setting.getLabel(i18next.t("application:Form position"), i18next.t("application:Form position - Tooltip"))} :
|
||||||
</Col>
|
</Col>
|
||||||
<Col span={22} >
|
<Col span={22} >
|
||||||
<Radio.Group onChange={e => {this.updateApplicationField("formOffset", e.target.value);}} value={this.state.application.formOffset !== 0 ? this.state.application.formOffset : 8}>
|
<Row style={{marginTop: "20px"}} >
|
||||||
<Radio.Button value={2}>left</Radio.Button>
|
<Radio.Group onChange={e => {this.updateApplicationField("formOffset", e.target.value);}} value={this.state.application.formOffset}>
|
||||||
<Radio.Button value={8}>center</Radio.Button>
|
<Radio.Button value={1}>{i18next.t("application:Left")}</Radio.Button>
|
||||||
<Radio.Button value={14}>right</Radio.Button>
|
<Radio.Button value={2}>{i18next.t("application:Center")}</Radio.Button>
|
||||||
</Radio.Group>
|
<Radio.Button value={3}>{i18next.t("application:Right")}</Radio.Button>
|
||||||
|
<Radio.Button value={4}>
|
||||||
|
{i18next.t("application:Enable side panel")}
|
||||||
|
</Radio.Button>
|
||||||
|
</Radio.Group>
|
||||||
|
</Row>
|
||||||
|
{this.state.application.formOffset === 4 ?
|
||||||
|
<Row style={{marginTop: "20px"}} >
|
||||||
|
<Col style={{marginTop: "5px"}} span={(Setting.isMobile()) ? 22 : 3}>
|
||||||
|
{Setting.getLabel(i18next.t("application:Side panel HTML"), i18next.t("application:Side panel HTML - Tooltip"))} :
|
||||||
|
</Col>
|
||||||
|
<Col span={21} >
|
||||||
|
<Popover placement="right" content={
|
||||||
|
<div style={{width: "900px", height: "300px"}} >
|
||||||
|
<CodeMirror value={this.state.application.formSideHtml === "" ? sideTemplate : this.state.application.formSideHtml}
|
||||||
|
options={{mode: "htmlmixed", theme: "material-darker"}}
|
||||||
|
onBeforeChange={(editor, data, value) => {
|
||||||
|
this.updateApplicationField("formSideHtml", value);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
} title={i18next.t("application:Side panel HTML - Edit")} trigger="click">
|
||||||
|
<Input value={this.state.application.formSideHtml} style={{marginBottom: "10px"}} onChange={e => {
|
||||||
|
this.updateApplicationField("formSideHtml", e.target.value);
|
||||||
|
}} />
|
||||||
|
</Popover>
|
||||||
|
</Col>
|
||||||
|
</Row>
|
||||||
|
: null}
|
||||||
</Col>
|
</Col>
|
||||||
</Row>
|
</Row>
|
||||||
{
|
{
|
||||||
@ -654,7 +723,7 @@ class ApplicationEditPage extends React.Component {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<React.Fragment>
|
<React.Fragment>
|
||||||
<Col span={11}>
|
<Col span={previewGrid}>
|
||||||
<Button style={{marginBottom: "10px"}} type="primary" shape="round" icon={<CopyOutlined />} onClick={() => {
|
<Button style={{marginBottom: "10px"}} type="primary" shape="round" icon={<CopyOutlined />} onClick={() => {
|
||||||
copy(`${window.location.origin}${signUpUrl}`);
|
copy(`${window.location.origin}${signUpUrl}`);
|
||||||
Setting.showMessage("success", i18next.t("application:Signup page URL copied to clipboard successfully, please paste it into the incognito window or another browser"));
|
Setting.showMessage("success", i18next.t("application:Signup page URL copied to clipboard successfully, please paste it into the incognito window or another browser"));
|
||||||
@ -663,7 +732,7 @@ class ApplicationEditPage extends React.Component {
|
|||||||
{i18next.t("application:Copy signup page URL")}
|
{i18next.t("application:Copy signup page URL")}
|
||||||
</Button>
|
</Button>
|
||||||
<br />
|
<br />
|
||||||
<div style={{position: "relative", width: "90%", border: "1px solid rgb(217,217,217)", boxShadow: "10px 10px 5px #888888", alignItems: "center", overflow: "auto", flexDirection: "column", flex: "auto"}}>
|
<div style={{position: "relative", width: previewWidth, border: "1px solid rgb(217,217,217)", boxShadow: "10px 10px 5px #888888", alignItems: "center", overflow: "auto", flexDirection: "column", flex: "auto"}}>
|
||||||
{
|
{
|
||||||
this.state.application.enablePassword ? (
|
this.state.application.enablePassword ? (
|
||||||
<SignupPage application={this.state.application} />
|
<SignupPage application={this.state.application} />
|
||||||
@ -674,8 +743,8 @@ class ApplicationEditPage extends React.Component {
|
|||||||
<div style={maskStyle} />
|
<div style={maskStyle} />
|
||||||
</div>
|
</div>
|
||||||
</Col>
|
</Col>
|
||||||
<Col span={11}>
|
<Col span={previewGrid}>
|
||||||
<Button style={{marginBottom: "10px"}} type="primary" shape="round" icon={<CopyOutlined />} onClick={() => {
|
<Button style={{marginBottom: "10px", marginTop: Setting.isMobile() ? "15px" : "0"}} type="primary" shape="round" icon={<CopyOutlined />} onClick={() => {
|
||||||
copy(`${window.location.origin}${signInUrl}`);
|
copy(`${window.location.origin}${signInUrl}`);
|
||||||
Setting.showMessage("success", i18next.t("application:Signin page URL copied to clipboard successfully, please paste it into the incognito window or another browser"));
|
Setting.showMessage("success", i18next.t("application:Signin page URL copied to clipboard successfully, please paste it into the incognito window or another browser"));
|
||||||
}}
|
}}
|
||||||
@ -683,7 +752,7 @@ class ApplicationEditPage extends React.Component {
|
|||||||
{i18next.t("application:Copy signin page URL")}
|
{i18next.t("application:Copy signin page URL")}
|
||||||
</Button>
|
</Button>
|
||||||
<br />
|
<br />
|
||||||
<div style={{position: "relative", width: "90%", border: "1px solid rgb(217,217,217)", boxShadow: "10px 10px 5px #888888", alignItems: "center", overflow: "auto", flexDirection: "column", flex: "auto"}}>
|
<div style={{position: "relative", width: previewWidth, border: "1px solid rgb(217,217,217)", boxShadow: "10px 10px 5px #888888", alignItems: "center", overflow: "auto", flexDirection: "column", flex: "auto"}}>
|
||||||
<LoginPage type={"login"} mode={"signin"} application={this.state.application} />
|
<LoginPage type={"login"} mode={"signin"} application={this.state.application} />
|
||||||
<div style={maskStyle} />
|
<div style={maskStyle} />
|
||||||
</div>
|
</div>
|
||||||
@ -696,7 +765,7 @@ class ApplicationEditPage extends React.Component {
|
|||||||
const promptUrl = `/prompt/${this.state.application.name}`;
|
const promptUrl = `/prompt/${this.state.application.name}`;
|
||||||
const maskStyle = {position: "absolute", top: "0px", left: "0px", zIndex: 10, height: "100%", width: "100%", background: "rgba(0,0,0,0.4)"};
|
const maskStyle = {position: "absolute", top: "0px", left: "0px", zIndex: 10, height: "100%", width: "100%", background: "rgba(0,0,0,0.4)"};
|
||||||
return (
|
return (
|
||||||
<Col span={11}>
|
<Col span={previewGrid}>
|
||||||
<Button style={{marginBottom: "10px"}} type="primary" shape="round" icon={<CopyOutlined />} onClick={() => {
|
<Button style={{marginBottom: "10px"}} type="primary" shape="round" icon={<CopyOutlined />} onClick={() => {
|
||||||
copy(`${window.location.origin}${promptUrl}`);
|
copy(`${window.location.origin}${promptUrl}`);
|
||||||
Setting.showMessage("success", i18next.t("application:Prompt page URL copied to clipboard successfully, please paste it into the incognito window or another browser"));
|
Setting.showMessage("success", i18next.t("application:Prompt page URL copied to clipboard successfully, please paste it into the incognito window or another browser"));
|
||||||
@ -705,9 +774,9 @@ class ApplicationEditPage extends React.Component {
|
|||||||
{i18next.t("application:Copy prompt page URL")}
|
{i18next.t("application:Copy prompt page URL")}
|
||||||
</Button>
|
</Button>
|
||||||
<br />
|
<br />
|
||||||
<div style={{position: "relative", width: "90%", border: "1px solid rgb(217,217,217)", boxShadow: "10px 10px 5px #888888", flexDirection: "column", flex: "auto"}}>
|
<div style={{position: "relative", width: previewWidth, border: "1px solid rgb(217,217,217)", boxShadow: "10px 10px 5px #888888", flexDirection: "column", flex: "auto"}}>
|
||||||
<PromptPage application={this.state.application} account={this.props.account} />
|
<PromptPage application={this.state.application} account={this.props.account} />
|
||||||
<div style={maskStyle}></div>
|
<div style={maskStyle} />
|
||||||
</div>
|
</div>
|
||||||
</Col>
|
</Col>
|
||||||
);
|
);
|
||||||
@ -715,10 +784,10 @@ class ApplicationEditPage extends React.Component {
|
|||||||
|
|
||||||
submitApplicationEdit(willExist) {
|
submitApplicationEdit(willExist) {
|
||||||
const application = Setting.deepCopy(this.state.application);
|
const application = Setting.deepCopy(this.state.application);
|
||||||
ApplicationBackend.updateApplication(this.state.application.owner, this.state.applicationName, application)
|
ApplicationBackend.updateApplication("admin", this.state.applicationName, application)
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
if (res.msg === "") {
|
if (res.status === "ok") {
|
||||||
Setting.showMessage("success", "Successfully saved");
|
Setting.showMessage("success", i18next.t("general:Successfully saved"));
|
||||||
this.setState({
|
this.setState({
|
||||||
applicationName: this.state.application.name,
|
applicationName: this.state.application.name,
|
||||||
});
|
});
|
||||||
@ -726,25 +795,29 @@ class ApplicationEditPage extends React.Component {
|
|||||||
if (willExist) {
|
if (willExist) {
|
||||||
this.props.history.push("/applications");
|
this.props.history.push("/applications");
|
||||||
} else {
|
} else {
|
||||||
this.props.history.push(`/applications/${this.state.application.name}`);
|
this.props.history.push(`/applications/${this.state.application.organization}/${this.state.application.name}`);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Setting.showMessage("error", res.msg);
|
Setting.showMessage("error", `${i18next.t("general:Failed to save")}: ${res.msg}`);
|
||||||
this.updateApplicationField("name", this.state.applicationName);
|
this.updateApplicationField("name", this.state.applicationName);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
Setting.showMessage("error", `Failed to connect to server: ${error}`);
|
Setting.showMessage("error", `${i18next.t("general:Failed to connect to server")}: ${error}`);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
deleteApplication() {
|
deleteApplication() {
|
||||||
ApplicationBackend.deleteApplication(this.state.application)
|
ApplicationBackend.deleteApplication(this.state.application)
|
||||||
.then(() => {
|
.then((res) => {
|
||||||
this.props.history.push("/applications");
|
if (res.status === "ok") {
|
||||||
|
this.props.history.push("/applications");
|
||||||
|
} else {
|
||||||
|
Setting.showMessage("error", `${i18next.t("general:Failed to delete")}: ${res.msg}`);
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
Setting.showMessage("error", `Application failed to delete: ${error}`);
|
Setting.showMessage("error", `${i18next.t("general:Failed to connect to server")}: ${error}`);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,11 +23,28 @@ import i18next from "i18next";
|
|||||||
import BaseListPage from "./BaseListPage";
|
import BaseListPage from "./BaseListPage";
|
||||||
|
|
||||||
class ApplicationListPage extends BaseListPage {
|
class ApplicationListPage extends BaseListPage {
|
||||||
|
constructor(props) {
|
||||||
|
super(props);
|
||||||
|
this.state = {
|
||||||
|
classes: props,
|
||||||
|
organizationName: props.account.owner,
|
||||||
|
data: [],
|
||||||
|
pagination: {
|
||||||
|
current: 1,
|
||||||
|
pageSize: 10,
|
||||||
|
},
|
||||||
|
loading: false,
|
||||||
|
searchText: "",
|
||||||
|
searchedColumn: "",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
newApplication() {
|
newApplication() {
|
||||||
const randomName = Setting.getRandomName();
|
const randomName = Setting.getRandomName();
|
||||||
return {
|
return {
|
||||||
owner: "admin", // this.props.account.applicationname,
|
owner: "admin", // this.props.account.applicationName,
|
||||||
name: `application_${randomName}`,
|
name: `application_${randomName}`,
|
||||||
|
organization: this.state.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`,
|
||||||
@ -53,7 +70,7 @@ class ApplicationListPage extends BaseListPage {
|
|||||||
redirectUris: ["http://localhost:9000/callback"],
|
redirectUris: ["http://localhost:9000/callback"],
|
||||||
tokenFormat: "JWT",
|
tokenFormat: "JWT",
|
||||||
expireInHours: 24 * 7,
|
expireInHours: 24 * 7,
|
||||||
formOffset: 8,
|
formOffset: 2,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -61,26 +78,33 @@ class ApplicationListPage extends BaseListPage {
|
|||||||
const newApplication = this.newApplication();
|
const newApplication = this.newApplication();
|
||||||
ApplicationBackend.addApplication(newApplication)
|
ApplicationBackend.addApplication(newApplication)
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
this.props.history.push({pathname: `/applications/${newApplication.name}`, mode: "add"});
|
if (res.status === "ok") {
|
||||||
}
|
this.props.history.push({pathname: `/applications/${newApplication.organization}/${newApplication.name}`, mode: "add"});
|
||||||
)
|
Setting.showMessage("success", i18next.t("general:Successfully added"));
|
||||||
|
} else {
|
||||||
|
Setting.showMessage("error", `${i18next.t("general:Failed to add")}: ${res.msg}`);
|
||||||
|
}
|
||||||
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
Setting.showMessage("error", `Application failed to add: ${error}`);
|
Setting.showMessage("error", `${i18next.t("general:Failed to connect to server")}: ${error}`);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
deleteApplication(i) {
|
deleteApplication(i) {
|
||||||
ApplicationBackend.deleteApplication(this.state.data[i])
|
ApplicationBackend.deleteApplication(this.state.data[i])
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
Setting.showMessage("success", "Application deleted successfully");
|
if (res.status === "ok") {
|
||||||
this.setState({
|
Setting.showMessage("success", i18next.t("general:Successfully deleted"));
|
||||||
data: Setting.deleteRow(this.state.data, i),
|
this.setState({
|
||||||
pagination: {total: this.state.pagination.total - 1},
|
data: Setting.deleteRow(this.state.data, i),
|
||||||
});
|
pagination: {total: this.state.pagination.total - 1},
|
||||||
}
|
});
|
||||||
)
|
} else {
|
||||||
|
Setting.showMessage("error", `${i18next.t("general:Failed to delete")}: ${res.msg}`);
|
||||||
|
}
|
||||||
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
Setting.showMessage("error", `Application failed to delete: ${error}`);
|
Setting.showMessage("error", `${i18next.t("general:Failed to connect to server")}: ${error}`);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -96,7 +120,7 @@ class ApplicationListPage extends BaseListPage {
|
|||||||
...this.getColumnSearchProps("name"),
|
...this.getColumnSearchProps("name"),
|
||||||
render: (text, record, index) => {
|
render: (text, record, index) => {
|
||||||
return (
|
return (
|
||||||
<Link to={`/applications/${text}`}>
|
<Link to={`/applications/${record.organization}/${text}`}>
|
||||||
{text}
|
{text}
|
||||||
</Link>
|
</Link>
|
||||||
);
|
);
|
||||||
@ -213,13 +237,13 @@ class ApplicationListPage extends BaseListPage {
|
|||||||
render: (text, record, index) => {
|
render: (text, record, index) => {
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<Button style={{marginTop: "10px", marginBottom: "10px", marginRight: "10px"}} type="primary" onClick={() => this.props.history.push(`/applications/${record.name}`)}>{i18next.t("general:Edit")}</Button>
|
<Button style={{marginTop: "10px", marginBottom: "10px", marginRight: "10px"}} type="primary" onClick={() => this.props.history.push(`/applications/${record.organization}/${record.name}`)}>{i18next.t("general:Edit")}</Button>
|
||||||
<Popconfirm
|
<Popconfirm
|
||||||
title={`Sure to delete application: ${record.name} ?`}
|
title={`Sure to delete application: ${record.name} ?`}
|
||||||
onConfirm={() => this.deleteApplication(index)}
|
onConfirm={() => this.deleteApplication(index)}
|
||||||
disabled={record.name === "app-built-in"}
|
disabled={record.name === "app-built-in"}
|
||||||
>
|
>
|
||||||
<Button style={{marginBottom: "10px"}} disabled={record.name === "app-built-in"} type="danger">{i18next.t("general:Delete")}</Button>
|
<Button style={{marginBottom: "10px"}} disabled={record.name === "app-built-in"} type="primary" danger>{i18next.t("general:Delete")}</Button>
|
||||||
</Popconfirm>
|
</Popconfirm>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
@ -254,7 +278,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});
|
||||||
ApplicationBackend.getApplications("admin", params.pagination.current, params.pagination.pageSize, field, value, sortField, sortOrder)
|
(Setting.isAdminUser(this.props.account) ? ApplicationBackend.getApplications("admin", params.pagination.current, params.pagination.pageSize, field, value, sortField, sortOrder) :
|
||||||
|
ApplicationBackend.getApplicationsByOrganization("admin", this.state.organizationName, params.pagination.current, params.pagination.pageSize, field, value, sortField, sortOrder))
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
if (res.status === "ok") {
|
if (res.status === "ok") {
|
||||||
this.setState({
|
this.setState({
|
||||||
|
@ -87,7 +87,7 @@ class BaseListPage extends React.Component {
|
|||||||
record[dataIndex]
|
record[dataIndex]
|
||||||
? record[dataIndex].toString().toLowerCase().includes(value.toLowerCase())
|
? record[dataIndex].toString().toLowerCase().includes(value.toLowerCase())
|
||||||
: "",
|
: "",
|
||||||
onFilterDropdownVisibleChange: visible => {
|
onFilterDropdownOpenChange: visible => {
|
||||||
if (visible) {
|
if (visible) {
|
||||||
setTimeout(() => this.searchInput.select(), 100);
|
setTimeout(() => this.searchInput.select(), 100);
|
||||||
}
|
}
|
||||||
|
@ -65,6 +65,7 @@ class CertEditPage extends React.Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
renderCert() {
|
renderCert() {
|
||||||
|
const editorWidth = Setting.isMobile() ? 22 : 9;
|
||||||
return (
|
return (
|
||||||
<Card size="small" title={
|
<Card size="small" title={
|
||||||
<div>
|
<div>
|
||||||
@ -166,7 +167,7 @@ class CertEditPage extends React.Component {
|
|||||||
<Col style={{marginTop: "5px"}} span={(Setting.isMobile()) ? 22 : 2}>
|
<Col style={{marginTop: "5px"}} span={(Setting.isMobile()) ? 22 : 2}>
|
||||||
{Setting.getLabel(i18next.t("cert:Certificate"), i18next.t("cert:Certificate - Tooltip"))} :
|
{Setting.getLabel(i18next.t("cert:Certificate"), i18next.t("cert:Certificate - Tooltip"))} :
|
||||||
</Col>
|
</Col>
|
||||||
<Col span={9} >
|
<Col span={editorWidth} >
|
||||||
<Button style={{marginRight: "10px", marginBottom: "10px"}} onClick={() => {
|
<Button style={{marginRight: "10px", marginBottom: "10px"}} onClick={() => {
|
||||||
copy(this.state.cert.certificate);
|
copy(this.state.cert.certificate);
|
||||||
Setting.showMessage("success", i18next.t("cert:Certificate copied to clipboard successfully"));
|
Setting.showMessage("success", i18next.t("cert:Certificate copied to clipboard successfully"));
|
||||||
@ -189,7 +190,7 @@ class CertEditPage extends React.Component {
|
|||||||
<Col style={{marginTop: "5px"}} span={(Setting.isMobile()) ? 22 : 2}>
|
<Col style={{marginTop: "5px"}} span={(Setting.isMobile()) ? 22 : 2}>
|
||||||
{Setting.getLabel(i18next.t("cert:Private key"), i18next.t("cert:Private key - Tooltip"))} :
|
{Setting.getLabel(i18next.t("cert:Private key"), i18next.t("cert:Private key - Tooltip"))} :
|
||||||
</Col>
|
</Col>
|
||||||
<Col span={9} >
|
<Col span={editorWidth} >
|
||||||
<Button style={{marginRight: "10px", marginBottom: "10px"}} onClick={() => {
|
<Button style={{marginRight: "10px", marginBottom: "10px"}} onClick={() => {
|
||||||
copy(this.state.cert.privateKey);
|
copy(this.state.cert.privateKey);
|
||||||
Setting.showMessage("success", i18next.t("cert:Private key copied to clipboard successfully"));
|
Setting.showMessage("success", i18next.t("cert:Private key copied to clipboard successfully"));
|
||||||
@ -217,8 +218,8 @@ class CertEditPage extends React.Component {
|
|||||||
const cert = Setting.deepCopy(this.state.cert);
|
const cert = Setting.deepCopy(this.state.cert);
|
||||||
CertBackend.updateCert(this.state.cert.owner, this.state.certName, cert)
|
CertBackend.updateCert(this.state.cert.owner, this.state.certName, cert)
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
if (res.msg === "") {
|
if (res.status === "ok") {
|
||||||
Setting.showMessage("success", "Successfully saved");
|
Setting.showMessage("success", i18next.t("general:Successfully saved"));
|
||||||
this.setState({
|
this.setState({
|
||||||
certName: this.state.cert.name,
|
certName: this.state.cert.name,
|
||||||
});
|
});
|
||||||
@ -229,22 +230,26 @@ class CertEditPage extends React.Component {
|
|||||||
this.props.history.push(`/certs/${this.state.cert.name}`);
|
this.props.history.push(`/certs/${this.state.cert.name}`);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Setting.showMessage("error", res.msg);
|
Setting.showMessage("error", `${i18next.t("general:Failed to save")}: ${res.msg}`);
|
||||||
this.updateCertField("name", this.state.certName);
|
this.updateCertField("name", this.state.certName);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
Setting.showMessage("error", `Failed to connect to server: ${error}`);
|
Setting.showMessage("error", `${i18next.t("general:Failed to connect to server")}: ${error}`);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
deleteCert() {
|
deleteCert() {
|
||||||
CertBackend.deleteCert(this.state.cert)
|
CertBackend.deleteCert(this.state.cert)
|
||||||
.then(() => {
|
.then((res) => {
|
||||||
this.props.history.push("/certs");
|
if (res.status === "ok") {
|
||||||
|
this.props.history.push("/certs");
|
||||||
|
} else {
|
||||||
|
Setting.showMessage("error", `${i18next.t("general:Failed to delete")}: ${res.msg}`);
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
Setting.showMessage("error", `Cert failed to delete: ${error}`);
|
Setting.showMessage("error", `${i18next.t("general:Failed to connect to server")}: ${error}`);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,26 +43,33 @@ class CertListPage extends BaseListPage {
|
|||||||
const newCert = this.newCert();
|
const newCert = this.newCert();
|
||||||
CertBackend.addCert(newCert)
|
CertBackend.addCert(newCert)
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
this.props.history.push({pathname: `/certs/${newCert.name}`, mode: "add"});
|
if (res.status === "ok") {
|
||||||
}
|
this.props.history.push({pathname: `/certs/${newCert.name}`, mode: "add"});
|
||||||
)
|
Setting.showMessage("success", i18next.t("general:Successfully added"));
|
||||||
|
} else {
|
||||||
|
Setting.showMessage("error", `${i18next.t("general:Failed to add")}: ${res.msg}`);
|
||||||
|
}
|
||||||
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
Setting.showMessage("error", `Cert failed to add: ${error}`);
|
Setting.showMessage("error", `${i18next.t("general:Failed to connect to server")}: ${error}`);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
deleteCert(i) {
|
deleteCert(i) {
|
||||||
CertBackend.deleteCert(this.state.data[i])
|
CertBackend.deleteCert(this.state.data[i])
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
Setting.showMessage("success", "Cert deleted successfully");
|
if (res.status === "ok") {
|
||||||
this.setState({
|
Setting.showMessage("success", i18next.t("general:Successfully deleted"));
|
||||||
data: Setting.deleteRow(this.state.data, i),
|
this.setState({
|
||||||
pagination: {total: this.state.pagination.total - 1},
|
data: Setting.deleteRow(this.state.data, i),
|
||||||
});
|
pagination: {total: this.state.pagination.total - 1},
|
||||||
}
|
});
|
||||||
)
|
} else {
|
||||||
|
Setting.showMessage("error", `${i18next.t("general:Failed to delete")}: ${res.msg}`);
|
||||||
|
}
|
||||||
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
Setting.showMessage("error", `Cert failed to delete: ${error}`);
|
Setting.showMessage("error", `${i18next.t("general:Failed to connect to server")}: ${error}`);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -165,7 +172,7 @@ class CertListPage extends BaseListPage {
|
|||||||
title={`Sure to delete cert: ${record.name} ?`}
|
title={`Sure to delete cert: ${record.name} ?`}
|
||||||
onConfirm={() => this.deleteCert(index)}
|
onConfirm={() => this.deleteCert(index)}
|
||||||
>
|
>
|
||||||
<Button style={{marginBottom: "10px"}} type="danger">{i18next.t("general:Delete")}</Button>
|
<Button style={{marginBottom: "10px"}} type="primary" danger>{i18next.t("general:Delete")}</Button>
|
||||||
</Popconfirm>
|
</Popconfirm>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
@ -30,6 +30,7 @@ export const CropperDiv = (props) => {
|
|||||||
const {title} = props;
|
const {title} = props;
|
||||||
const {user} = props;
|
const {user} = props;
|
||||||
const {buttonText} = props;
|
const {buttonText} = props;
|
||||||
|
const {organization} = props;
|
||||||
let uploadButton;
|
let uploadButton;
|
||||||
|
|
||||||
const onChange = (e) => {
|
const onChange = (e) => {
|
||||||
@ -92,9 +93,8 @@ export const CropperDiv = (props) => {
|
|||||||
|
|
||||||
const getOptions = (data) => {
|
const getOptions = (data) => {
|
||||||
const options = [];
|
const options = [];
|
||||||
if (props.account.organization.defaultAvatar !== null) {
|
options.push({value: organization?.defaultAvatar});
|
||||||
options.push({value: props.account.organization.defaultAvatar});
|
|
||||||
}
|
|
||||||
for (let i = 0; i < data.length; i++) {
|
for (let i = 0; i < data.length; i++) {
|
||||||
if (data[i].fileType === "image") {
|
if (data[i].fileType === "image") {
|
||||||
const url = `${data[i].url}`;
|
const url = `${data[i].url}`;
|
||||||
@ -125,7 +125,7 @@ export const CropperDiv = (props) => {
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
ResourceBackend.getResources(props.account.owner, props.account.name, "", "", "", "", "", "")
|
ResourceBackend.getResources(user.owner, user.name, "", "", "", "", "", "")
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
setOptions(getOptions(res));
|
setOptions(getOptions(res));
|
||||||
@ -140,7 +140,7 @@ export const CropperDiv = (props) => {
|
|||||||
<Modal
|
<Modal
|
||||||
maskClosable={false}
|
maskClosable={false}
|
||||||
title={title}
|
title={title}
|
||||||
visible={visible}
|
open={visible}
|
||||||
okText={i18next.t("user:Upload a photo")}
|
okText={i18next.t("user:Upload a photo")}
|
||||||
confirmLoading={confirmLoading}
|
confirmLoading={confirmLoading}
|
||||||
onCancel={handleCancel}
|
onCancel={handleCancel}
|
||||||
|
@ -144,7 +144,7 @@ class LdapListPage extends React.Component {
|
|||||||
onConfirm={() => this.deleteLdap(index)}
|
onConfirm={() => this.deleteLdap(index)}
|
||||||
>
|
>
|
||||||
<Button style={{marginBottom: "10px"}}
|
<Button style={{marginBottom: "10px"}}
|
||||||
type="danger">{i18next.t("general:Delete")}</Button>
|
type="primary" danger>{i18next.t("general:Delete")}</Button>
|
||||||
</Popconfirm>
|
</Popconfirm>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
@ -81,7 +81,7 @@ class LdapTable extends React.Component {
|
|||||||
table = Setting.deleteRow(table, i);
|
table = Setting.deleteRow(table, i);
|
||||||
this.updateTable(table);
|
this.updateTable(table);
|
||||||
} else {
|
} else {
|
||||||
Setting.showMessage("error", res.msg);
|
Setting.showMessage("error", `${i18next.t("general:Failed to save")}: ${res.msg}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@ -162,7 +162,7 @@ class LdapTable extends React.Component {
|
|||||||
onConfirm={() => this.deleteRow(table, index)}
|
onConfirm={() => this.deleteRow(table, index)}
|
||||||
>
|
>
|
||||||
<Button style={{marginBottom: "10px"}}
|
<Button style={{marginBottom: "10px"}}
|
||||||
type="danger">{i18next.t("general:Delete")}</Button>
|
type="primary" danger>{i18next.t("general:Delete")}</Button>
|
||||||
</Popconfirm>
|
</Popconfirm>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
@ -158,8 +158,8 @@ class ModelEditPage extends React.Component {
|
|||||||
const model = Setting.deepCopy(this.state.model);
|
const model = Setting.deepCopy(this.state.model);
|
||||||
ModelBackend.updateModel(this.state.organizationName, this.state.modelName, model)
|
ModelBackend.updateModel(this.state.organizationName, this.state.modelName, model)
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
if (res.msg === "") {
|
if (res.status === "ok") {
|
||||||
Setting.showMessage("success", "Successfully saved");
|
Setting.showMessage("success", i18next.t("general:Successfully saved"));
|
||||||
this.setState({
|
this.setState({
|
||||||
modelName: this.state.model.name,
|
modelName: this.state.model.name,
|
||||||
});
|
});
|
||||||
@ -170,22 +170,26 @@ class ModelEditPage extends React.Component {
|
|||||||
this.props.history.push(`/models/${this.state.model.owner}/${this.state.model.name}`);
|
this.props.history.push(`/models/${this.state.model.owner}/${this.state.model.name}`);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Setting.showMessage("error", res.msg);
|
Setting.showMessage("error", `${i18next.t("general:Failed to save")}: ${res.msg}`);
|
||||||
this.updateModelField("name", this.state.modelName);
|
this.updateModelField("name", this.state.modelName);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
Setting.showMessage("error", `Failed to connect to server: ${error}`);
|
Setting.showMessage("error", `${i18next.t("general:Failed to connect to server")}: ${error}`);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
deleteModel() {
|
deleteModel() {
|
||||||
ModelBackend.deleteModel(this.state.model)
|
ModelBackend.deleteModel(this.state.model)
|
||||||
.then(() => {
|
.then((res) => {
|
||||||
this.props.history.push("/models");
|
if (res.status === "ok") {
|
||||||
|
this.props.history.push("/models");
|
||||||
|
} else {
|
||||||
|
Setting.showMessage("error", `${i18next.t("general:Failed to delete")}: ${res.msg}`);
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
Setting.showMessage("error", `Model failed to delete: ${error}`);
|
Setting.showMessage("error", `${i18next.t("general:Failed to connect to server")}: ${error}`);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,46 +38,38 @@ class ModelListPage extends BaseListPage {
|
|||||||
const newModel = this.newModel();
|
const newModel = this.newModel();
|
||||||
ModelBackend.addModel(newModel)
|
ModelBackend.addModel(newModel)
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
this.props.history.push({pathname: `/models/${newModel.owner}/${newModel.name}`, mode: "add"});
|
if (res.status === "ok") {
|
||||||
}
|
this.props.history.push({pathname: `/models/${newModel.owner}/${newModel.name}`, mode: "add"});
|
||||||
)
|
Setting.showMessage("success", i18next.t("general:Successfully added"));
|
||||||
|
} else {
|
||||||
|
Setting.showMessage("error", `${i18next.t("general:Failed to add")}: ${res.msg}`);
|
||||||
|
}
|
||||||
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
Setting.showMessage("error", `Model failed to add: ${error}`);
|
Setting.showMessage("error", `${i18next.t("general:Failed to connect to server")}: ${error}`);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
deleteModel(i) {
|
deleteModel(i) {
|
||||||
ModelBackend.deleteModel(this.state.data[i])
|
ModelBackend.deleteModel(this.state.data[i])
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
Setting.showMessage("success", "Model deleted successfully");
|
if (res.status === "ok") {
|
||||||
this.setState({
|
Setting.showMessage("success", i18next.t("general:Successfully deleted"));
|
||||||
data: Setting.deleteRow(this.state.data, i),
|
this.setState({
|
||||||
pagination: {total: this.state.pagination.total - 1},
|
data: Setting.deleteRow(this.state.data, i),
|
||||||
});
|
pagination: {total: this.state.pagination.total - 1},
|
||||||
}
|
});
|
||||||
)
|
} else {
|
||||||
|
Setting.showMessage("error", `${i18next.t("general:Failed to delete")}: ${res.msg}`);
|
||||||
|
}
|
||||||
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
Setting.showMessage("error", `Model failed to delete: ${error}`);
|
Setting.showMessage("error", `${i18next.t("general:Failed to connect to server")}: ${error}`);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
renderTable(models) {
|
renderTable(models) {
|
||||||
const columns = [
|
const columns = [
|
||||||
{
|
|
||||||
title: i18next.t("general:Organization"),
|
|
||||||
dataIndex: "owner",
|
|
||||||
key: "owner",
|
|
||||||
width: "120px",
|
|
||||||
sorter: true,
|
|
||||||
...this.getColumnSearchProps("owner"),
|
|
||||||
render: (text, record, index) => {
|
|
||||||
return (
|
|
||||||
<Link to={`/organizations/${text}`}>
|
|
||||||
{text}
|
|
||||||
</Link>
|
|
||||||
);
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
title: i18next.t("general:Name"),
|
title: i18next.t("general:Name"),
|
||||||
dataIndex: "name",
|
dataIndex: "name",
|
||||||
@ -94,6 +86,21 @@ class ModelListPage extends BaseListPage {
|
|||||||
);
|
);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
title: i18next.t("general:Organization"),
|
||||||
|
dataIndex: "owner",
|
||||||
|
key: "owner",
|
||||||
|
width: "120px",
|
||||||
|
sorter: true,
|
||||||
|
...this.getColumnSearchProps("owner"),
|
||||||
|
render: (text, record, index) => {
|
||||||
|
return (
|
||||||
|
<Link to={`/organizations/${text}`}>
|
||||||
|
{text}
|
||||||
|
</Link>
|
||||||
|
);
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
title: i18next.t("general:Created time"),
|
title: i18next.t("general:Created time"),
|
||||||
dataIndex: "createdTime",
|
dataIndex: "createdTime",
|
||||||
@ -139,7 +146,7 @@ class ModelListPage extends BaseListPage {
|
|||||||
title={`Sure to delete model: ${record.name} ?`}
|
title={`Sure to delete model: ${record.name} ?`}
|
||||||
onConfirm={() => this.deleteModel(index)}
|
onConfirm={() => this.deleteModel(index)}
|
||||||
>
|
>
|
||||||
<Button style={{marginBottom: "10px"}} type="danger">{i18next.t("general:Delete")}</Button>
|
<Button style={{marginBottom: "10px"}} type="primary" danger>{i18next.t("general:Delete")}</Button>
|
||||||
</Popconfirm>
|
</Popconfirm>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
@ -255,6 +255,31 @@ class OrganizationEditPage extends React.Component {
|
|||||||
}} />
|
}} />
|
||||||
</Col>
|
</Col>
|
||||||
</Row>
|
</Row>
|
||||||
|
<Row style={{marginTop: "20px"}} >
|
||||||
|
<Col style={{marginTop: "5px"}} span={(Setting.isMobile()) ? 22 : 2}>
|
||||||
|
{Setting.getLabel(i18next.t("general:Languages"), i18next.t("general:Languages - Tooltip"))} :
|
||||||
|
</Col>
|
||||||
|
<Col span={22} >
|
||||||
|
<Select virtual={false} mode="tags" style={{width: "100%"}}
|
||||||
|
value={this.state.organization.languages}
|
||||||
|
onChange={(value => {
|
||||||
|
this.updateOrganizationField("languages", value);
|
||||||
|
})} >
|
||||||
|
{
|
||||||
|
[
|
||||||
|
{value: "en", label: "English"},
|
||||||
|
{value: "zh", label: "简体中文"},
|
||||||
|
{value: "es", label: "Español"},
|
||||||
|
{value: "fr", label: "Français"},
|
||||||
|
{value: "de", label: "Deutsch"},
|
||||||
|
{value: "ja", label: "日本語"},
|
||||||
|
{value: "ko", label: "한국어"},
|
||||||
|
{value: "ru", label: "Русский"},
|
||||||
|
].map((item, index) => <Option key={index} value={item.value}>{item.label}</Option>)
|
||||||
|
}
|
||||||
|
</Select>
|
||||||
|
</Col>
|
||||||
|
</Row>
|
||||||
<Row style={{marginTop: "20px"}} >
|
<Row style={{marginTop: "20px"}} >
|
||||||
<Col style={{marginTop: "5px"}} span={(Setting.isMobile()) ? 19 : 2}>
|
<Col style={{marginTop: "5px"}} span={(Setting.isMobile()) ? 19 : 2}>
|
||||||
{Setting.getLabel(i18next.t("organization:Soft deletion"), i18next.t("organization:Soft deletion - Tooltip"))} :
|
{Setting.getLabel(i18next.t("organization:Soft deletion"), i18next.t("organization:Soft deletion - Tooltip"))} :
|
||||||
@ -310,8 +335,8 @@ class OrganizationEditPage extends React.Component {
|
|||||||
const organization = Setting.deepCopy(this.state.organization);
|
const organization = Setting.deepCopy(this.state.organization);
|
||||||
OrganizationBackend.updateOrganization(this.state.organization.owner, this.state.organizationName, organization)
|
OrganizationBackend.updateOrganization(this.state.organization.owner, this.state.organizationName, organization)
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
if (res.msg === "") {
|
if (res.status === "ok") {
|
||||||
Setting.showMessage("success", "Successfully saved");
|
Setting.showMessage("success", i18next.t("general:Successfully saved"));
|
||||||
this.setState({
|
this.setState({
|
||||||
organizationName: this.state.organization.name,
|
organizationName: this.state.organization.name,
|
||||||
});
|
});
|
||||||
@ -322,22 +347,26 @@ class OrganizationEditPage extends React.Component {
|
|||||||
this.props.history.push(`/organizations/${this.state.organization.name}`);
|
this.props.history.push(`/organizations/${this.state.organization.name}`);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Setting.showMessage("error", res.msg);
|
Setting.showMessage("error", `${i18next.t("general:Failed to save")}: ${res.msg}`);
|
||||||
this.updateOrganizationField("name", this.state.organizationName);
|
this.updateOrganizationField("name", this.state.organizationName);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
Setting.showMessage("error", `Failed to connect to server: ${error}`);
|
Setting.showMessage("error", `${i18next.t("general:Failed to connect to server")}: ${error}`);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
deleteOrganization() {
|
deleteOrganization() {
|
||||||
OrganizationBackend.deleteOrganization(this.state.organization)
|
OrganizationBackend.deleteOrganization(this.state.organization)
|
||||||
.then(() => {
|
.then((res) => {
|
||||||
this.props.history.push("/organizations");
|
if (res.status === "ok") {
|
||||||
|
this.props.history.push("/organizations");
|
||||||
|
} else {
|
||||||
|
Setting.showMessage("error", `${i18next.t("general:Failed to delete")}: ${res.msg}`);
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
Setting.showMessage("error", `Failed to connect to server: ${error}`);
|
Setting.showMessage("error", `${i18next.t("general:Failed to connect to server")}: ${error}`);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,6 +37,7 @@ class OrganizationListPage extends BaseListPage {
|
|||||||
defaultAvatar: `${Setting.StaticBaseUrl}/img/casbin.svg`,
|
defaultAvatar: `${Setting.StaticBaseUrl}/img/casbin.svg`,
|
||||||
defaultApplication: "",
|
defaultApplication: "",
|
||||||
tags: [],
|
tags: [],
|
||||||
|
languages: ["en", "zh", "es", "fr", "de", "ja", "ko", "ru"],
|
||||||
masterPassword: "",
|
masterPassword: "",
|
||||||
enableSoftDeletion: false,
|
enableSoftDeletion: false,
|
||||||
isProfilePublic: true,
|
isProfilePublic: true,
|
||||||
@ -74,26 +75,33 @@ class OrganizationListPage extends BaseListPage {
|
|||||||
const newOrganization = this.newOrganization();
|
const newOrganization = this.newOrganization();
|
||||||
OrganizationBackend.addOrganization(newOrganization)
|
OrganizationBackend.addOrganization(newOrganization)
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
this.props.history.push({pathname: `/organizations/${newOrganization.name}`, mode: "add"});
|
if (res.status === "ok") {
|
||||||
}
|
this.props.history.push({pathname: `/organizations/${newOrganization.name}`, mode: "add"});
|
||||||
)
|
Setting.showMessage("success", i18next.t("general:Successfully added"));
|
||||||
|
} else {
|
||||||
|
Setting.showMessage("error", `${i18next.t("general:Failed to add")}: ${res.msg}`);
|
||||||
|
}
|
||||||
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
Setting.showMessage("error", `Organization failed to add: ${error}`);
|
Setting.showMessage("error", `${i18next.t("general:Failed to connect to server")}: ${error}`);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
deleteOrganization(i) {
|
deleteOrganization(i) {
|
||||||
OrganizationBackend.deleteOrganization(this.state.data[i])
|
OrganizationBackend.deleteOrganization(this.state.data[i])
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
Setting.showMessage("success", "Organization deleted successfully");
|
if (res.status === "ok") {
|
||||||
this.setState({
|
Setting.showMessage("success", i18next.t("general:Successfully deleted"));
|
||||||
data: Setting.deleteRow(this.state.data, i),
|
this.setState({
|
||||||
pagination: {total: this.state.pagination.total - 1},
|
data: Setting.deleteRow(this.state.data, i),
|
||||||
});
|
pagination: {total: this.state.pagination.total - 1},
|
||||||
}
|
});
|
||||||
)
|
} else {
|
||||||
|
Setting.showMessage("error", `${i18next.t("general:Failed to delete")}: ${res.msg}`);
|
||||||
|
}
|
||||||
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
Setting.showMessage("error", `Organization failed to delete: ${error}`);
|
Setting.showMessage("error", `${i18next.t("general:Failed to connect to server")}: ${error}`);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -223,7 +231,7 @@ class OrganizationListPage extends BaseListPage {
|
|||||||
onConfirm={() => this.deleteOrganization(index)}
|
onConfirm={() => this.deleteOrganization(index)}
|
||||||
disabled={record.name === "built-in"}
|
disabled={record.name === "built-in"}
|
||||||
>
|
>
|
||||||
<Button style={{marginBottom: "10px"}} disabled={record.name === "built-in"} type="danger">{i18next.t("general:Delete")}</Button>
|
<Button style={{marginBottom: "10px"}} disabled={record.name === "built-in"} type="primary" danger>{i18next.t("general:Delete")}</Button>
|
||||||
</Popconfirm>
|
</Popconfirm>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
@ -64,7 +64,7 @@ export const PasswordModal = (props) => {
|
|||||||
<Modal
|
<Modal
|
||||||
maskClosable={false}
|
maskClosable={false}
|
||||||
title={i18next.t("user:Password")}
|
title={i18next.t("user:Password")}
|
||||||
visible={visible}
|
open={visible}
|
||||||
okText={i18next.t("user:Set Password")}
|
okText={i18next.t("user:Set Password")}
|
||||||
cancelText={i18next.t("user:Cancel")}
|
cancelText={i18next.t("user:Cancel")}
|
||||||
confirmLoading={confirmLoading}
|
confirmLoading={confirmLoading}
|
||||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user