mirror of
https://github.com/casdoor/casdoor.git
synced 2025-05-23 02:35:49 +08:00
fix: refactor functions and code (#1559)
This commit is contained in:
parent
eb72c9f273
commit
f2f962b893
@ -21,19 +21,21 @@ type CaptchaProvider interface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func GetCaptchaProvider(captchaType string) CaptchaProvider {
|
func GetCaptchaProvider(captchaType string) CaptchaProvider {
|
||||||
if captchaType == "Default" {
|
switch captchaType {
|
||||||
|
case "Default":
|
||||||
return NewDefaultCaptchaProvider()
|
return NewDefaultCaptchaProvider()
|
||||||
} else if captchaType == "reCAPTCHA" {
|
case "reCAPTCHA":
|
||||||
return NewReCaptchaProvider()
|
return NewReCaptchaProvider()
|
||||||
} else if captchaType == "hCaptcha" {
|
case "Aliyun Captcha":
|
||||||
return NewHCaptchaProvider()
|
|
||||||
} else if captchaType == "Aliyun Captcha" {
|
|
||||||
return NewAliyunCaptchaProvider()
|
return NewAliyunCaptchaProvider()
|
||||||
} else if captchaType == "GEETEST" {
|
case "hCaptcha":
|
||||||
|
return NewHCaptchaProvider()
|
||||||
|
case "GEETEST":
|
||||||
return NewGEETESTCaptchaProvider()
|
return NewGEETESTCaptchaProvider()
|
||||||
} else if captchaType == "Cloudflare Turnstile" {
|
case "Cloudflare Turnstile":
|
||||||
return NewCloudflareTurnstileProvider()
|
return NewCloudflareTurnstileProvider()
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -51,7 +51,7 @@ type LdapSyncResp struct {
|
|||||||
func (c *ApiController) GetLdapUser() {
|
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.IsStringsEmpty(ldapServer.Host, ldapServer.Admin, ldapServer.Passwd, ldapServer.BaseDn) {
|
||||||
c.ResponseError(c.T("general:Missing parameter"))
|
c.ResponseError(c.T("general:Missing parameter"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -119,7 +119,7 @@ func (c *ApiController) GetLdaps() {
|
|||||||
func (c *ApiController) GetLdap() {
|
func (c *ApiController) GetLdap() {
|
||||||
id := c.Input().Get("id")
|
id := c.Input().Get("id")
|
||||||
|
|
||||||
if util.IsStrsEmpty(id) {
|
if util.IsStringsEmpty(id) {
|
||||||
c.ResponseError(c.T("general:Missing parameter"))
|
c.ResponseError(c.T("general:Missing parameter"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -140,7 +140,7 @@ func (c *ApiController) AddLdap() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if util.IsStrsEmpty(ldap.Owner, ldap.ServerName, ldap.Host, ldap.Admin, ldap.Passwd, ldap.BaseDn) {
|
if util.IsStringsEmpty(ldap.Owner, ldap.ServerName, ldap.Host, ldap.Admin, ldap.Passwd, ldap.BaseDn) {
|
||||||
c.ResponseError(c.T("general:Missing parameter"))
|
c.ResponseError(c.T("general:Missing parameter"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -170,7 +170,7 @@ func (c *ApiController) AddLdap() {
|
|||||||
func (c *ApiController) UpdateLdap() {
|
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.IsStringsEmpty(ldap.Owner, ldap.ServerName, ldap.Host, ldap.Admin, ldap.Passwd, ldap.BaseDn) {
|
||||||
c.ResponseError(c.T("general:Missing parameter"))
|
c.ResponseError(c.T("general:Missing parameter"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -80,7 +80,7 @@ func (c *ApiController) SendEmail() {
|
|||||||
c.ResponseOk()
|
c.ResponseOk()
|
||||||
}
|
}
|
||||||
|
|
||||||
if util.IsStrsEmpty(emailForm.Title, emailForm.Content, emailForm.Sender) {
|
if util.IsStringsEmpty(emailForm.Title, emailForm.Content, emailForm.Sender) {
|
||||||
c.ResponseError(fmt.Sprintf(c.T("service:Empty parameters for emailForm: %v"), emailForm))
|
c.ResponseError(fmt.Sprintf(c.T("service:Empty parameters for emailForm: %v"), emailForm))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -177,7 +177,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 util.IsStrsEmpty(destType, dest, code) {
|
if util.IsStringsEmpty(destType, dest, code) {
|
||||||
c.ResponseError(c.T("general:Missing parameter"))
|
c.ResponseError(c.T("general:Missing parameter"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -329,7 +329,7 @@ func GetLdaps(owner string) []*Ldap {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func GetLdap(id string) *Ldap {
|
func GetLdap(id string) *Ldap {
|
||||||
if util.IsStrsEmpty(id) {
|
if util.IsStringsEmpty(id) {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -122,11 +122,8 @@ func AddToVerificationRecord(user *User, provider *Provider, remoteAddr, recordT
|
|||||||
record.Owner = provider.Owner
|
record.Owner = provider.Owner
|
||||||
record.Name = util.GenerateId()
|
record.Name = util.GenerateId()
|
||||||
record.CreatedTime = util.GetCurrentTime()
|
record.CreatedTime = util.GetCurrentTime()
|
||||||
if user != nil {
|
|
||||||
record.User = user.GetId()
|
|
||||||
}
|
|
||||||
record.Provider = provider.Name
|
|
||||||
|
|
||||||
|
record.Provider = provider.Name
|
||||||
record.Receiver = dest
|
record.Receiver = dest
|
||||||
record.Code = code
|
record.Code = code
|
||||||
record.Time = time.Now().Unix()
|
record.Time = time.Now().Unix()
|
||||||
|
@ -145,7 +145,7 @@ func GetMd5Hash(text string) string {
|
|||||||
return hex.EncodeToString(hash[:])
|
return hex.EncodeToString(hash[:])
|
||||||
}
|
}
|
||||||
|
|
||||||
func IsStrsEmpty(strs ...string) bool {
|
func IsStringsEmpty(strs ...string) bool {
|
||||||
for _, str := range strs {
|
for _, str := range strs {
|
||||||
if len(str) == 0 {
|
if len(str) == 0 {
|
||||||
return true
|
return true
|
||||||
|
@ -183,7 +183,7 @@ func TestIsStrsEmpty(t *testing.T) {
|
|||||||
}
|
}
|
||||||
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 := IsStrsEmpty(scenery.input...)
|
actual := IsStringsEmpty(scenery.input...)
|
||||||
assert.Equal(t, scenery.expected, actual, "The returned value not is expected")
|
assert.Equal(t, scenery.expected, actual, "The returned value not is expected")
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,17 @@
|
|||||||
|
// 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.
|
||||||
|
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import {Col, Row} from "antd";
|
import {Col, Row} from "antd";
|
||||||
import * as Setting from "../Setting";
|
import * as Setting from "../Setting";
|
||||||
|
Loading…
x
Reference in New Issue
Block a user