Merge branch 'develop' of gitee.com:fusenpack/fusenapi into develop
This commit is contained in:
commit
262c8dc1b5
16
fs_template/get_reset_password_html.tpl
Normal file
16
fs_template/get_reset_password_html.tpl
Normal file
|
@ -0,0 +1,16 @@
|
|||
Subject: Password Reset Request for Your {{ .CompanyName }} Account
|
||||
|
||||
Dear {{ .UserName }},
|
||||
|
||||
We have received your request to reset the password for your {{ .CompanyName }} account.
|
||||
|
||||
To proceed with the password reset, please click the button below to open the Reset Password page:
|
||||
|
||||
<a href="{{ .ConfirmationLink }}" target="_blank" style="color: #FFFFFF; text-decoration: none;">Reset Password</a>
|
||||
|
||||
Please note that this password reset confirmation link will expire in 60 minutes. If you have any further questions, feel free to reach out to us.
|
||||
|
||||
Regards,
|
||||
{{ .SenderName }}
|
||||
{{ .SenderTitle }}
|
||||
{{ .CompanyName }}
|
|
@ -117,6 +117,11 @@ button:hover {
|
|||
</form>
|
||||
</div>
|
||||
|
||||
<div id="messageContainer">
|
||||
<p id="successMessage" class="message success"></p>
|
||||
<p id="errorMessage" class="message error"></p>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
function resetPassword() {
|
||||
const new_password = document.getElementById("new_password").value;
|
||||
|
@ -141,13 +146,19 @@ function resetPassword() {
|
|||
body: JSON.stringify(data)
|
||||
})
|
||||
.then(response => {
|
||||
if (response.ok) {
|
||||
|
||||
if (response.ok && response.data.code == 200) {
|
||||
console.log('Password reset successful');
|
||||
// 在这里执行其他成功处理逻辑
|
||||
// 显示成功消息或进行其他操作
|
||||
document.getElementById('successMessage').innerText = response.data;
|
||||
} else {
|
||||
console.error('Password reset failed');
|
||||
// 在这里执行其他失败处理逻辑
|
||||
// 显示失败消息或进行其他操作
|
||||
document.getElementById('errorMessage').innerText = 'Password reset failed. Please try again.';
|
||||
}
|
||||
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Error:', error);
|
||||
|
|
|
@ -1,16 +0,0 @@
|
|||
Dear {{ .UserName }},
|
||||
|
||||
We have received your request to reset your {{ .CompanyName }} account password.
|
||||
|
||||
Please click the button below to confirm your new password:
|
||||
|
||||
<h1 style="color: red; font-weight: bold;">{{ .MaskedPassword }}</h1> (This can be replaced by the masked new password)
|
||||
|
||||
<a href="{{ .ConfirmationLink }}" target="_blank" style="background-color: #008CBA; color: #FFFFFF; text-decoration: none; padding: 10px 15px; border-radius: 3px; font-weight: bold;">Confirm New Password</a>
|
||||
|
||||
This password reset confirmation link will expire in 60 minutes. Please let us know if you have any other questions!
|
||||
|
||||
Regards,
|
||||
{{ .SenderName }}
|
||||
{{ .SenderTitle }}
|
||||
{{ .CompanyName }}
|
|
@ -31,7 +31,7 @@ type UserBasicInfoForSave struct {
|
|||
}
|
||||
|
||||
func (u *FsUserModel) FindUserByEmail(ctx context.Context, emailname string) (resp FsUser, err error) {
|
||||
err = u.db.WithContext(ctx).Model(&FsUser{}).Where("`email` = ?", emailname).Take(&resp).Error
|
||||
err = u.db.WithContext(ctx).Model(&FsUser{}).Where("`email` = ? and is_del = ?", emailname, 0).Take(&resp).Error
|
||||
return resp, err
|
||||
}
|
||||
|
||||
|
@ -46,7 +46,7 @@ func (u *FsUserModel) FindUserByGoogleId(ctx context.Context, Id int64) (resp Fs
|
|||
}
|
||||
|
||||
func (u *FsUserModel) Transaction(ctx context.Context, fc func(tx *gorm.DB) error) (err error) {
|
||||
return u.db.WithContext(ctx).Transaction(fc)
|
||||
return u.db.Model(&FsUser{}).WithContext(ctx).Transaction(fc)
|
||||
}
|
||||
|
||||
// 继承guest_id的资源表
|
||||
|
|
|
@ -53,7 +53,7 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
|||
Handler: UserResetPasswordHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
Method: http.MethodPost,
|
||||
Method: http.MethodGet,
|
||||
Path: "/api/auth/reset/password/html",
|
||||
Handler: UserResetPasswordHtmlHandler(serverCtx),
|
||||
},
|
||||
|
|
|
@ -34,7 +34,7 @@ func init() {
|
|||
EmailManager = &EmailSender{
|
||||
EmailTasks: make(chan *EmailFormat, 10),
|
||||
Auth: smtp.PlainAuth(
|
||||
"",
|
||||
"fusen support",
|
||||
"support@fusenpack.com",
|
||||
"wfbjpdgvaozjvwah",
|
||||
"smtp.gmail.com",
|
||||
|
@ -179,7 +179,6 @@ func (m *EmailSender) Resend(uniqueKey string, content []byte) {
|
|||
|
||||
m.lock.Lock()
|
||||
defer m.lock.Unlock()
|
||||
|
||||
// Check if the email task still exists and has not been sent successfully
|
||||
if task, ok := m.emailSending[uniqueKey]; ok && task.SendTime.Add(m.ResendTimeLimit).After(time.Now().UTC()) {
|
||||
err := smtp.SendMail(task.Email.TargetEmail, m.Auth, m.FromEmail, []string{task.Email.TargetEmail}, content)
|
||||
|
|
|
@ -55,9 +55,10 @@ func (l *UserResetPasswordLogic) UserResetPassword(req *types.RequestUserResetPa
|
|||
}
|
||||
|
||||
err = l.svcCtx.AllModels.FsUser.Transaction(l.ctx, func(tx *gorm.DB) error {
|
||||
user := &gmodel.FsUser{Id: int64(rt.UserId)}
|
||||
err := tx.Take(user).Error
|
||||
user := &gmodel.FsUser{}
|
||||
err := tx.Model(user).Where("id = ?", rt.UserId).Take(user).Error
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
return err
|
||||
}
|
||||
if *user.PasswordHash != rt.OldPassword {
|
||||
|
@ -67,6 +68,7 @@ func (l *UserResetPasswordLogic) UserResetPassword(req *types.RequestUserResetPa
|
|||
})
|
||||
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
return resp.SetStatus(basic.CodeDbSqlErr, err.Error())
|
||||
}
|
||||
|
||||
|
|
|
@ -62,16 +62,15 @@ func (l *UserResetTokenLogic) UserResetToken(req *types.RequestUserResetToken, u
|
|||
userName := *user.FirstName + " " + *user.LastName
|
||||
// 进入发送邮箱的系统
|
||||
EmailManager.EmailTasks <- &EmailFormat{
|
||||
TemplateName: "reset_password.tpl",
|
||||
TemplateName: "get_reset_password_html.tpl",
|
||||
UniqueKey: "reset_password-" + req.Email,
|
||||
TargetEmail: req.Email,
|
||||
CompanyName: "fusen",
|
||||
ConfirmationLink: resetToken, // 跳转连接
|
||||
ConfirmationLink: l.svcCtx.Config.MainAddress + "/api/auth/reset/password/html?reset_token=" + resetToken, // 跳转连接
|
||||
SenderName: "support@fusenpack.com",
|
||||
SenderTitle: "register-valid",
|
||||
SenderTitle: "reset password",
|
||||
Extend: map[string]string{
|
||||
"UserName": userName,
|
||||
"ResetToken": resetToken,
|
||||
"UserName": userName,
|
||||
},
|
||||
} // email进入队
|
||||
|
||||
|
|
|
@ -37,7 +37,7 @@ type DataResetToken struct {
|
|||
}
|
||||
|
||||
type RequestUserResetHtml struct {
|
||||
ResetToken string `json:"reset_token"`
|
||||
ResetToken string `form:"reset_token"`
|
||||
}
|
||||
|
||||
type RequestUserResetPassword struct {
|
||||
|
|
|
@ -38,7 +38,7 @@ service auth {
|
|||
|
||||
// 获取重定向到html页面
|
||||
@handler UserResetPasswordHtmlHandler
|
||||
post /api/auth/reset/password/html(RequestUserResetHtml) returns (response);
|
||||
get /api/auth/reset/password/html(RequestUserResetHtml) returns (response);
|
||||
|
||||
@handler DebugAuthDeleteHandler
|
||||
post /api/auth/debug/delete(RequestAuthDelete) returns (response);
|
||||
|
@ -96,7 +96,7 @@ type (
|
|||
|
||||
// RequestUserResetPassword 重置密码
|
||||
RequestUserResetHtml {
|
||||
ResetToken string `json:"reset_token"`
|
||||
ResetToken string `form:"reset_token"`
|
||||
}
|
||||
|
||||
// RequestUserResetPassword 重置密码
|
||||
|
|
Loading…
Reference in New Issue
Block a user