videoplayer/service/userService.go

44 lines
909 B
Go
Raw Normal View History

package service
import (
"regexp"
"videoplayer/dao"
"videoplayer/proto"
)
func CreateUser(name string, password, email string) uint {
return dao.CreateUser(name, password, email)
}
func GetUser(name, email, password string) dao.User {
emailRegex := `^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$`
re := regexp.MustCompile(emailRegex)
var user dao.User
if re.MatchString(name) {
user = dao.FindUserByEmail(name)
} else {
user = dao.FindUserByName(name)
}
if user.ID != 0 && user.Password == password {
return user
}
return dao.User{}
}
func ContainsUser(name, email string) bool {
user := dao.FindUserByName(name)
user2 := dao.FindUserByEmail(email)
if user.ID != 0 || user2.ID != 0 {
return true
}
return false
}
2024-06-28 10:38:55 +08:00
func GetUserByID(id int) []proto.User {
return dao.FindUserByID(id)
}
2024-06-28 10:38:55 +08:00
func GetUserByNameLike(name string) []proto.User {
return dao.FindUserByNameLike(name)
}