Merge branch 'master' of https://git.loafle.net/overflow/overflow_service
This commit is contained in:
commit
c8399a63b8
@ -13,6 +13,7 @@ import (
|
||||
"net/mail"
|
||||
"net/smtp"
|
||||
"strings"
|
||||
"git.loafle.net/overflow/overflow_service/proxy/utils"
|
||||
)
|
||||
|
||||
const (
|
||||
@ -28,12 +29,9 @@ type Email struct {
|
||||
Member member.Member `json:"member"`
|
||||
From string `json:"_"`
|
||||
Subj string `json:"_"`
|
||||
AuthToken string `json:"authToken"`
|
||||
IsInvalid bool `json:"isInvalid"`
|
||||
IsConfirm bool `json:"isConfirm"`
|
||||
EmailAuthKey string `json:"EmailAuthKey"`
|
||||
CreateDate timestamp.Timestamp `json:"createDate,omitempty"`
|
||||
UpdateDate timestamp.Timestamp `json:"updateDate,omitempty"`
|
||||
ConfirmDate timestamp.Timestamp `json:"confirmDate,omitempty"`
|
||||
authConfirmDate timestamp.Timestamp `json:"authConfirmDate,omitempty"`
|
||||
SmtpServer string `json:"_"`
|
||||
BodyMsg string `json:"_"`
|
||||
}
|
||||
@ -111,9 +109,7 @@ func (es *EmailService) SendEmailForAuth(e *Email) error {
|
||||
}
|
||||
|
||||
//Todo auth token generation
|
||||
e.AuthToken = es.generationAuthToken(e)
|
||||
e.IsInvalid = false
|
||||
e.IsConfirm = false
|
||||
e.EmailAuthKey = es.generationAuthToken(e)
|
||||
|
||||
conn, err := tls.Dial("tcp", SERVER_NAME, tlsconfig)
|
||||
es.checkError(err)
|
||||
@ -150,25 +146,15 @@ func (es *EmailService) SendEmailForAuth(e *Email) error {
|
||||
return err
|
||||
}
|
||||
|
||||
func (es *EmailService) getEmailMap(e *Email) map[string]string {
|
||||
|
||||
emMap := make(map[string]string)
|
||||
|
||||
str, err := json.Marshal(e)
|
||||
|
||||
if err != nil {
|
||||
log.Fatal("Json Marshal Error: ", err)
|
||||
}
|
||||
|
||||
emMap["com.loafle.overflow.email.model.EmailAuth"] = string(str)
|
||||
|
||||
return emMap
|
||||
}
|
||||
|
||||
func (es *EmailService) saveEmail(e *Email) {
|
||||
|
||||
memMap := es.getEmailMap(e)
|
||||
proxy.InvokeDB("emailAuth", "create", memMap)
|
||||
rr, err := utils.InvokeDBByModel("emailAuth","save", e, utils.MODEL_EMAIL_AUTH)
|
||||
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
log.Println(rr)
|
||||
|
||||
}
|
||||
|
||||
@ -176,23 +162,24 @@ func (es *EmailService) CheckAuthURL(e *Email) bool {
|
||||
|
||||
//Query from the database with an authentication token.
|
||||
|
||||
emMap := es.getEmailMap(e)
|
||||
re, err := utils.InvokeDBByModel("emailAuth","findByEmailAuthKey", e.EmailAuthKey, utils.MODEL_STRING)
|
||||
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
re := proxy.InvokeDB("emailAuth", "findByAuthToken", emMap)
|
||||
|
||||
tempEmail := &Email{}
|
||||
json.Unmarshal([]byte(re), tempEmail)
|
||||
|
||||
r := strings.Compare(e.AuthToken, tempEmail.AuthToken)
|
||||
r := strings.Compare(e.EmailAuthKey, tempEmail.EmailAuthKey)
|
||||
|
||||
//Todo Check for valid
|
||||
|
||||
log.Println(tempEmail)
|
||||
if r == 0 {
|
||||
// Todo isConfirm change true and db update
|
||||
tempEmail.IsConfirm = true
|
||||
tempEmail.UpdateDate = timestamp.Now()
|
||||
tempEmail.ConfirmDate = timestamp.Now()
|
||||
tempEmail.authConfirmDate = timestamp.Now()
|
||||
|
||||
es.modifyEmailAuth(tempEmail)
|
||||
return true
|
||||
@ -201,7 +188,13 @@ func (es *EmailService) CheckAuthURL(e *Email) bool {
|
||||
}
|
||||
|
||||
func (es *EmailService) modifyEmailAuth(e *Email) {
|
||||
emMap := es.getEmailMap(e)
|
||||
|
||||
proxy.InvokeDB("emailAuth", "update", emMap)
|
||||
re, err := utils.InvokeDBByModel("emailAuth","save", e, utils.MODEL_EMAIL_AUTH)
|
||||
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
log.Println(re)
|
||||
}
|
||||
|
@ -12,8 +12,8 @@ func getEmailObj() (*Email,*EmailService) {
|
||||
m := member.Member{
|
||||
Email:"geek@loafle.com",
|
||||
Name:"geek",
|
||||
Company:"loafle",
|
||||
Id:json.Number("4"),
|
||||
CompanyName:"loafle",
|
||||
Id:json.Number("2"),
|
||||
}
|
||||
e := NewEmail(m, "Hello Oveflow")
|
||||
|
||||
@ -29,7 +29,7 @@ func TestEmailService_CheckAuthURL(t *testing.T) {
|
||||
e, es := getEmailObj()
|
||||
|
||||
//e.Id = json.Number("2")
|
||||
e.AuthToken = "3C03F8AB-1D4D-4C8A-8C36-EE2D644988B5"
|
||||
e.EmailAuthKey = "3C03F8AB-1D4D-4C8A-8C36-EE2D644988B5"
|
||||
|
||||
rr := es.CheckAuthURL(e)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user