-
Notifications
You must be signed in to change notification settings - Fork 0
/
authentication.go
executable file
·56 lines (44 loc) · 1.71 KB
/
authentication.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
50
51
52
53
54
55
56
package campid
import (
"context"
"github.com/ewe-studios/sabuhp"
"github.com/influx6/npkg/nerror"
"github.com/nyaruka/phonenumbers"
)
type Authenticator interface {
Login(ctx context.Context, msg sabuhp.Message, tr sabuhp.Transport) sabuhp.MessageErr
Logout(ctx context.Context, msg sabuhp.Message, tr sabuhp.Transport) sabuhp.MessageErr
VerifyLogin(ctx context.Context, msg sabuhp.Message, tr sabuhp.Transport) sabuhp.MessageErr
FinishLogin(ctx context.Context, msg sabuhp.Message, tr sabuhp.Transport) sabuhp.MessageErr
VerifyAccess(ctx context.Context, msg sabuhp.Message, tr sabuhp.Transport) sabuhp.MessageErr
RefreshAccess(ctx context.Context, msg sabuhp.Message, tr sabuhp.Transport) sabuhp.MessageErr
Register(ctx context.Context, msg sabuhp.Message, tr sabuhp.Transport) sabuhp.MessageErr
VerifyRegistration(ctx context.Context, msg sabuhp.Message, tr sabuhp.Transport) sabuhp.MessageErr
FinishRegistration(ctx context.Context, msg sabuhp.Message, tr sabuhp.Transport) sabuhp.MessageErr
}
type PhoneValidator interface {
ValidatePhone(phone string) error
}
type PhoneValidatorImpl struct {
DefaultRegion string
}
func (ph PhoneValidatorImpl) ValidatePhone(phone string) error {
var phoneNumber, phoneNumberErr = phonenumbers.Parse(phone, ph.DefaultRegion)
if phoneNumberErr != nil {
return nerror.WrapOnly(phoneNumberErr)
}
if phonenumbers.IsValidNumber(phoneNumber) {
return nil
}
return nerror.New("invalid phone number %q provided", phone)
}
type EmailValidator interface {
ValidateEmail(email string) error
}
type EmailValidatorImpl struct{}
func (e EmailValidatorImpl) ValidateEmail(email string) error {
if err := ValidateEmail(email); err != nil {
return nerror.WrapOnly(err)
}
return nil
}