build auth sms

This commit is contained in:
Tue 2022-11-07 11:21:27 +07:00
parent 0b82072bea
commit d946b993ee
4 changed files with 60 additions and 0 deletions

37
client/auth_sms.go Normal file
View File

@ -0,0 +1,37 @@
package client
import (
"encoding/json"
"errors"
"git.selly.red/Selly-Modules/natsio"
"git.selly.red/Selly-Modules/natsio/model"
"git.selly.red/Selly-Modules/natsio/subject"
)
// AuthSMS ...
type AuthSMS struct{}
// GetAuthSMS ...
func GetAuthSMS() AuthSMS {
return AuthSMS{}
}
func (s AuthSMS) CheckPermission(p model.CheckPermissionRequest) error {
msg, err := natsio.GetServer().Request(subject.AuthSMS.CheckPermission, toBytes(p))
if err != nil {
return err
}
var r struct {
Error string `json:"error"`
}
if err = json.Unmarshal(msg.Data, &r); err != nil {
return err
}
if r.Error != "" {
return errors.New(r.Error)
}
return nil
}

View File

@ -0,0 +1,7 @@
package model
type CheckPermissionRequest struct {
Value []string `json:"value"`
ID string `json:"_id"`
DeviceID string `json:"deviceId"`
}

View File

@ -0,0 +1 @@
package model

15
subject/auth_sms.go Normal file
View File

@ -0,0 +1,15 @@
package subject
import "fmt"
func getAuthSMSValue(val string) string {
return fmt.Sprintf("%s.%s", prefixes.AuthSMS, val)
}
var AuthSMS = struct {
// AuthSMS
CheckPermission string
}{
// Users
CheckPermission: getAuthSMSValue("check_permission"),
}