fix(quality): switch linter and fix errors

This commit is contained in:
2024-12-02 23:26:26 +01:00
parent 7c67720621
commit 0accb49871
7 changed files with 38 additions and 26 deletions

View File

@@ -280,7 +280,9 @@ func (service AuthServiceImpl) ChangePassword(user *User, currPass, newPass stri
newHash := GetHashPassword(newPass, userDb.Salt)
err = service.dbAuth.UpdateUserPassword(user.Id, newHash)
userDb.Password = newHash
err = service.dbAuth.UpdateUser(userDb)
if err != nil {
return err
}
@@ -304,7 +306,7 @@ func (service AuthServiceImpl) ForgotPassword(email string) error {
utils.LogError("Could not render reset password email", err)
return types.ErrInternal
}
service.mailService.SendMail(email, "Reset Password", mail.String())
go service.mailService.SendMail(email, "Reset Password", mail.String())
}
return nil

View File

@@ -238,7 +238,7 @@ func TestSendVerificationMail(t *testing.T) {
mockAuthDb.EXPECT().GetEmailVerificationToken(userId).Return(token, nil)
mockMail.EXPECT().SendMail(email, "Welcome to ME-FIT", mock.MatchedBy(func(message string) bool { return strings.Contains(message, token) })).Return(nil)
mockMail.EXPECT().SendMail(email, "Welcome to ME-FIT", mock.MatchedBy(func(message string) bool { return strings.Contains(message, token) })).Return()
underTest := NewAuthServiceImpl(mockAuthDb, mockRandom, mockClock, mockMail, &types.ServerSettings{})

View File

@@ -2,12 +2,15 @@ package service
import (
"fmt"
"me-fit/types"
"net/smtp"
"me-fit/types"
"me-fit/utils"
)
type MailService interface {
SendMail(to string, subject string, message string) error
// Sending an email is a fire and forget operation. Thus no error handling
SendMail(to string, subject string, message string)
}
type MailServiceImpl struct {
@@ -18,9 +21,9 @@ func NewMailServiceImpl(serverSettings *types.ServerSettings) MailServiceImpl {
return MailServiceImpl{serverSettings: serverSettings}
}
func (m MailServiceImpl) SendMail(to string, subject string, message string) error {
func (m MailServiceImpl) SendMail(to string, subject string, message string) {
if m.serverSettings.Smtp == nil {
return nil
return
}
s := m.serverSettings.Smtp
@@ -29,5 +32,8 @@ func (m MailServiceImpl) SendMail(to string, subject string, message string) err
msg := fmt.Sprintf("From: %v <%v>\nTo: %v\nSubject: %v\nMIME-version: 1.0;\nContent-Type: text/html; charset=\"UTF-8\";\n\n%v", s.FromName, s.FromMail, to, subject, message)
return smtp.SendMail(s.Host+":"+s.Port, auth, s.FromMail, []string{to}, []byte(msg))
err := smtp.SendMail(s.Host+":"+s.Port, auth, s.FromMail, []string{to}, []byte(msg))
if err != nil {
utils.LogError("Error sending mail: %v", err)
}
}