noauthagent auth process

This commit is contained in:
insanity@loafle.com 2017-06-05 21:11:04 +09:00
parent efc069738d
commit 9e178bd8ff
2 changed files with 55 additions and 5 deletions

View File

@ -5,6 +5,9 @@ import (
"git.loafle.net/overflow/commons_go/model/timestamp"
"git.loafle.net/overflow/overflow_proxy_service/proxy"
"encoding/json"
"git.loafle.net/overflow/overflow_proxy_service/proxy/member"
"git.loafle.net/overflow/overflow_proxy_service/proxy/agent"
"github.com/reactivex/rxgo/errors"
)
type NoAuthAgentService struct {
@ -77,12 +80,12 @@ func(as *NoAuthAgentService)CheckAuth(tempKey string) (string,error) {
}
func(as *NoAuthAgentService)GetNoAuthList(authStatus string) (string,error) {
func(as *NoAuthAgentService)GetNoAuthList(excludeStatus string) (string,error) {
memMap := make(map[string]string)
na := NewNoAuthAgent("", 0, "")
na.AuthStatus = authStatus
na.AuthStatus = excludeStatus
bytes, err := json.Marshal(na)
if err != nil {
@ -101,3 +104,35 @@ func(as *NoAuthAgentService)GetNoAuthList(authStatus string) (string,error) {
func (as *NoAuthAgentService) GetModel() (interface{}) {
return NewNoAuthAgent("", 0, "")
}
func (as *NoAuthAgentService)RequestAuth(noauthAgt NoAuthAgent, memberId, desc string) (string, error) {
paramMap := make(map[string]string)
noauthAgt.AuthStatus = "ACCEPT"
bytes, err := json.Marshal(noauthAgt)
if err != nil {
return "", err;
}
paramMap["com.loafle.overflow.noauthagent.model.NoAuthAgent"] = string(bytes)
out := proxy.InvokeDB("noauthAgent", "update", paramMap)
if len(out) == 0 {
return "", errors.New("Cannot update Agent. ")
}
m := member.Member{}
m.Id = json.Number(memberId)
newAgent := agent.NewAgent(desc, m)
newone, err := agent.NewAgentService().SaveAgent(newAgent)
if err!= nil {
return "", err
}
return newone, nil
}
func (as *NoAuthAgentService)ReadNoAuthAgent(id string) (string, error){
mm := make(map[string]string)
mm["id"] = id
out := proxy.InvokeDB("noauthAgent", "find", mm)
return out, nil
}

View File

@ -5,6 +5,7 @@ import (
"github.com/google/uuid"
"testing"
"encoding/json"
)
@ -22,9 +23,9 @@ func TestCreateUUid(t *testing.T) {
func TestCreateNoAuthAgent(t *testing.T) {
na := NewNoAuthAgent("2334278390283", 111, "Snoop")
na := NewNoAuthAgent("233421390283", 111, "Snoop")
na.TempKey = "22222222"
na.TempKey = "1111111"
na.AuthStatus = "WAIT"
nas := NewNoAuthAgentService()
@ -73,3 +74,17 @@ func TestNoAuthList(t *testing.T) {
t.Log(out)
}
func TestRequestAuth(t *testing.T) {
nas := NewNoAuthAgentService()
res, err := nas.ReadNoAuthAgent("1")
na := NoAuthAgent{}
json.Unmarshal([]byte(res), na)
newone, err := nas.RequestAuth(na, "1", "test")
if err!= nil {
t.Fatal(err)
}
t.Log(newone)
}