login logic has added
This commit is contained in:
parent
dc92bff913
commit
ef5ecee286
|
@ -1,14 +1,13 @@
|
|||
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"`
|
||||
Id json.Number `json:"id,Number,omitempty"`
|
||||
Email string `json:"email"`
|
||||
PwSalt string `json:"pwSalt"`
|
||||
Digest string `json:"digest"`
|
||||
|
@ -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,68 +38,63 @@ 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){
|
||||
func (m *MemberService) Modify() string {
|
||||
log.Println("Call Modify", m.Email, "::", m.PwSalt)
|
||||
// Todo Call DB Gateway
|
||||
m.Digest = "read"
|
||||
|
@ -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"
|
||||
|
|
|
@ -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)
|
||||
|
@ -49,3 +48,14 @@ func TestMemberService_ReadByEmail(t *testing.T) {
|
|||
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)
|
||||
}
|
Loading…
Reference in New Issue
Block a user