casdoor/object/check.go

38 lines
811 B
Go
Raw Normal View History

2021-02-11 22:56:08 +08:00
package object
2021-02-14 01:04:51 +08:00
import "fmt"
2021-02-11 22:56:08 +08:00
func CheckUserRegister(userId string, password string) string {
if len(userId) == 0 || len(password) == 0 {
return "username and password cannot be blank"
} else if HasUser(userId) {
return "username already exists"
} else {
return ""
}
}
func CheckUserLogin(userId string, password string) string {
if !HasUser(userId) {
return "username does not exist, please sign up first"
}
if !IsPasswordCorrect(userId, password) {
return "password incorrect"
}
return ""
}
2021-02-14 00:22:24 +08:00
2021-02-14 01:04:51 +08:00
func (user *User) getId() string {
return fmt.Sprintf("%s/%s", user.Owner, user.Name)
}
2021-02-21 23:51:40 +08:00
func GetUserIdByField(application *Application, field string, value string) string {
user := GetUserByField(application.Organization, field, value)
2021-02-14 00:22:24 +08:00
if user != nil {
2021-02-14 01:04:51 +08:00
return user.getId()
2021-02-14 00:22:24 +08:00
}
return ""
}