mirror of
https://github.com/casdoor/casdoor.git
synced 2025-08-07 05:17:48 +08:00
Compare commits
5 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
b6b77da7cf | ||
![]() |
8b4637aa3a | ||
![]() |
87506b84e3 | ||
![]() |
fed9332246 | ||
![]() |
33afc52a0b |
@@ -27,8 +27,7 @@ type SmtpEmailProvider struct {
|
||||
}
|
||||
|
||||
func NewSmtpEmailProvider(userName string, password string, host string, port int, typ string, disableSsl bool) *SmtpEmailProvider {
|
||||
dialer := &gomail.Dialer{}
|
||||
dialer = gomail.NewDialer(host, port, userName, password)
|
||||
dialer := gomail.NewDialer(host, port, userName, password)
|
||||
if typ == "SUBMAIL" {
|
||||
dialer.TLSConfig = &tls.Config{InsecureSkipVerify: true}
|
||||
}
|
||||
|
13
idp/goth.go
13
idp/goth.go
@@ -278,9 +278,16 @@ func NewGothIdProvider(providerType string, clientId string, clientSecret string
|
||||
Session: &naver.Session{},
|
||||
}
|
||||
case "Nextcloud":
|
||||
idp = GothIdProvider{
|
||||
Provider: nextcloud.New(clientId, clientSecret, redirectUrl),
|
||||
Session: &nextcloud.Session{},
|
||||
if hostUrl != "" {
|
||||
idp = GothIdProvider{
|
||||
Provider: nextcloud.NewCustomisedDNS(clientId, clientSecret, redirectUrl, hostUrl),
|
||||
Session: &nextcloud.Session{},
|
||||
}
|
||||
} else {
|
||||
idp = GothIdProvider{
|
||||
Provider: nextcloud.New(clientId, clientSecret, redirectUrl),
|
||||
Session: &nextcloud.Session{},
|
||||
}
|
||||
}
|
||||
case "OneDrive":
|
||||
idp = GothIdProvider{
|
||||
|
@@ -81,62 +81,12 @@ func UploadUsers(owner string, path string) (bool, error) {
|
||||
return false, err
|
||||
}
|
||||
|
||||
transUsers, err := StringArrayToUser(table)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
newUsers := []*User{}
|
||||
for index, line := range table {
|
||||
line := line
|
||||
if index == 0 || parseLineItem(&line, 0) == "" {
|
||||
continue
|
||||
}
|
||||
|
||||
user := &User{
|
||||
Owner: parseLineItem(&line, 0),
|
||||
Name: parseLineItem(&line, 1),
|
||||
CreatedTime: parseLineItem(&line, 2),
|
||||
UpdatedTime: parseLineItem(&line, 3),
|
||||
Id: parseLineItem(&line, 4),
|
||||
Type: parseLineItem(&line, 5),
|
||||
Password: parseLineItem(&line, 6),
|
||||
PasswordSalt: parseLineItem(&line, 7),
|
||||
DisplayName: parseLineItem(&line, 8),
|
||||
FirstName: parseLineItem(&line, 9),
|
||||
LastName: parseLineItem(&line, 10),
|
||||
Avatar: parseLineItem(&line, 11),
|
||||
PermanentAvatar: "",
|
||||
Email: parseLineItem(&line, 12),
|
||||
Phone: parseLineItem(&line, 13),
|
||||
Location: parseLineItem(&line, 14),
|
||||
Address: []string{parseLineItem(&line, 15)},
|
||||
Affiliation: parseLineItem(&line, 16),
|
||||
Title: parseLineItem(&line, 17),
|
||||
IdCardType: parseLineItem(&line, 18),
|
||||
IdCard: parseLineItem(&line, 19),
|
||||
Homepage: parseLineItem(&line, 20),
|
||||
Bio: parseLineItem(&line, 21),
|
||||
Tag: parseLineItem(&line, 22),
|
||||
Region: parseLineItem(&line, 23),
|
||||
Language: parseLineItem(&line, 24),
|
||||
Gender: parseLineItem(&line, 25),
|
||||
Birthday: parseLineItem(&line, 26),
|
||||
Education: parseLineItem(&line, 27),
|
||||
Score: parseLineItemInt(&line, 28),
|
||||
Karma: parseLineItemInt(&line, 29),
|
||||
Ranking: parseLineItemInt(&line, 30),
|
||||
IsDefaultAvatar: false,
|
||||
IsOnline: parseLineItemBool(&line, 31),
|
||||
IsAdmin: parseLineItemBool(&line, 32),
|
||||
IsForbidden: parseLineItemBool(&line, 33),
|
||||
IsDeleted: parseLineItemBool(&line, 34),
|
||||
SignupApplication: parseLineItem(&line, 35),
|
||||
Hash: "",
|
||||
PreHash: "",
|
||||
CreatedIp: parseLineItem(&line, 36),
|
||||
LastSigninTime: parseLineItem(&line, 37),
|
||||
LastSigninIp: parseLineItem(&line, 38),
|
||||
Ldap: "",
|
||||
Properties: map[string]string{},
|
||||
DeletedTime: parseLineItem(&line, 39),
|
||||
}
|
||||
|
||||
for _, user := range transUsers {
|
||||
if _, ok := oldUserMap[user.GetId()]; !ok {
|
||||
newUsers = append(newUsers, user)
|
||||
}
|
||||
|
@@ -19,12 +19,14 @@ import (
|
||||
"fmt"
|
||||
"reflect"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/casdoor/casdoor/conf"
|
||||
"github.com/casdoor/casdoor/i18n"
|
||||
"github.com/casdoor/casdoor/idp"
|
||||
"github.com/casdoor/casdoor/util"
|
||||
"github.com/go-webauthn/webauthn/webauthn"
|
||||
jsoniter "github.com/json-iterator/go"
|
||||
"github.com/xorm-io/core"
|
||||
)
|
||||
@@ -689,3 +691,103 @@ func IsAppUser(userId string) bool {
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func setReflectAttr[T any](fieldValue *reflect.Value, fieldString string) error {
|
||||
unmarshalValue := new(T)
|
||||
err := json.Unmarshal([]byte(fieldString), unmarshalValue)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
fvElem := fieldValue
|
||||
fvElem.Set(reflect.ValueOf(*unmarshalValue))
|
||||
return nil
|
||||
}
|
||||
|
||||
func StringArrayToUser(stringArray [][]string) ([]*User, error) {
|
||||
fieldNames := stringArray[0]
|
||||
excelMap := []map[string]string{}
|
||||
userFieldMap := map[string]int{}
|
||||
|
||||
reflectedUser := reflect.TypeOf(User{})
|
||||
for i := 0; i < reflectedUser.NumField(); i++ {
|
||||
userFieldMap[strings.ToLower(reflectedUser.Field(i).Name)] = i
|
||||
}
|
||||
|
||||
for idx, field := range stringArray {
|
||||
if idx == 0 {
|
||||
continue
|
||||
}
|
||||
|
||||
tempMap := map[string]string{}
|
||||
for idx, val := range field {
|
||||
tempMap[fieldNames[idx]] = val
|
||||
}
|
||||
excelMap = append(excelMap, tempMap)
|
||||
}
|
||||
|
||||
users := []*User{}
|
||||
var err error
|
||||
|
||||
for _, u := range excelMap {
|
||||
user := User{}
|
||||
reflectedUser := reflect.ValueOf(&user).Elem()
|
||||
for k, v := range u {
|
||||
if v == "" || v == "null" || v == "[]" || v == "{}" {
|
||||
continue
|
||||
}
|
||||
fName := strings.ToLower(strings.ReplaceAll(k, "_", ""))
|
||||
fieldIdx, ok := userFieldMap[fName]
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
fv := reflectedUser.Field(fieldIdx)
|
||||
if !fv.IsValid() {
|
||||
continue
|
||||
}
|
||||
switch fv.Kind() {
|
||||
case reflect.String:
|
||||
fv.SetString(v)
|
||||
continue
|
||||
case reflect.Bool:
|
||||
fv.SetBool(v == "1")
|
||||
continue
|
||||
case reflect.Int:
|
||||
intVal, err := strconv.Atoi(v)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
fv.SetInt(int64(intVal))
|
||||
continue
|
||||
}
|
||||
|
||||
switch fv.Type() {
|
||||
case reflect.TypeOf([]string{}):
|
||||
err = setReflectAttr[[]string](&fv, v)
|
||||
case reflect.TypeOf([]*string{}):
|
||||
err = setReflectAttr[[]*string](&fv, v)
|
||||
case reflect.TypeOf([]*FaceId{}):
|
||||
err = setReflectAttr[[]*FaceId](&fv, v)
|
||||
case reflect.TypeOf([]*MfaProps{}):
|
||||
err = setReflectAttr[[]*MfaProps](&fv, v)
|
||||
case reflect.TypeOf([]*Role{}):
|
||||
err = setReflectAttr[[]*Role](&fv, v)
|
||||
case reflect.TypeOf([]*Permission{}):
|
||||
err = setReflectAttr[[]*Permission](&fv, v)
|
||||
case reflect.TypeOf([]ManagedAccount{}):
|
||||
err = setReflectAttr[[]ManagedAccount](&fv, v)
|
||||
case reflect.TypeOf([]MfaAccount{}):
|
||||
err = setReflectAttr[[]MfaAccount](&fv, v)
|
||||
case reflect.TypeOf([]webauthn.Credential{}):
|
||||
err = setReflectAttr[[]webauthn.Credential](&fv, v)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
users = append(users, &user)
|
||||
}
|
||||
|
||||
return users, nil
|
||||
}
|
||||
|
@@ -950,7 +950,7 @@ class ProviderEditPage extends React.Component {
|
||||
)
|
||||
}
|
||||
{
|
||||
this.state.provider.type !== "ADFS" && this.state.provider.type !== "AzureAD" && this.state.provider.type !== "AzureADB2C" && (this.state.provider.type !== "Casdoor" && this.state.category !== "Storage") && this.state.provider.type !== "Okta" ? null : (
|
||||
this.state.provider.type !== "ADFS" && this.state.provider.type !== "AzureAD" && this.state.provider.type !== "AzureADB2C" && (this.state.provider.type !== "Casdoor" && this.state.category !== "Storage") && this.state.provider.type !== "Okta" && this.state.provider.type !== "Nextcloud" ? null : (
|
||||
<Row style={{marginTop: "20px"}} >
|
||||
<Col style={{marginTop: "5px"}} span={2}>
|
||||
{Setting.getLabel(i18next.t("provider:Domain"), i18next.t("provider:Domain - Tooltip"))} :
|
||||
|
@@ -37,7 +37,7 @@ export function signup(values) {
|
||||
}
|
||||
|
||||
export function getEmailAndPhone(organization, username) {
|
||||
return fetch(`${authConfig.serverUrl}/api/get-email-and-phone?organization=${organization}&username=${username}`, {
|
||||
return fetch(`${authConfig.serverUrl}/api/get-email-and-phone?organization=${organization}&username=${encodeURIComponent(username)}`, {
|
||||
method: "GET",
|
||||
credentials: "include",
|
||||
headers: {
|
||||
|
@@ -193,7 +193,11 @@ class AuthCallback extends React.Component {
|
||||
const token = res.data;
|
||||
Setting.goToLink(`${oAuthParams.redirectUri}${concatChar}${responseType}=${token}&state=${oAuthParams.state}&token_type=bearer`);
|
||||
} else if (responseType === "link") {
|
||||
const from = innerParams.get("from");
|
||||
let from = innerParams.get("from");
|
||||
const oauth = innerParams.get("oauth");
|
||||
if (oauth) {
|
||||
from += `?oauth=${oauth}`;
|
||||
}
|
||||
Setting.goToLinkSoftOrJumpSelf(this, from);
|
||||
} else if (responseType === "saml") {
|
||||
if (res.data2.method === "POST") {
|
||||
|
@@ -194,8 +194,10 @@ class PromptPage extends React.Component {
|
||||
const redirectUri = params.get("redirectUri");
|
||||
const code = params.get("code");
|
||||
const state = params.get("state");
|
||||
const oauth = params.get("oauth");
|
||||
if (redirectUri === null || code === null || state === null) {
|
||||
return "";
|
||||
const signInUrl = sessionStorage.getItem("signinUrl");
|
||||
return oauth === "true" ? signInUrl : "";
|
||||
}
|
||||
return `${redirectUri}?code=${code}&state=${state}`;
|
||||
}
|
||||
|
@@ -402,6 +402,10 @@ export function getAuthUrl(application, provider, method, code) {
|
||||
redirectUri = `${redirectOrigin}/api/callback`;
|
||||
} else if (provider.type === "Google" && provider.disableSsl) {
|
||||
scope += "+https://www.googleapis.com/auth/user.phonenumbers.read";
|
||||
} else if (provider.type === "Nextcloud") {
|
||||
if (provider.domain) {
|
||||
endpoint = `${provider.domain}/apps/oauth2/authorize`;
|
||||
}
|
||||
}
|
||||
|
||||
if (provider.type === "Google" || provider.type === "GitHub" || provider.type === "Facebook"
|
||||
|
@@ -195,8 +195,9 @@ class SignupPage extends React.Component {
|
||||
if (authConfig.appName === application.name) {
|
||||
return "/result";
|
||||
} else {
|
||||
const oAuthParams = Util.getOAuthGetParameters();
|
||||
if (Setting.hasPromptPage(application)) {
|
||||
return `/prompt/${application.name}`;
|
||||
return `/prompt/${application.name}?oauth=${oAuthParams !== null}`;
|
||||
} else {
|
||||
return `/result/${application.name}`;
|
||||
}
|
||||
|
Binary file not shown.
Reference in New Issue
Block a user