mirror of
https://github.com/casdoor/casdoor.git
synced 2025-07-03 12:30:19 +08:00
fix: improve code specification (#231)
This commit is contained in:
@ -99,7 +99,7 @@ func (a *Adapter) open() {
|
||||
}
|
||||
|
||||
func (a *Adapter) close() {
|
||||
a.Engine.Close()
|
||||
_ = a.Engine.Close()
|
||||
a.Engine = nil
|
||||
}
|
||||
|
||||
|
@ -24,7 +24,7 @@ import (
|
||||
var reWhiteSpace *regexp.Regexp
|
||||
|
||||
func init() {
|
||||
reWhiteSpace, _ = regexp.Compile("\\s")
|
||||
reWhiteSpace, _ = regexp.Compile(`\s`)
|
||||
}
|
||||
|
||||
func CheckUserSignup(application *Application, organization *Organization, username string, password string, displayName string, email string, phone string, affiliation string) string {
|
||||
|
@ -152,43 +152,30 @@ func (l *ldapConn) GetLdapUsers(baseDn string) ([]ldapUser, error) {
|
||||
switch attribute.Name {
|
||||
case "uidNumber":
|
||||
ldapUserItem.UidNumber = attribute.Values[0]
|
||||
break
|
||||
case "uid":
|
||||
ldapUserItem.Uid = attribute.Values[0]
|
||||
break
|
||||
case "cn":
|
||||
ldapUserItem.Cn = attribute.Values[0]
|
||||
break
|
||||
case "gidNumber":
|
||||
ldapUserItem.GidNumber = attribute.Values[0]
|
||||
break
|
||||
case "entryUUID":
|
||||
ldapUserItem.Uuid = attribute.Values[0]
|
||||
break
|
||||
case "mail":
|
||||
ldapUserItem.Mail = attribute.Values[0]
|
||||
break
|
||||
case "email":
|
||||
ldapUserItem.Email = attribute.Values[0]
|
||||
break
|
||||
case "emailAddress":
|
||||
ldapUserItem.EmailAddress = attribute.Values[0]
|
||||
break
|
||||
case "telephoneNumber":
|
||||
ldapUserItem.TelephoneNumber = attribute.Values[0]
|
||||
break
|
||||
case "mobile":
|
||||
ldapUserItem.Mobile = attribute.Values[0]
|
||||
break
|
||||
case "mobileTelephoneNumber":
|
||||
ldapUserItem.MobileTelephoneNumber = attribute.Values[0]
|
||||
break
|
||||
case "registeredAddress":
|
||||
ldapUserItem.RegisteredAddress = attribute.Values[0]
|
||||
break
|
||||
case "postalAddress":
|
||||
ldapUserItem.PostalAddress = attribute.Values[0]
|
||||
break
|
||||
}
|
||||
}
|
||||
ldapUsers = append(ldapUsers, ldapUserItem)
|
||||
@ -348,7 +335,7 @@ func CheckLdapUuidExist(owner string, uuids []string) []string {
|
||||
// }
|
||||
//}
|
||||
|
||||
err := adapter.Engine.Where(fmt.Sprintf("ldap IN (%s) AND owner = ?", "'" + strings.Join(uuids, "','") + "'"), owner).Find(&results)
|
||||
err := adapter.Engine.Where(fmt.Sprintf("ldap IN (%s) AND owner = ?", "'"+strings.Join(uuids, "','")+"'"), owner).Find(&results)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
@ -43,8 +43,8 @@ type Provider struct {
|
||||
AppId string `xorm:"varchar(100)" json:"appId"`
|
||||
|
||||
Endpoint string `xorm:"varchar(100)" json:"endpoint"`
|
||||
Domain string `xorm:"varchar(100)" json:"domain"`
|
||||
Bucket string `xorm:"varchar(100)" json:"bucket"`
|
||||
Domain string `xorm:"varchar(100)" json:"domain"`
|
||||
Bucket string `xorm:"varchar(100)" json:"bucket"`
|
||||
|
||||
ProviderUrl string `xorm:"varchar(200)" json:"providerUrl"`
|
||||
}
|
||||
|
@ -19,8 +19,8 @@ import (
|
||||
)
|
||||
|
||||
type Records struct {
|
||||
Id int `xorm:"int notnull pk autoincr" json:"id"`
|
||||
Record util.Record `xorm:"extends"`
|
||||
Id int `xorm:"int notnull pk autoincr" json:"id"`
|
||||
Record util.Record `xorm:"extends"`
|
||||
}
|
||||
|
||||
func AddRecord(record *util.Record) bool {
|
||||
|
@ -132,9 +132,9 @@ func GetLastUser(owner string) *User {
|
||||
|
||||
if existed {
|
||||
return &user
|
||||
} else {
|
||||
return nil
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func UpdateUser(id string, user *User) bool {
|
||||
|
@ -16,6 +16,7 @@ package object
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/casbin/casdoor/util"
|
||||
@ -78,3 +79,27 @@ func TestGetSaltedPassword(t *testing.T) {
|
||||
salt := "123"
|
||||
fmt.Printf("%s -> %s\n", password, getSaltedPassword(password, salt))
|
||||
}
|
||||
|
||||
func TestGetMaskedUsers(t *testing.T) {
|
||||
type args struct {
|
||||
users []*User
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
want []*User
|
||||
}{
|
||||
{
|
||||
name: "1",
|
||||
args: args{users: []*User{{Password: "casdoor"},{Password: "casbin"}}},
|
||||
want: []*User{{Password: "***"},{Password: "***"}},
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if got := GetMaskedUsers(tt.args.users); !reflect.DeepEqual(got, tt.want) {
|
||||
t.Errorf("GetMaskedUsers() = %v, want %v", got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user