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,7 +153,7 @@ func Load() (*Config, error) {
|
||||
return &cfg, nil
|
||||
}
|
||||
|
||||
func GetConfig() *Config {
|
||||
func GetConfig() Config {
|
||||
|
||||
if config == nil {
|
||||
|
||||
@@ -162,7 +162,7 @@ func GetConfig() *Config {
|
||||
}
|
||||
}
|
||||
|
||||
return config
|
||||
return *config
|
||||
}
|
||||
|
||||
var config *Config
|
||||
|
||||
@@ -146,7 +146,7 @@ func (a *authControllerImpl) RegistrationBegin(c *gin.Context) {
|
||||
// @Router /auth/registrationComplete [post]
|
||||
func (a *authControllerImpl) RegistrationComplete(c *gin.Context) {
|
||||
request, ok := utils.GetRequest[models.RegistrationCompleteRequest](c)
|
||||
if !ok {
|
||||
if !ok {
|
||||
c.Status(http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
@@ -168,10 +168,10 @@ func (a *authControllerImpl) RegistrationComplete(c *gin.Context) {
|
||||
}
|
||||
|
||||
func (a *authControllerImpl) RegisterRoutes(group *gin.RouterGroup) {
|
||||
group.POST("/registrationBegin", middleware.RequestMiddleware[models.RegistrationBeginRequest](enums.GuestRole), a.RegistrationBegin)
|
||||
group.POST("/registrationComplete", middleware.RequestMiddleware[models.RegistrationCompleteRequest](enums.GuestRole), a.RegistrationComplete)
|
||||
group.POST("/login", middleware.RequestMiddleware[models.LoginRequest](enums.GuestRole), a.Login)
|
||||
group.POST("/refresh", middleware.RequestMiddleware[models.RegistrationBeginRequest](enums.UserRole), a.Refresh)
|
||||
group.POST("/passwordResetBegin", middleware.RequestMiddleware[models.RegistrationBeginRequest](enums.GuestRole), a.PasswordResetBegin)
|
||||
group.POST("/passwordResetComplete", middleware.RequestMiddleware[models.RegistrationBeginRequest](enums.GuestRole), a.PasswordResetComplete)
|
||||
group.POST("/registrationBegin", middleware.RequestMiddleware[models.RegistrationBeginRequest](enums.GuestRole), a.RegistrationBegin)
|
||||
group.POST("/registrationComplete", middleware.RequestMiddleware[models.RegistrationCompleteRequest](enums.GuestRole), a.RegistrationComplete)
|
||||
group.POST("/login", middleware.RequestMiddleware[models.LoginRequest](enums.GuestRole), a.Login)
|
||||
group.POST("/refresh", middleware.RequestMiddleware[models.RegistrationBeginRequest](enums.UserRole), a.Refresh)
|
||||
group.POST("/passwordResetBegin", middleware.RequestMiddleware[models.RegistrationBeginRequest](enums.GuestRole), a.PasswordResetBegin)
|
||||
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
|
||||
|
||||
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 {
|
||||
return nil, false
|
||||
return nil, false
|
||||
}
|
||||
|
||||
if username == nil {
|
||||
return &UserInfo{Username: "", Role: enums.GuestRole}, true
|
||||
return &UserInfo{Username: "", Role: enums.GuestRole}, true
|
||||
}
|
||||
|
||||
if role == nil {
|
||||
|
||||
@@ -16,3 +16,22 @@
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
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