feat: initialized smtp service;
refactor: config now returns a copy of a struct to prevent editing; chore: corrected identation
This commit is contained in:
@@ -108,5 +108,5 @@ func main() {
|
|||||||
})
|
})
|
||||||
}),
|
}),
|
||||||
|
|
||||||
).Run()
|
).Run()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -153,16 +153,16 @@ func Load() (*Config, error) {
|
|||||||
return &cfg, nil
|
return &cfg, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetConfig() *Config {
|
func GetConfig() Config {
|
||||||
|
|
||||||
if config == nil {
|
if config == nil {
|
||||||
|
|
||||||
if _, err := Load(); err != nil {
|
if _, err := Load(); err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return config
|
return *config
|
||||||
}
|
}
|
||||||
|
|
||||||
var config *Config
|
var config *Config
|
||||||
|
|||||||
@@ -146,7 +146,7 @@ func (a *authControllerImpl) RegistrationBegin(c *gin.Context) {
|
|||||||
// @Router /auth/registrationComplete [post]
|
// @Router /auth/registrationComplete [post]
|
||||||
func (a *authControllerImpl) RegistrationComplete(c *gin.Context) {
|
func (a *authControllerImpl) RegistrationComplete(c *gin.Context) {
|
||||||
request, ok := utils.GetRequest[models.RegistrationCompleteRequest](c)
|
request, ok := utils.GetRequest[models.RegistrationCompleteRequest](c)
|
||||||
if !ok {
|
if !ok {
|
||||||
c.Status(http.StatusBadRequest)
|
c.Status(http.StatusBadRequest)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -168,10 +168,10 @@ func (a *authControllerImpl) RegistrationComplete(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (a *authControllerImpl) RegisterRoutes(group *gin.RouterGroup) {
|
func (a *authControllerImpl) RegisterRoutes(group *gin.RouterGroup) {
|
||||||
group.POST("/registrationBegin", middleware.RequestMiddleware[models.RegistrationBeginRequest](enums.GuestRole), a.RegistrationBegin)
|
group.POST("/registrationBegin", middleware.RequestMiddleware[models.RegistrationBeginRequest](enums.GuestRole), a.RegistrationBegin)
|
||||||
group.POST("/registrationComplete", middleware.RequestMiddleware[models.RegistrationCompleteRequest](enums.GuestRole), a.RegistrationComplete)
|
group.POST("/registrationComplete", middleware.RequestMiddleware[models.RegistrationCompleteRequest](enums.GuestRole), a.RegistrationComplete)
|
||||||
group.POST("/login", middleware.RequestMiddleware[models.LoginRequest](enums.GuestRole), a.Login)
|
group.POST("/login", middleware.RequestMiddleware[models.LoginRequest](enums.GuestRole), a.Login)
|
||||||
group.POST("/refresh", middleware.RequestMiddleware[models.RegistrationBeginRequest](enums.UserRole), a.Refresh)
|
group.POST("/refresh", middleware.RequestMiddleware[models.RegistrationBeginRequest](enums.UserRole), a.Refresh)
|
||||||
group.POST("/passwordResetBegin", middleware.RequestMiddleware[models.RegistrationBeginRequest](enums.GuestRole), a.PasswordResetBegin)
|
group.POST("/passwordResetBegin", middleware.RequestMiddleware[models.RegistrationBeginRequest](enums.GuestRole), a.PasswordResetBegin)
|
||||||
group.POST("/passwordResetComplete", middleware.RequestMiddleware[models.RegistrationBeginRequest](enums.GuestRole), a.PasswordResetComplete)
|
group.POST("/passwordResetComplete", middleware.RequestMiddleware[models.RegistrationBeginRequest](enums.GuestRole), a.PasswordResetComplete)
|
||||||
}
|
}
|
||||||
|
|||||||
10
backend/internal/errors/smtp.go
Normal file
10
backend/internal/errors/smtp.go
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
package errors
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
ErrSmtpDisabled = errors.New("Smtp is not enabled in the config")
|
||||||
|
ErrSmtpSendFailure = errors.New("Failed to send email")
|
||||||
|
)
|
||||||
@@ -46,15 +46,15 @@ func UserInfoFromContext(c *gin.Context) (*UserInfo, bool) {
|
|||||||
var ok bool
|
var ok bool
|
||||||
|
|
||||||
username, ok = c.Get("username") ; if !ok {
|
username, ok = c.Get("username") ; if !ok {
|
||||||
return &UserInfo{Username: "", Role: enums.GuestRole}, true
|
return &UserInfo{Username: "", Role: enums.GuestRole}, true
|
||||||
}
|
}
|
||||||
|
|
||||||
role, ok = c.Get("role"); if !ok {
|
role, ok = c.Get("role"); if !ok {
|
||||||
return nil, false
|
return nil, false
|
||||||
}
|
}
|
||||||
|
|
||||||
if username == nil {
|
if username == nil {
|
||||||
return &UserInfo{Username: "", Role: enums.GuestRole}, true
|
return &UserInfo{Username: "", Role: enums.GuestRole}, true
|
||||||
}
|
}
|
||||||
|
|
||||||
if role == nil {
|
if role == nil {
|
||||||
@@ -103,7 +103,7 @@ func RequestMiddleware[T any](role enums.Role) gin.HandlerFunc {
|
|||||||
User: *userInfo,
|
User: *userInfo,
|
||||||
Body: body,
|
Body: body,
|
||||||
}
|
}
|
||||||
|
|
||||||
c.Set(requestKey, request)
|
c.Set(requestKey, request)
|
||||||
c.Next()
|
c.Next()
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -16,3 +16,22 @@
|
|||||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
package services
|
package services
|
||||||
|
|
||||||
|
import "go.uber.org/zap"
|
||||||
|
|
||||||
|
type SmtpService interface {
|
||||||
|
SendEmail(to string, content string)
|
||||||
|
}
|
||||||
|
|
||||||
|
type smtpServiceImpl struct {
|
||||||
|
log *zap.Logger
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewSmtpService(_log *zap.Logger) SmtpService {
|
||||||
|
return &smtpServiceImpl{log: _log}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *smtpServiceImpl) SendEmail(to string, content string) {
|
||||||
|
panic("unimplemented")
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user