35 lines
725 B
Go
35 lines
725 B
Go
package service
|
|
|
|
import (
|
|
"regexp"
|
|
"videoplayer/dao"
|
|
)
|
|
|
|
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
|
|
}
|