-
Notifications
You must be signed in to change notification settings - Fork 145
/
service.go
49 lines (38 loc) · 1.04 KB
/
service.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package users
import (
"errors"
"fmt"
"strings"
"github.com/hatchet-dev/hatchet/pkg/config/server"
)
type UserService struct {
config *server.ServerConfig
}
func NewUserService(config *server.ServerConfig) *UserService {
return &UserService{
config: config,
}
}
func (u *UserService) checkUserRestrictionsForEmail(conf *server.ServerConfig, email string) error {
if len(conf.Auth.ConfigFile.RestrictedEmailDomains) == 0 {
return nil
}
// parse domain from email
// make sure there's only one @ in the email
if strings.Count(email, "@") != 1 {
return errors.New("invalid email")
}
domain := strings.Split(email, "@")[1]
return u.checkUserRestrictions(conf, domain)
}
func (u *UserService) checkUserRestrictions(conf *server.ServerConfig, emailDomain string) error {
if len(conf.Auth.ConfigFile.RestrictedEmailDomains) == 0 {
return nil
}
for _, domain := range conf.Auth.ConfigFile.RestrictedEmailDomains {
if domain == emailDomain {
return nil
}
}
return fmt.Errorf("email is not in the restricted domain group")
}