email auth
This commit is contained in:
parent
9802ab5e70
commit
b511e5dfca
@ -12,6 +12,7 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"git.loafle.net/overflow/overflow_proxy_service/proxy"
|
"git.loafle.net/overflow/overflow_proxy_service/proxy"
|
||||||
"git.loafle.net/overflow/overflow_proxy_service/proxy/member"
|
"git.loafle.net/overflow/overflow_proxy_service/proxy/member"
|
||||||
|
"git.loafle.net/overflow/commons_go/model/timestamp"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -23,14 +24,18 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type Email struct {
|
type Email struct {
|
||||||
Id json.Number `json:"id,Number,omitempty"`
|
Id json.Number `json:"id,Number,omitempty"`
|
||||||
Member member.Member `json:"member"`
|
Member member.Member `json:"member"`
|
||||||
From string `json:"_"`
|
From string `json:"_"`
|
||||||
Subj string `json:"_"`
|
Subj string `json:"_"`
|
||||||
AuthToken string `json:"authToken"`
|
AuthToken string `json:"authToken"`
|
||||||
IsInvalid bool `json:"isInvalid"`
|
IsInvalid bool `json:"isInvalid"`
|
||||||
SmtpServer string `json:"_"`
|
IsConfirm bool `json:"isConfirm"`
|
||||||
BodyMsg string `json:"_"`
|
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{}
|
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) {
|
func (es *EmailService) checkError(err error) {
|
||||||
@ -137,6 +118,7 @@ func (es *EmailService)SendEmailForAuth(e *Email) (error){
|
|||||||
//Todo auth token generation
|
//Todo auth token generation
|
||||||
e.AuthToken = es.generationAuthToken(e)
|
e.AuthToken = es.generationAuthToken(e)
|
||||||
e.IsInvalid = false
|
e.IsInvalid = false
|
||||||
|
e.IsConfirm = false
|
||||||
|
|
||||||
conn, err := tls.Dial("tcp", SERVER_NAME, tlsconfig)
|
conn, err := tls.Dial("tcp", SERVER_NAME, tlsconfig)
|
||||||
es.checkError(err)
|
es.checkError(err)
|
||||||
@ -187,3 +169,50 @@ func (es *EmailService) saveEmail(e *Email) {
|
|||||||
proxy.InvokeDB("emailAuth", "create", memMap)
|
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)
|
||||||
|
}
|
@ -26,7 +26,14 @@ func TestSendEmailForAuth(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestEmailService_CheckAuthURL(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) {
|
func TestAuthTokenGeneration(t *testing.T) {
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user