diff --git a/proxy/email/email_service.go b/proxy/email/email_service.go index bf3c745..30f9974 100644 --- a/proxy/email/email_service.go +++ b/proxy/email/email_service.go @@ -12,6 +12,7 @@ import ( "encoding/json" "git.loafle.net/overflow/overflow_proxy_service/proxy" "git.loafle.net/overflow/overflow_proxy_service/proxy/member" + "git.loafle.net/overflow/commons_go/model/timestamp" ) const ( @@ -23,14 +24,18 @@ const ( ) type Email struct { - Id json.Number `json:"id,Number,omitempty"` - Member member.Member `json:"member"` - From string `json:"_"` - Subj string `json:"_"` - AuthToken string `json:"authToken"` - IsInvalid bool `json:"isInvalid"` - SmtpServer string `json:"_"` - BodyMsg string `json:"_"` + Id json.Number `json:"id,Number,omitempty"` + Member member.Member `json:"member"` + From string `json:"_"` + Subj string `json:"_"` + AuthToken string `json:"authToken"` + IsInvalid bool `json:"isInvalid"` + IsConfirm bool `json:"isConfirm"` + CreateDate timestamp.Timestamp `json:"createDate,omitempty"` + UpdateDate timestamp.Timestamp `json:"updateDate,omitempty"` + ConfirmDate timestamp.Timestamp `json:"confirmDate,omitempty"` + SmtpServer string `json:"_"` + BodyMsg string `json:"_"` } @@ -56,30 +61,6 @@ func NewEmailService() *EmailService{ return &EmailService{} } -func (es *EmailService) CheckAuthURL(e *Email) bool { - - //Todo Query from the database with an authentication token. - memMap := make(map[string]string) - - str, err := json.Marshal(e) - - if err != nil { - log.Fatal("Json Marshal Error: ", err) - } - - memMap["com.loafle.overflow.email.model.EmailAuth"] = string(str) - - re := proxy.InvokeDB("emailAuth", "find", memMap) - tempEmail := &Email{} - json.Unmarshal([]byte(re), tempEmail) - - r := strings.Compare(e.AuthToken, tempEmail.AuthToken) - - if r == 0 { - return true - } - return false -} func (es *EmailService) checkError(err error) { @@ -137,6 +118,7 @@ func (es *EmailService)SendEmailForAuth(e *Email) (error){ //Todo auth token generation e.AuthToken = es.generationAuthToken(e) e.IsInvalid = false + e.IsConfirm = false conn, err := tls.Dial("tcp", SERVER_NAME, tlsconfig) es.checkError(err) @@ -187,3 +169,50 @@ func (es *EmailService) saveEmail(e *Email) { proxy.InvokeDB("emailAuth", "create", memMap) } + +func (es *EmailService) CheckAuthURL(e *Email) bool { + + //Todo Query from the database with an authentication token. + + memMap := make(map[string]string) + + str, err := json.Marshal(e) + + if err != nil { + log.Fatal("Json Marshal Error: ", err) + } + + memMap["com.loafle.overflow.email.model.EmailAuth"] = string(str) + + re := proxy.InvokeDB("emailAuth", "findByAuthToken", memMap) + tempEmail := &Email{} + json.Unmarshal([]byte(re), tempEmail) + + r := strings.Compare(e.AuthToken, tempEmail.AuthToken) + + log.Println(tempEmail) + if r == 0 { + // Todo isConfirm change true and db update + tempEmail.IsConfirm = true + tempEmail.UpdateDate = timestamp.Now() + tempEmail.ConfirmDate = timestamp.Now() + + es.modifyEmailAuth(tempEmail) + return true + } + return false +} + +func (es *EmailService) modifyEmailAuth(e *Email) { + memMap := make(map[string]string) + + str, err := json.Marshal(e) + + fmt.Println(string(str)) + if err != nil { + log.Fatal("Json Marshal Error: ", err) + } + + memMap["com.loafle.overflow.email.model.EmailAuth"] = string(str) + proxy.InvokeDB("emailAuth", "update", memMap) +} \ No newline at end of file diff --git a/proxy/email/email_service_test.go b/proxy/email/email_service_test.go index 9a98729..3039afe 100644 --- a/proxy/email/email_service_test.go +++ b/proxy/email/email_service_test.go @@ -26,7 +26,14 @@ func TestSendEmailForAuth(t *testing.T) { } func TestEmailService_CheckAuthURL(t *testing.T) { + e, es := getEmailObj() + //e.Id = json.Number("2") + e.AuthToken = "3C03F8AB-1D4D-4C8A-8C36-EE2D644988B5" + + rr := es.CheckAuthURL(e) + + fmt.Println(rr) } func TestAuthTokenGeneration(t *testing.T) {