mirror of
https://github.com/casdoor/casdoor.git
synced 2025-07-02 19:40:19 +08:00
Add account APIs.
This commit is contained in:
23
object/check.go
Normal file
23
object/check.go
Normal file
@ -0,0 +1,23 @@
|
||||
package object
|
||||
|
||||
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 ""
|
||||
}
|
@ -60,6 +60,15 @@ func GetUser(id string) *User {
|
||||
return getUser(owner, name)
|
||||
}
|
||||
|
||||
func HasUser(id string) bool {
|
||||
return GetUser(id) != nil
|
||||
}
|
||||
|
||||
func IsPasswordCorrect(userId string, password string) bool {
|
||||
user := GetUser(userId)
|
||||
return user.Password == password
|
||||
}
|
||||
|
||||
func UpdateUser(id string, user *User) bool {
|
||||
owner, name := util.GetOwnerAndNameFromId(id)
|
||||
if getUser(owner, name) == nil {
|
||||
|
Reference in New Issue
Block a user