-
Notifications
You must be signed in to change notification settings - Fork 0
/
service-whatsapp.go
50 lines (39 loc) · 1.02 KB
/
service-whatsapp.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
package multauth
import (
"strings"
"errors"
)
type UserWhatsappService struct {
UserService
Provider UserServiceProviderInterface `db:"-"`
Whatsapp string `db:"whatsapp" json:"whatsapp"`
Passcode string `db:"passcode" json:"passcode"`
}
func (service *UserWhatsappService) Init(data map[string]interface{}) error {
length, lengthOk := data["Length"].(int)
if !lengthOk {
length = DEFAULT_SERVICE_LENGTH
}
service.Passcode = strings.Repeat("0", length) // experimental
return nil
}
func (service *UserWhatsappService) SetPasscode() error {
length := len(service.Passcode)
if length == 0 {
length = DEFAULT_SERVICE_LENGTH
}
if service.Whatsapp == "" {
return errors.New("Error")
}
passcode, err := generateOTP(length)
if err != nil {
return errors.New("Error")
}
errSend := service.Provider.Send(service.Whatsapp, passcode)
if errSend != nil { return errSend }
service.Passcode = passcode
return nil
}
func (service UserWhatsappService) CheckPasscode(value string) bool {
return service.Passcode == value
}