videoplayer/service/userService.go

26 lines
531 B
Go

package service
import (
"regexp"
"videoplayer/dao"
)
func CreateUser(name string, password, email string) int {
return dao.CreateUser(name, password, email)
}
func GetUser(name, 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{}
}