Merge pull request #6869 from rainzm/notify/email_fix

Notify/email fix
This commit is contained in:
yunion-ci-robot
2020-06-18 20:13:02 +08:00
committed by GitHub
4 changed files with 22 additions and 44 deletions
@@ -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>
@@ -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>
+1 -1
View File
@@ -26,7 +26,7 @@ type NotifyTemplateManager struct {
}
func (nm *NotifyTemplateManager) DeleteContents(s *mcclient.ClientSession, params jsonutils.JSONObject) (jsonutils.JSONObject, error) {
path := "/templates/delete-template"
path := "/notifytemplates/delete-template"
return modulebase.Post(nm.ResourceManager, s, path, params, "")
}
+10 -37
View File
@@ -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)
@@ -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 {
+8 -3
View File
@@ -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" {
@@ -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)