-
Notifications
You must be signed in to change notification settings - Fork 13
/
sms_gateway_mobica.go
49 lines (37 loc) · 1.02 KB
/
sms_gateway_mobica.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 otp
import (
"math/rand"
"strconv"
"github.com/coretrix/hitrix/service/component/sms"
)
const SMSOTPProviderMobica = "Mobica"
type Mobica struct {
mobicaProvider sms.IProvider
}
func NewMobicaSMSOTPProvider(mobicaProvider sms.IProvider) *Mobica {
return &Mobica{
mobicaProvider: mobicaProvider,
}
}
func (m *Mobica) GetName() string {
return SMSOTPProviderMobica
}
func (m *Mobica) GetCode() string {
rangeMin := 10000
rangeMax := 100000
//nolint //G404: Use of weak random number generator (math/rand instead of crypto/rand)
return strconv.Itoa(rand.Intn(rangeMax-rangeMin+1) + rangeMin)
}
func (m *Mobica) GetPhonePrefixes() []string {
return nil
}
func (m *Mobica) SendOTP(phone *Phone, code string) (string, string, error) {
_, err := m.mobicaProvider.SendSMSMessage(&sms.Message{
Text: code,
Number: phone.Number,
})
return "", "", err
}
func (m *Mobica) VerifyOTP(_ *Phone, code, generatedCode string) (string, string, bool, bool, error) {
return "", "", true, code == generatedCode, nil
}