go fmt
This commit is contained in:
parent
d75306d489
commit
3701881461
|
@ -1,76 +1,72 @@
|
|||
package email
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net"
|
||||
"net/smtp"
|
||||
"crypto/tls"
|
||||
"log"
|
||||
"net/mail"
|
||||
"strings"
|
||||
"github.com/google/uuid"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"git.loafle.net/overflow/commons_go/model/timestamp"
|
||||
"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"
|
||||
"github.com/google/uuid"
|
||||
"log"
|
||||
"net"
|
||||
"net/mail"
|
||||
"net/smtp"
|
||||
"strings"
|
||||
)
|
||||
|
||||
const (
|
||||
FROM = "geek@loafle.com"
|
||||
FROM = "geek@loafle.com"
|
||||
SERVER_NAME = "smtp.worksmobile.com:465"
|
||||
SUBJECT = "This is the Test Email"
|
||||
BODY_MSG = "This is an Example Email\n with two lines \n http://localhost:8080/v1/overflow/services"
|
||||
SUBJECT = "This is the Test Email"
|
||||
BODY_MSG = "This is an Example Email\n with two lines \n http://localhost:8080/v1/overflow/services"
|
||||
SERVER_PASS = "@loafle@5795"
|
||||
)
|
||||
|
||||
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"`
|
||||
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:"_"`
|
||||
|
||||
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:"_"`
|
||||
}
|
||||
|
||||
func NewEmail(member member.Member, subject string) *Email {
|
||||
|
||||
if subject == ""{
|
||||
if subject == "" {
|
||||
subject = SUBJECT
|
||||
}
|
||||
|
||||
return &Email{
|
||||
Member:member,
|
||||
From:FROM,
|
||||
Subj:subject,
|
||||
SmtpServer:SERVER_NAME,
|
||||
Member: member,
|
||||
From: FROM,
|
||||
Subj: subject,
|
||||
SmtpServer: SERVER_NAME,
|
||||
}
|
||||
}
|
||||
|
||||
type EmailService struct {
|
||||
|
||||
}
|
||||
|
||||
func NewEmailService() *EmailService{
|
||||
func NewEmailService() *EmailService {
|
||||
return &EmailService{}
|
||||
}
|
||||
|
||||
|
||||
|
||||
func (es *EmailService) checkError(err error) {
|
||||
if err != nil {
|
||||
log.Panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
func (es *EmailService) getSendMailMessage(e *Email) (string) {
|
||||
to := mail.Address{"Park Byung Eun",e.Member.Email}
|
||||
func (es *EmailService) getSendMailMessage(e *Email) string {
|
||||
to := mail.Address{"Park Byung Eun", e.Member.Email}
|
||||
from := mail.Address{"Overflow", e.From}
|
||||
//body := "This is an Example Email\n with two lines \n http://localhost:8080/v1/overflow/services"
|
||||
|
||||
|
@ -83,7 +79,7 @@ func (es *EmailService) getSendMailMessage(e *Email) (string) {
|
|||
message := ""
|
||||
|
||||
for k, v := range headers {
|
||||
message += fmt.Sprintf("%s: %s\r\n",k,v)
|
||||
message += fmt.Sprintf("%s: %s\r\n", k, v)
|
||||
}
|
||||
message += "\r\n" + BODY_MSG
|
||||
|
||||
|
@ -93,26 +89,25 @@ func (es *EmailService) getSendMailMessage(e *Email) (string) {
|
|||
func (es *EmailService) generationAuthToken(e *Email) string {
|
||||
var tempToken string
|
||||
|
||||
uuid,_ := uuid.NewRandom()
|
||||
uuid, _ := uuid.NewRandom()
|
||||
tempToken += strings.ToUpper(uuid.String())
|
||||
|
||||
return tempToken
|
||||
}
|
||||
|
||||
|
||||
func (es *EmailService)SendEmailForAuth(e *Email) (error){
|
||||
to := mail.Address{"Park Byung Eun",e.Member.Email}
|
||||
func (es *EmailService) SendEmailForAuth(e *Email) error {
|
||||
to := mail.Address{"Park Byung Eun", e.Member.Email}
|
||||
from := mail.Address{"Overflow", e.From}
|
||||
|
||||
message := es.getSendMailMessage(e)
|
||||
|
||||
host, _, _ := net.SplitHostPort(SERVER_NAME)
|
||||
auth := smtp.PlainAuth("",FROM, SERVER_PASS, host)
|
||||
auth := smtp.PlainAuth("", FROM, SERVER_PASS, host)
|
||||
|
||||
// TLS config
|
||||
tlsconfig := &tls.Config {
|
||||
tlsconfig := &tls.Config{
|
||||
InsecureSkipVerify: true,
|
||||
ServerName: host,
|
||||
ServerName: host,
|
||||
}
|
||||
|
||||
//Todo auth token generation
|
||||
|
@ -188,7 +183,7 @@ func (es *EmailService) CheckAuthURL(e *Email) bool {
|
|||
tempEmail := &Email{}
|
||||
json.Unmarshal([]byte(re), tempEmail)
|
||||
|
||||
r := strings.Compare(e.AuthToken, tempEmail.AuthToken)
|
||||
r := strings.Compare(e.AuthToken, tempEmail.AuthToken)
|
||||
|
||||
log.Println(tempEmail)
|
||||
if r == 0 {
|
||||
|
@ -207,4 +202,4 @@ func (es *EmailService) modifyEmailAuth(e *Email) {
|
|||
emMap := es.getEmailMap(e)
|
||||
|
||||
proxy.InvokeDB("emailAuth", "update", emMap)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user