fix(quality): switch linter and fix errors
This commit is contained in:
10
Dockerfile
10
Dockerfile
@@ -1,10 +1,16 @@
|
||||
FROM golang:1.23.3@sha256:73f06be4578c9987ce560087e2e2ea6485fb605e3910542cadd8fa09fc5f3e31 AS builder_go
|
||||
WORKDIR /me-fit
|
||||
RUN go install github.com/a-h/templ/cmd/templ@latest && go install github.com/vektra/mockery/v2@latest && go install honnef.co/go/tools/cmd/staticcheck@latest
|
||||
RUN curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.62.2
|
||||
RUN go install github.com/a-h/templ/cmd/templ@latest
|
||||
RUN go install github.com/vektra/mockery/v2@latest
|
||||
COPY go.mod go.sum ./
|
||||
RUN go mod download
|
||||
COPY . ./
|
||||
RUN templ generate && mockery --log-level warn && staticcheck ./... && go test ./... && go build -o /me-fit/me-fit .
|
||||
RUN templ generate
|
||||
RUN mockery --log-level warn
|
||||
RUN go test ./...
|
||||
RUN golangci-lint run ./...
|
||||
RUN go build -o /me-fit/me-fit .
|
||||
|
||||
|
||||
FROM node:22.11.0@sha256:5c76d05034644fa8ecc9c2aa84e0a83cd981d0ef13af5455b87b9adf5b216561 AS builder_node
|
||||
|
||||
18
db/auth.go
18
db/auth.go
@@ -79,7 +79,6 @@ type AuthDb interface {
|
||||
GetUser(email string) (*User, error)
|
||||
GetUserById(userId uuid.UUID) (*User, error)
|
||||
DeleteUser(userId uuid.UUID) error
|
||||
UpdateUserPassword(userId uuid.UUID, newHash []byte) error
|
||||
|
||||
InsertEmailVerificationToken(userId uuid.UUID, token string) error
|
||||
InsertForgotPasswordToken(email string, token string) error
|
||||
@@ -200,28 +199,28 @@ func (db AuthDbSqlite) DeleteUser(userId uuid.UUID) error {
|
||||
|
||||
_, err = tx.Exec("DELETE FROM workout WHERE user_id = ?", userId)
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
_ = tx.Rollback()
|
||||
utils.LogError("Could not delete workouts", err)
|
||||
return types.ErrInternal
|
||||
}
|
||||
|
||||
_, err = tx.Exec("DELETE FROM user_token WHERE user_uuid = ?", userId)
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
_ = tx.Rollback()
|
||||
utils.LogError("Could not delete user tokens", err)
|
||||
return types.ErrInternal
|
||||
}
|
||||
|
||||
_, err = tx.Exec("DELETE FROM session WHERE user_uuid = ?", userId)
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
_ = tx.Rollback()
|
||||
utils.LogError("Could not delete sessions", err)
|
||||
return types.ErrInternal
|
||||
}
|
||||
|
||||
_, err = tx.Exec("DELETE FROM user WHERE user_uuid = ?", userId)
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
_ = tx.Rollback()
|
||||
utils.LogError("Could not delete user", err)
|
||||
return types.ErrInternal
|
||||
}
|
||||
@@ -235,15 +234,6 @@ func (db AuthDbSqlite) DeleteUser(userId uuid.UUID) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (db AuthDbSqlite) UpdateUserPassword(userId uuid.UUID, newHash []byte) error {
|
||||
_, err := db.db.Exec("UPDATE user SET password = ? WHERE user_uuid = ?", newHash, userId)
|
||||
if err != nil {
|
||||
utils.LogError("Could not update password", err)
|
||||
return types.ErrInternal
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (db AuthDbSqlite) InsertEmailVerificationToken(userId uuid.UUID, token string) error {
|
||||
_, err := db.db.Exec(`
|
||||
INSERT INTO user_token (user_uuid, type, token, created_at)
|
||||
|
||||
@@ -329,7 +329,10 @@ func (handler HandlerAuthImpl) HandleVerifyResendComp() http.HandlerFunc {
|
||||
|
||||
go handler.service.SendVerificationMail(user.Id, user.Email)
|
||||
|
||||
w.Write([]byte("<p class=\"mt-8\">Verification email sent</p>"))
|
||||
_, err = w.Write([]byte("<p class=\"mt-8\">Verification email sent</p>"))
|
||||
if err != nil {
|
||||
utils.LogError("Could not write response", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -106,7 +106,12 @@ func (handler WorkoutHandlerImpl) handleGetWorkout() http.HandlerFunc {
|
||||
wos = append(wos, workout.Workout{Id: wo.RowId, Date: wo.Date, Type: wo.Type, Sets: wo.Sets, Reps: wo.Reps})
|
||||
}
|
||||
|
||||
workout.WorkoutListComp(wos).Render(r.Context(), w)
|
||||
err = workout.WorkoutListComp(wos).Render(r.Context(), w)
|
||||
if err != nil {
|
||||
utils.LogError("Could not render workoutlist", err)
|
||||
utils.TriggerToast(w, r, "error", "Internal Server Error")
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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{})
|
||||
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user