Compare commits

..

No commits in common. "90cdcd16af2d3741247214f4e123825cc749a996" and "6d12ef9b94627527fca4119dda7f2b96d537ea48" have entirely different histories.

3 changed files with 4 additions and 25 deletions

View File

@ -116,7 +116,7 @@ func (s *AccountServiceDefault) CreateAccount(email string, password string, ver
} }
if verifyEmail { if verifyEmail {
err = s.SendEmailVerification(user.ID) err = s.SendEmailVerification(&user)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -125,12 +125,7 @@ func (s *AccountServiceDefault) CreateAccount(email string, password string, ver
return &user, nil return &user, nil
} }
func (s AccountServiceDefault) SendEmailVerification(userId uint) error { func (s *AccountServiceDefault) SendEmailVerification(user *models.User) error {
exists, user, err := s.AccountExists(userId)
if !exists || err != nil {
return err
}
token := GenerateSecurityToken() token := GenerateSecurityToken()
var verification models.EmailVerification var verification models.EmailVerification
@ -139,7 +134,7 @@ func (s AccountServiceDefault) SendEmailVerification(userId uint) error {
verification.Token = token verification.Token = token
verification.ExpiresAt = time.Now().Add(time.Hour) verification.ExpiresAt = time.Now().Add(time.Hour)
err = s.db.Create(&verification).Error err := s.db.Create(&verification).Error
if err != nil { if err != nil {
return NewAccountError(ErrKeyDatabaseOperationFailed, err) return NewAccountError(ErrKeyDatabaseOperationFailed, err)
} }

View File

@ -169,16 +169,7 @@ func (a AccountAPI) verifyEmail(jc jape.Context) {
if jc.Check("failed to verify email", err) != nil { if jc.Check("failed to verify email", err) != nil {
return return
} }
}
func (a AccountAPI) resendVerifyEmail(jc jape.Context) {
user := middleware.GetUserFromContext(jc.Request.Context())
err := a.accounts.SendEmailVerification(user)
if jc.Check("failed to resend email verification", err) != nil {
return
}
} }
func (a AccountAPI) otpGenerate(jc jape.Context) { func (a AccountAPI) otpGenerate(jc jape.Context) {
@ -451,8 +442,7 @@ func (a *AccountAPI) Routes() (*httprouter.Router, error) {
"POST /api/auth/logout": middleware.ApplyMiddlewares(a.logout, corsMw.Handler, authMw, middleware.ProxyMiddleware), "POST /api/auth/logout": middleware.ApplyMiddlewares(a.logout, corsMw.Handler, authMw, middleware.ProxyMiddleware),
// Account // Account
"POST /api/account/verify-email": middleware.ApplyMiddlewares(a.verifyEmail, corsMw.Handler, authMw, middleware.ProxyMiddleware), "POST /api/account/verify-email": middleware.ApplyMiddlewares(a.verifyEmail, corsMw.Handler, middleware.ProxyMiddleware),
"POST /api/account/verify-email/resend": middleware.ApplyMiddlewares(a.resendVerifyEmail, corsMw.Handler, authMw, middleware.ProxyMiddleware),
"POST /api/account/otp/verify": middleware.ApplyMiddlewares(a.otpVerify, corsMw.Handler, authMw, middleware.ProxyMiddleware), "POST /api/account/otp/verify": middleware.ApplyMiddlewares(a.otpVerify, corsMw.Handler, authMw, middleware.ProxyMiddleware),
"POST /api/account/otp/disable": middleware.ApplyMiddlewares(a.otpDisable, corsMw.Handler, authMw, middleware.ProxyMiddleware), "POST /api/account/otp/disable": middleware.ApplyMiddlewares(a.otpDisable, corsMw.Handler, authMw, middleware.ProxyMiddleware),
"POST /api/account/password-reset/request": middleware.ApplyMiddlewares(a.passwordResetRequest, corsMw.Handler, middleware.ProxyMiddleware), "POST /api/account/password-reset/request": middleware.ApplyMiddlewares(a.passwordResetRequest, corsMw.Handler, middleware.ProxyMiddleware),

View File

@ -54,12 +54,6 @@ paths:
responses: responses:
'200': '200':
description: Email verified successfully description: Email verified successfully
/api/account/verify-email/resend:
post:
summary: Resend email verification
responses:
'200':
description: Email verification resent successfully
/api/auth/otp/generate: /api/auth/otp/generate:
get: get:
summary: Generate OTP for two-factor authentication summary: Generate OTP for two-factor authentication