diff --git a/config/email.go b/config/email.go index 863d2e9..ace6a71 100644 --- a/config/email.go +++ b/config/email.go @@ -2,18 +2,20 @@ package config type Email struct { Sender string `mapstructure:"sender"` + SenderCustomer string `mapstructure:"sender_customer"` CustomReceiver string `mapstructure:"custom_receiver"` ResetPassword EmailConfig `mapstructure:"reset_password"` } type EmailConfig struct { - Subject string `mapstructure:"subject"` - OpeningWord string `mapstructure:"opening_word"` - Link string `mapstructure:"link"` - Notes string `mapstructure:"note"` - ClosingWord string `mapstructure:"closing_word"` - TemplateName string `mapstructure:"template_name"` - TemplatePath string `mapstructure:"template_path"` + Subject string `mapstructure:"subject"` + OpeningWord string `mapstructure:"opening_word"` + Link string `mapstructure:"link"` + Notes string `mapstructure:"note"` + ClosingWord string `mapstructure:"closing_word"` + TemplateName string `mapstructure:"template_name"` + TemplatePath string `mapstructure:"template_path"` + TemplatePathCustomer string `mapstructure:"template_path_customer"` } type EmailMemberRequestActionConfig struct { diff --git a/infra/furtuna.development.yaml b/infra/furtuna.development.yaml index 799ea12..e49d63c 100644 --- a/infra/furtuna.development.yaml +++ b/infra/furtuna.development.yaml @@ -45,9 +45,11 @@ brevo: email: sender: "furtuna.official@gmail.com" + sender_customer: "furtuna.official@gmail.com" reset_password: template_name: "reset_password" template_path: "templates/reset_password.html" + template_path_customer: "templates/reset_password_customer.html" subject: "Reset Password" opening_word: "Terima kasih sudah menjadi bagian dari Furtuna. Anda telah berhasil melakukan reset password, silakan masukan unik password yang dibuat oleh sistem dibawah ini:" closing_word: "Silakan login kembali menggunakan email dan password anda diatas, sistem akan secara otomatis meminta anda untuk membuat password baru setelah berhasil login. Mohon maaf atas kendala yang dialami." diff --git a/internal/services/auth/init.go b/internal/services/auth/init.go index 53f40bb..1b9856b 100644 --- a/internal/services/auth/init.go +++ b/internal/services/auth/init.go @@ -2,6 +2,7 @@ package auth import ( "context" + "fmt" "furtuna-be/config" "furtuna-be/internal/common/mycontext" "furtuna-be/internal/entity" @@ -117,25 +118,32 @@ func (u *AuthServiceImpl) SendPasswordResetLink(ctx context.Context, email strin return errors.ErrorInternalServer } - // Update the user's password in the database if err := u.authRepo.UpdatePassword(ctx, trx, hashPassword, user.ID, true); err != nil { logger.ContextLogger(ctx).Error("error when updating user password", zap.Error(err)) u.trxRepo.Rollback(trx) return errors.ErrorInternalServer } - // If a custom receiver is specified, override the email if u.emailCfg.CustomReceiver != "" { email = u.emailCfg.CustomReceiver } + sender := u.emailCfg.Sender + templatePath := u.emailCfg.ResetPassword.TemplatePath + subject := fmt.Sprintf("Furtuna %s", u.emailCfg.ResetPassword.Subject) + if user.UserType == "CUSTOMER" { + sender = u.emailCfg.SenderCustomer + templatePath = u.emailCfg.ResetPassword.TemplatePathCustomer + subject = fmt.Sprintf("Ayogo %s", u.emailCfg.ResetPassword.Subject) + } + // Prepare the email notification parameters renewPasswordRequest := entity.SendEmailNotificationParam{ - Sender: u.emailCfg.Sender, + Sender: sender, Recipient: email, - Subject: u.emailCfg.ResetPassword.Subject, + Subject: subject, TemplateName: u.emailCfg.ResetPassword.TemplateName, - TemplatePath: u.emailCfg.ResetPassword.TemplatePath, + TemplatePath: templatePath, Data: map[string]interface{}{ "Name": user.Name, "OpeningWord": u.emailCfg.ResetPassword.OpeningWord, diff --git a/templates/reset_password_customer.html b/templates/reset_password_customer.html new file mode 100644 index 0000000..112e525 --- /dev/null +++ b/templates/reset_password_customer.html @@ -0,0 +1,137 @@ + + + + + Reset Password + + + + + + + +
+
+ +
Lupa Kata Sandi
+
+ Kami mengirimkan Anda email ini karena Anda meminta pengaturan ulang kata sandi. Berikut adalah kata sandi sementara Anda: +
+
{{ .Password }}
+
Gunakan kata sandi ini untuk masuk dan segera ganti kata sandi Anda setelah berhasil masuk.
+
+ +
+
+ + +