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>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div id="messageContainer">
|
||||||
|
<p id="successMessage" class="message success"></p>
|
||||||
|
<p id="errorMessage" class="message error"></p>
|
||||||
|
</div>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
function resetPassword() {
|
function resetPassword() {
|
||||||
const new_password = document.getElementById("new_password").value;
|
const new_password = document.getElementById("new_password").value;
|
||||||
@ -141,13 +146,19 @@ function resetPassword() {
|
|||||||
body: JSON.stringify(data)
|
body: JSON.stringify(data)
|
||||||
})
|
})
|
||||||
.then(response => {
|
.then(response => {
|
||||||
if (response.ok) {
|
|
||||||
|
if (response.ok && response.data.code == 200) {
|
||||||
console.log('Password reset successful');
|
console.log('Password reset successful');
|
||||||
// 在这里执行其他成功处理逻辑
|
// 在这里执行其他成功处理逻辑
|
||||||
|
// 显示成功消息或进行其他操作
|
||||||
|
document.getElementById('successMessage').innerText = response.data;
|
||||||
} else {
|
} else {
|
||||||
console.error('Password reset failed');
|
console.error('Password reset failed');
|
||||||
// 在这里执行其他失败处理逻辑
|
// 在这里执行其他失败处理逻辑
|
||||||
|
// 显示失败消息或进行其他操作
|
||||||
|
document.getElementById('errorMessage').innerText = 'Password reset failed. Please try again.';
|
||||||
}
|
}
|
||||||
|
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
console.error('Error:', 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) {
|
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
|
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) {
|
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的资源表
|
// 继承guest_id的资源表
|
||||||
|
@ -53,7 +53,7 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
|||||||
Handler: UserResetPasswordHandler(serverCtx),
|
Handler: UserResetPasswordHandler(serverCtx),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Method: http.MethodPost,
|
Method: http.MethodGet,
|
||||||
Path: "/api/auth/reset/password/html",
|
Path: "/api/auth/reset/password/html",
|
||||||
Handler: UserResetPasswordHtmlHandler(serverCtx),
|
Handler: UserResetPasswordHtmlHandler(serverCtx),
|
||||||
},
|
},
|
||||||
|
@ -34,7 +34,7 @@ func init() {
|
|||||||
EmailManager = &EmailSender{
|
EmailManager = &EmailSender{
|
||||||
EmailTasks: make(chan *EmailFormat, 10),
|
EmailTasks: make(chan *EmailFormat, 10),
|
||||||
Auth: smtp.PlainAuth(
|
Auth: smtp.PlainAuth(
|
||||||
"",
|
"fusen support",
|
||||||
"support@fusenpack.com",
|
"support@fusenpack.com",
|
||||||
"wfbjpdgvaozjvwah",
|
"wfbjpdgvaozjvwah",
|
||||||
"smtp.gmail.com",
|
"smtp.gmail.com",
|
||||||
@ -179,7 +179,6 @@ func (m *EmailSender) Resend(uniqueKey string, content []byte) {
|
|||||||
|
|
||||||
m.lock.Lock()
|
m.lock.Lock()
|
||||||
defer m.lock.Unlock()
|
defer m.lock.Unlock()
|
||||||
|
|
||||||
// Check if the email task still exists and has not been sent successfully
|
// 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()) {
|
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)
|
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 {
|
err = l.svcCtx.AllModels.FsUser.Transaction(l.ctx, func(tx *gorm.DB) error {
|
||||||
user := &gmodel.FsUser{Id: int64(rt.UserId)}
|
user := &gmodel.FsUser{}
|
||||||
err := tx.Take(user).Error
|
err := tx.Model(user).Where("id = ?", rt.UserId).Take(user).Error
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
logx.Error(err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if *user.PasswordHash != rt.OldPassword {
|
if *user.PasswordHash != rt.OldPassword {
|
||||||
@ -67,6 +68,7 @@ func (l *UserResetPasswordLogic) UserResetPassword(req *types.RequestUserResetPa
|
|||||||
})
|
})
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
logx.Error(err)
|
||||||
return resp.SetStatus(basic.CodeDbSqlErr, err.Error())
|
return resp.SetStatus(basic.CodeDbSqlErr, err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -62,16 +62,15 @@ func (l *UserResetTokenLogic) UserResetToken(req *types.RequestUserResetToken, u
|
|||||||
userName := *user.FirstName + " " + *user.LastName
|
userName := *user.FirstName + " " + *user.LastName
|
||||||
// 进入发送邮箱的系统
|
// 进入发送邮箱的系统
|
||||||
EmailManager.EmailTasks <- &EmailFormat{
|
EmailManager.EmailTasks <- &EmailFormat{
|
||||||
TemplateName: "reset_password.tpl",
|
TemplateName: "get_reset_password_html.tpl",
|
||||||
UniqueKey: "reset_password-" + req.Email,
|
UniqueKey: "reset_password-" + req.Email,
|
||||||
TargetEmail: req.Email,
|
TargetEmail: req.Email,
|
||||||
CompanyName: "fusen",
|
CompanyName: "fusen",
|
||||||
ConfirmationLink: resetToken, // 跳转连接
|
ConfirmationLink: l.svcCtx.Config.MainAddress + "/api/auth/reset/password/html?reset_token=" + resetToken, // 跳转连接
|
||||||
SenderName: "support@fusenpack.com",
|
SenderName: "support@fusenpack.com",
|
||||||
SenderTitle: "register-valid",
|
SenderTitle: "reset password",
|
||||||
Extend: map[string]string{
|
Extend: map[string]string{
|
||||||
"UserName": userName,
|
"UserName": userName,
|
||||||
"ResetToken": resetToken,
|
|
||||||
},
|
},
|
||||||
} // email进入队
|
} // email进入队
|
||||||
|
|
||||||
|
@ -37,7 +37,7 @@ type DataResetToken struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type RequestUserResetHtml struct {
|
type RequestUserResetHtml struct {
|
||||||
ResetToken string `json:"reset_token"`
|
ResetToken string `form:"reset_token"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type RequestUserResetPassword struct {
|
type RequestUserResetPassword struct {
|
||||||
|
@ -38,7 +38,7 @@ service auth {
|
|||||||
|
|
||||||
// 获取重定向到html页面
|
// 获取重定向到html页面
|
||||||
@handler UserResetPasswordHtmlHandler
|
@handler UserResetPasswordHtmlHandler
|
||||||
post /api/auth/reset/password/html(RequestUserResetHtml) returns (response);
|
get /api/auth/reset/password/html(RequestUserResetHtml) returns (response);
|
||||||
|
|
||||||
@handler DebugAuthDeleteHandler
|
@handler DebugAuthDeleteHandler
|
||||||
post /api/auth/debug/delete(RequestAuthDelete) returns (response);
|
post /api/auth/debug/delete(RequestAuthDelete) returns (response);
|
||||||
@ -96,7 +96,7 @@ type (
|
|||||||
|
|
||||||
// RequestUserResetPassword 重置密码
|
// RequestUserResetPassword 重置密码
|
||||||
RequestUserResetHtml {
|
RequestUserResetHtml {
|
||||||
ResetToken string `json:"reset_token"`
|
ResetToken string `form:"reset_token"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// RequestUserResetPassword 重置密码
|
// RequestUserResetPassword 重置密码
|
||||||
|
Loading…
x
Reference in New Issue
Block a user