From ef5ecee286cd720bd652d22d87561b8eda279f76 Mon Sep 17 00:00:00 2001 From: "insanity@loafle.com" Date: Sat, 27 May 2017 14:57:13 +0900 Subject: [PATCH] login logic has added --- proxy/member_service.go | 80 +++++++++++++++++------------------- proxy/member_service_test.go | 36 ++++++++++------ 2 files changed, 60 insertions(+), 56 deletions(-) diff --git a/proxy/member_service.go b/proxy/member_service.go index 1ab86c0..77d6333 100644 --- a/proxy/member_service.go +++ b/proxy/member_service.go @@ -1,20 +1,19 @@ package proxy import ( - "log" "encoding/json" - //"loafle.com/overflow/encryption_go/src/loafle.com/overflow/encryption" - //"strings" + "loafle.com/overflow/encryption_go" + "log" ) type MemberService struct { - Id string `json:"id"` - Email string `json:"email"` - PwSalt string `json:"pwSalt"` - Digest string `json:"digest"` - Name string `json:"name"` - Company string `json:"company"` - Phone string `json:"phone"` + Id json.Number `json:"id,Number,omitempty"` + Email string `json:"email"` + PwSalt string `json:"pwSalt"` + Digest string `json:"digest"` + Name string `json:"name"` + Company string `json:"company"` + Phone string `json:"phone"` } var TARGET_DAO = "member" @@ -24,7 +23,7 @@ func NewMember() *MemberService { return &m } -func (m *MemberService) getMemberMap() (map[string]string) { +func (m *MemberService) getMemberMap() map[string]string { memMap := make(map[string]string) str, err := json.Marshal(m) @@ -39,69 +38,64 @@ func (m *MemberService) getMemberMap() (map[string]string) { } func (m *MemberService) Login() string { - log.Println("Call Login", m.Email, m.PwSalt) - mStr := m.Read() + result := m.ReadByEmail() + if result == "" { + return "login reject" + } + temp := MemberService{} + err := json.Unmarshal([]byte(result), &temp) + if err != nil { + return err.Error() + } - mTemp := &MemberService{} - json.Unmarshal([]byte(mStr), mTemp) - - //pwSalt, digest, err := encryption.Encrypt(m.PwSalt) - //if { - // - //} - log.Println("member Pw: ", m.PwSalt) - log.Println("member Temp Pw: ", mTemp.PwSalt) - - if m.PwSalt != mTemp.PwSalt { + b := encryption.Check(m.PwSalt, temp.PwSalt, temp.Digest) + if !b { return "login reject" } return "login success" } -func (m *MemberService) Regist() (string){ +func (m *MemberService) Regist() string { log.Println("Call Regist", m.Email, m.PwSalt) - // Todo Call DB Gateway - m.Digest = "qwer5795" + + pwSalt, digest, err := encryption.Encrypt(m.PwSalt) + if err != nil { + log.Fatal("encryption Encrypt Error: ", err) + } + + m.PwSalt = pwSalt + m.Digest = digest memMap := m.getMemberMap() - //pwSalt, digest, err := encryption.Encrypt(m.PwSalt) - - //if err != nil { - // log.Fatal("encryption Encrypt Error: ", err) - //} - // - //m.PwSalt = string(pwSalt) - //m.Digest = string(digest) - re := invokeDB(TARGET_DAO, "create", memMap) return re } -func (m *MemberService) ReadByEmail() (string) { +func (m *MemberService) ReadByEmail() string { log.Println("Call ReadByEmail", m.Email) memMap := m.getMemberMap() re := invokeDB(TARGET_DAO, "findByEmail", memMap) - return "" + return re } -func (m *MemberService) Read() (string){ +func (m *MemberService) Read() string { log.Println("Call Read", m.Email) // Todo Call DB Gateway m.Digest = "qwer5795" //memMap := m.getMemberMap() mm := make(map[string]string) - mm["id"] = m.Id + mm["id"] = string(m.Id) log.Println("Read Member", m) re := invokeDB(TARGET_DAO, "find", mm) return re } -func (m *MemberService) Modify() (string){ - log.Println("Call Modify", m.Email, "::", m.PwSalt) +func (m *MemberService) Modify() string { + log.Println("Call Modify", m.Email, "::", m.PwSalt) // Todo Call DB Gateway m.Digest = "read" memMap := m.getMemberMap() @@ -111,7 +105,7 @@ func (m *MemberService) Modify() (string){ return re } -func (m *MemberService) Remove() (string){ +func (m *MemberService) Remove() string { log.Println("Call Remove", m.Email) // Todo Call DB Gateway m.Digest = "read" diff --git a/proxy/member_service_test.go b/proxy/member_service_test.go index 02e4938..e2244d6 100644 --- a/proxy/member_service_test.go +++ b/proxy/member_service_test.go @@ -3,7 +3,6 @@ package proxy import ( "testing" "log" - "loafle.com/overflow/encryption_go" ) func TestMemberService_Login(t *testing.T) { @@ -12,29 +11,29 @@ func TestMemberService_Login(t *testing.T) { func TestMemberService_Regist(t *testing.T) { m := &MemberService{ - Email:"geek@loafle.com", + Email:"geek2@loafle.com", PwSalt:"qwer5795", - Digest:"Digest", Company:"Loafle", Name:"Geek", Phone:"010-4055-6699", } - encryption.Encrypt(m.PwSalt) - mm := m.getMemberMap() + retMem := m.Regist() + t.Log(retMem) +} - rr := invokeDB(TARGET_DAO, "create", mm) - log.Println(rr) +func TestMemberLogin(t *testing.T) { + m := &MemberService{ + Email:"geek@loafle.com", + PwSalt:"qwer5795", + } + b := m.Login() + t.Log("LOGIN RESULT : ", b) } func TestMemberService_Read(t *testing.T) { - //m := &MemberService{ - // Id:"3", - //} - - //mm := m.getMemberMap() mm := make(map[string] string) - mm["id"] = "4" + mm["id"] = "12" rr := invokeDB(TARGET_DAO, "find", mm) log.Println(rr) @@ -48,4 +47,15 @@ func TestMemberService_ReadByEmail(t *testing.T) { mm := m.getMemberMap() rr := invokeDB(TARGET_DAO, "findByEmail", mm) log.Println(rr) +} + +func TestMemberUpdate(t *testing.T) { + m := &MemberService{ + Id: "11", + Email:"keeg@loafle.com", + } + + mm := m.getMemberMap() + rr := invokeDB(TARGET_DAO, "update", mm) + log.Println(rr) } \ No newline at end of file