Skip to content

Commit

Permalink
fix: Fix problems about sending verify email
Browse files Browse the repository at this point in the history
  • Loading branch information
rainzm committed Jun 18, 2020
1 parent 8ed4148 commit 109bdc0
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<table style="margin-left: 20px;">
<tr>
<td>
<img src="data:{{.logo_format}};base64,{{.logo}}" alt="" style="color: #fff; width: 80px; vertical-align: middle;">
<img src="data:{{.login_logo_format}};base64,{{.login_logo}}" alt="" style="color: #fff; height: 32px; vertical-align: middle;">
</td>
</tr>
</table>
Expand Down Expand Up @@ -56,10 +56,10 @@
</td>
</tr>
<tr style="width: 96%;">
<td colspan="2" style="border-top: 1px dashed #ccc; color: #ccc; font-size: 12px; padding-bottom: 10px; font-weight: 100;">*为了确保您的帐号安全,该链接仅48小时内访问有效,请勿直接回复此邮件。</td>
<td colspan="2" style="border-top: 1px dashed #ccc; color: #333; font-size: 12px; padding-bottom: 10px; font-weight: 100;">*为了确保您的帐号安全,该链接仅48小时内访问有效,请勿直接回复此邮件。</td>
</tr>
<tr>
<td colspan="2" style="background: #333; text-align: right; padding-right: 20px; font-size: 12px; color: #949494; height: 50px;">版权所有 © {{.copyright}} 保留一切权利</td>
<td colspan="2" style="background: #333; text-align: right; padding-right: 20px; font-size: 12px; color: #fff; height: 50px;">版权所有 © {{.copyright}} 保留一切权利</td>
</tr>
</table>
</body>
Expand Down
47 changes: 10 additions & 37 deletions pkg/notify/models/mod_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ var templatePath = "/opt/yunion/share/template"
func (tm *STemplateManager) defaultTemplate() ([]STemplate, error) {
templates := make([]STemplate, 0, 4)

for _, templateType := range []string{"title", "content", "remote"} {
for _, templateType := range []string{"title", "content"} {
contactType, topic := CONTACTTYPE_ALL, ""
titleTemplatePath := fmt.Sprintf("%s/%s", templatePath, templateType)
files, err := ioutil.ReadDir(titleTemplatePath)
Expand Down Expand Up @@ -122,52 +122,25 @@ func (tm *STemplateManager) defaultTemplate() ([]STemplate, error) {
return templates, nil
}

var (
InitVerifyEmailOver = false
)

type CompanyInfo struct {
Logo string
LogoFormat string
Copyright string
type SCompanyInfo struct {
LoginLogo string `json:"login_logo"`
LoginLogoFormat string `json:"login_logo_format"`
Copyright string `json:"copyright"`
}

func (tm *STemplateManager) TryInitVerifyEmail(ctx context.Context) error {
if InitVerifyEmailOver {
return nil
}
func (tm *STemplateManager) GetCompanyInfo(ctx context.Context) (SCompanyInfo, error) {
// fetch copyright and logo
session := auth.GetAdminSession(ctx, "", "")
obj, err := modules.Info.Get(session, "info", jsonutils.NewDict())
if err != nil {
return err
return SCompanyInfo{}, err
}
var info CompanyInfo
var info SCompanyInfo
err = obj.Unmarshal(&info)
if err != nil {
return err
return SCompanyInfo{}, err
}

// fetch verify email template
q := tm.Query().Equals("contact_type", "email").Equals("topic", "VERIFY").Equals("template_type", "content")
tem := &STemplate{}
err = q.First(tem)
if err != nil {
return err
}

tem.SetModelManager(TemplateManager, tem)

content, err := tem.Execute(jsonutils.Marshal(info).String())
if err != nil {
return err
}

_, err = db.Update(tem, func() error {
tem.Content = content
return nil
})
return err
return info, nil
}

func (tm *STemplateManager) InitializeData() error {
Expand Down
11 changes: 8 additions & 3 deletions pkg/notify/models/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@ func SendVerifyMessage(ctx context.Context, userCred mcclient.TokenCredential, v
err error
msg string
)
err = TemplateManager.TryInitVerifyEmail(ctx)
info, err := TemplateManager.GetCompanyInfo(ctx)
if err != nil {
log.Errorf("unable to try to init verify eamil: %s", err.Error())
log.Errorf("unable to try to get company info: %s", err.Error())
}
processId, token := verify.ID, verify.Token
if contact.ContactType == "email" {
Expand All @@ -92,7 +92,12 @@ func SendVerifyMessage(ctx context.Context, userCred mcclient.TokenCredential, v
data := struct {
Name string
Link string
}{uName, emailUrl}
SCompanyInfo
}{
Name: uName,
Link: emailUrl,
SCompanyInfo: info,
}
msg = jsonutils.Marshal(data).String()
} else if contact.ContactType == "mobile" {
msg = fmt.Sprintf(`{"code": "%s"}`, token)
Expand Down

0 comments on commit 109bdc0

Please sign in to comment.