Add User reset password
This commit is contained in:
parent
0839c04257
commit
80ee503798
@ -2,18 +2,20 @@ package config
|
|||||||
|
|
||||||
type Email struct {
|
type Email struct {
|
||||||
Sender string `mapstructure:"sender"`
|
Sender string `mapstructure:"sender"`
|
||||||
|
SenderCustomer string `mapstructure:"sender_customer"`
|
||||||
CustomReceiver string `mapstructure:"custom_receiver"`
|
CustomReceiver string `mapstructure:"custom_receiver"`
|
||||||
ResetPassword EmailConfig `mapstructure:"reset_password"`
|
ResetPassword EmailConfig `mapstructure:"reset_password"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type EmailConfig struct {
|
type EmailConfig struct {
|
||||||
Subject string `mapstructure:"subject"`
|
Subject string `mapstructure:"subject"`
|
||||||
OpeningWord string `mapstructure:"opening_word"`
|
OpeningWord string `mapstructure:"opening_word"`
|
||||||
Link string `mapstructure:"link"`
|
Link string `mapstructure:"link"`
|
||||||
Notes string `mapstructure:"note"`
|
Notes string `mapstructure:"note"`
|
||||||
ClosingWord string `mapstructure:"closing_word"`
|
ClosingWord string `mapstructure:"closing_word"`
|
||||||
TemplateName string `mapstructure:"template_name"`
|
TemplateName string `mapstructure:"template_name"`
|
||||||
TemplatePath string `mapstructure:"template_path"`
|
TemplatePath string `mapstructure:"template_path"`
|
||||||
|
TemplatePathCustomer string `mapstructure:"template_path_customer"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type EmailMemberRequestActionConfig struct {
|
type EmailMemberRequestActionConfig struct {
|
||||||
|
|||||||
@ -45,9 +45,11 @@ brevo:
|
|||||||
|
|
||||||
email:
|
email:
|
||||||
sender: "furtuna.official@gmail.com"
|
sender: "furtuna.official@gmail.com"
|
||||||
|
sender_customer: "furtuna.official@gmail.com"
|
||||||
reset_password:
|
reset_password:
|
||||||
template_name: "reset_password"
|
template_name: "reset_password"
|
||||||
template_path: "templates/reset_password.html"
|
template_path: "templates/reset_password.html"
|
||||||
|
template_path_customer: "templates/reset_password_customer.html"
|
||||||
subject: "Reset Password"
|
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:"
|
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."
|
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."
|
||||||
|
|||||||
@ -2,6 +2,7 @@ package auth
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"fmt"
|
||||||
"furtuna-be/config"
|
"furtuna-be/config"
|
||||||
"furtuna-be/internal/common/mycontext"
|
"furtuna-be/internal/common/mycontext"
|
||||||
"furtuna-be/internal/entity"
|
"furtuna-be/internal/entity"
|
||||||
@ -117,25 +118,32 @@ func (u *AuthServiceImpl) SendPasswordResetLink(ctx context.Context, email strin
|
|||||||
return errors.ErrorInternalServer
|
return errors.ErrorInternalServer
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update the user's password in the database
|
|
||||||
if err := u.authRepo.UpdatePassword(ctx, trx, hashPassword, user.ID, true); err != nil {
|
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))
|
logger.ContextLogger(ctx).Error("error when updating user password", zap.Error(err))
|
||||||
u.trxRepo.Rollback(trx)
|
u.trxRepo.Rollback(trx)
|
||||||
return errors.ErrorInternalServer
|
return errors.ErrorInternalServer
|
||||||
}
|
}
|
||||||
|
|
||||||
// If a custom receiver is specified, override the email
|
|
||||||
if u.emailCfg.CustomReceiver != "" {
|
if u.emailCfg.CustomReceiver != "" {
|
||||||
email = 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
|
// Prepare the email notification parameters
|
||||||
renewPasswordRequest := entity.SendEmailNotificationParam{
|
renewPasswordRequest := entity.SendEmailNotificationParam{
|
||||||
Sender: u.emailCfg.Sender,
|
Sender: sender,
|
||||||
Recipient: email,
|
Recipient: email,
|
||||||
Subject: u.emailCfg.ResetPassword.Subject,
|
Subject: subject,
|
||||||
TemplateName: u.emailCfg.ResetPassword.TemplateName,
|
TemplateName: u.emailCfg.ResetPassword.TemplateName,
|
||||||
TemplatePath: u.emailCfg.ResetPassword.TemplatePath,
|
TemplatePath: templatePath,
|
||||||
Data: map[string]interface{}{
|
Data: map[string]interface{}{
|
||||||
"Name": user.Name,
|
"Name": user.Name,
|
||||||
"OpeningWord": u.emailCfg.ResetPassword.OpeningWord,
|
"OpeningWord": u.emailCfg.ResetPassword.OpeningWord,
|
||||||
|
|||||||
137
templates/reset_password_customer.html
Normal file
137
templates/reset_password_customer.html
Normal file
@ -0,0 +1,137 @@
|
|||||||
|
<!doctype html>
|
||||||
|
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office">
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<title>Reset Password</title>
|
||||||
|
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||||
|
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
|
<style type="text/css">
|
||||||
|
body {
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
-webkit-text-size-adjust: 100%;
|
||||||
|
-ms-text-size-adjust: 100%;
|
||||||
|
background-color: #f1f0f7;
|
||||||
|
}
|
||||||
|
|
||||||
|
table,
|
||||||
|
td {
|
||||||
|
border-collapse: collapse;
|
||||||
|
mso-table-lspace: 0pt;
|
||||||
|
mso-table-rspace: 0pt;
|
||||||
|
}
|
||||||
|
|
||||||
|
img {
|
||||||
|
border: 0;
|
||||||
|
height: auto;
|
||||||
|
line-height: 100%;
|
||||||
|
outline: none;
|
||||||
|
text-decoration: none;
|
||||||
|
-ms-interpolation-mode: bicubic;
|
||||||
|
}
|
||||||
|
|
||||||
|
p {
|
||||||
|
display: block;
|
||||||
|
margin: 13px 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.mj-column-per-100 {
|
||||||
|
width: 100% !important;
|
||||||
|
max-width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.content {
|
||||||
|
background-color: #ffffff;
|
||||||
|
margin: 0px auto;
|
||||||
|
max-width: 600px;
|
||||||
|
padding: 20px;
|
||||||
|
border-radius: 10px;
|
||||||
|
box-shadow: 0px 4px 8px rgba(0, 0, 0, 0.1);
|
||||||
|
}
|
||||||
|
|
||||||
|
.header {
|
||||||
|
font-family: Ubuntu, Helvetica, Arial, sans-serif;
|
||||||
|
font-size: 24px;
|
||||||
|
line-height: 28px;
|
||||||
|
color: #f46f02;
|
||||||
|
text-align: center;
|
||||||
|
margin-bottom: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.title {
|
||||||
|
font-family: Ubuntu, Helvetica, Arial, sans-serif;
|
||||||
|
font-size: 20px;
|
||||||
|
line-height: 22px;
|
||||||
|
color: #000000;
|
||||||
|
text-align: center;
|
||||||
|
margin-bottom: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.text {
|
||||||
|
font-family: Ubuntu, Helvetica, Arial, sans-serif;
|
||||||
|
font-size: 16px;
|
||||||
|
line-height: 22px;
|
||||||
|
color: #000000;
|
||||||
|
text-align: center;
|
||||||
|
margin-bottom: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.password {
|
||||||
|
display: block;
|
||||||
|
width: fit-content;
|
||||||
|
margin: 20px auto;
|
||||||
|
background-color: #f5f5f5;
|
||||||
|
color: #000000;
|
||||||
|
text-align: center;
|
||||||
|
padding: 15px 25px;
|
||||||
|
border-radius: 5px;
|
||||||
|
font-family: Ubuntu, Helvetica, Arial, sans-serif;
|
||||||
|
font-size: 18px;
|
||||||
|
line-height: 22px;
|
||||||
|
font-weight: bold;
|
||||||
|
letter-spacing: 1px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.footer {
|
||||||
|
font-family: Ubuntu, Helvetica, Arial, sans-serif;
|
||||||
|
font-size: 12px;
|
||||||
|
line-height: 15px;
|
||||||
|
text-align: center;
|
||||||
|
color: #808080;
|
||||||
|
margin-top: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.divider {
|
||||||
|
border-top: solid 1px #808080;
|
||||||
|
margin: 20px auto;
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.logo {
|
||||||
|
display: block;
|
||||||
|
margin: 0 auto 20px;
|
||||||
|
width: 150px;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<div style="padding: 50px; background-color: #f1f0f7;">
|
||||||
|
<div class="content">
|
||||||
|
<img src="https://res.cloudinary.com/dl0wpumax/image/upload/v1724958874/logo_sf947j.png" alt="Ayogo Logo" class="logo">
|
||||||
|
<div class="title">Lupa Kata Sandi</div>
|
||||||
|
<div class="text">
|
||||||
|
Kami mengirimkan Anda email ini karena Anda meminta pengaturan ulang kata sandi. Berikut adalah kata sandi sementara Anda:
|
||||||
|
</div>
|
||||||
|
<div class="password">{{ .Password }}</div>
|
||||||
|
<div class="text">Gunakan kata sandi ini untuk masuk dan segera ganti kata sandi Anda setelah berhasil masuk.</div>
|
||||||
|
<div class="divider"></div>
|
||||||
|
<div class="footer">
|
||||||
|
Jangan Bagikan Email Ini. Email ini berisi informasi sensitif. Harap jangan membagikan email, kata sandi, atau kode akses ini kepada orang lain.
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
|
||||||
|
</html>
|
||||||
Loading…
x
Reference in New Issue
Block a user