Skip to content

Commit

Permalink
Add post-email verification view (#298)
Browse files Browse the repository at this point in the history
  • Loading branch information
juancwu authored Dec 28, 2024
2 parents f4623d1 + 025f99c commit 436829a
Show file tree
Hide file tree
Showing 6 changed files with 712 additions and 28 deletions.
2 changes: 2 additions & 0 deletions backend/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ require (
)

require (
github.com/PuerkitoBio/goquery v1.10.1 // indirect
github.com/andybalholm/cascadia v1.3.3 // indirect
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.6.7 // indirect
github.com/aws/aws-sdk-go-v2/credentials v1.17.47 // indirect
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.21 // indirect
Expand Down
62 changes: 62 additions & 0 deletions backend/go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
github.com/PuerkitoBio/goquery v1.10.1 h1:Y8JGYUkXWTGRB6Ars3+j3kN0xg1YqqlwvdTV8WTFQcU=
github.com/PuerkitoBio/goquery v1.10.1/go.mod h1:IYiHrOMps66ag56LEH7QYDDupKXyo5A8qrjIx3ZtujY=
github.com/a-h/templ v0.2.793 h1:Io+/ocnfGWYO4VHdR0zBbf39PQlnzVCVVD+wEEs6/qY=
github.com/a-h/templ v0.2.793/go.mod h1:lq48JXoUvuQrU0VThrK31yFwdRjTCnIE5bcPCM9IP1w=
github.com/andybalholm/cascadia v1.3.3 h1:AG2YHrzJIm4BZ19iwJ/DAua6Btl3IwJX+VI4kktS1LM=
github.com/andybalholm/cascadia v1.3.3/go.mod h1:xNd9bqTn98Ln4DwST8/nG+H0yuB8Hmgu1YHNnWw0GeA=
github.com/aws/aws-sdk-go-v2 v1.32.6 h1:7BokKRgRPuGmKkFMhEg/jSul+tB9VvXhcViILtfG8b4=
github.com/aws/aws-sdk-go-v2 v1.32.6/go.mod h1:P5WJBrYqqbWVaOxgH0X/FYYD47/nooaPOZPlQdmiN2U=
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.6.7 h1:lL7IfaFzngfx0ZwUGOZdsFFnQ5uLvR0hWqqhyE7Q9M8=
Expand Down Expand Up @@ -105,23 +109,81 @@ github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6Kllzaw
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
github.com/valyala/fasttemplate v1.2.2 h1:lxLXG0uE3Qnshl9QyaK6XJxMXlQZELvChBOCmQD0Loo=
github.com/valyala/fasttemplate v1.2.2/go.mod h1:KHLXt3tVN2HBp8eijSv/kGJopbvo7S+qRAEEKiv+SiQ=
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/crypto v0.13.0/go.mod h1:y6Z2r+Rw4iayiXXAIxJIDAJ1zMW4yaTpebo8fPOliYc=
golang.org/x/crypto v0.19.0/go.mod h1:Iy9bg/ha4yyC70EfRS8jz+B6ybOBKMaSxLj6P6oBDfU=
golang.org/x/crypto v0.23.0/go.mod h1:CKFgDieR+mRhux2Lsu27y0fO304Db0wZe70UKqHu0v8=
golang.org/x/crypto v0.31.0 h1:ihbySMvVjLAeSH1IbfcRTkD/iNscyz8rGzjF/E5hV6U=
golang.org/x/crypto v0.31.0/go.mod h1:kDsLvtWBEx7MV9tJOj9bnXsPbxwJQ6csT/x4KIN4Ssk=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/mod v0.12.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/mod v0.15.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
golang.org/x/mod v0.17.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg=
golang.org/x/net v0.15.0/go.mod h1:idbUs1IY1+zTqbi8yxTbhexhEEk5ur9LInksu6HrEpk=
golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44=
golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM=
golang.org/x/net v0.28.0 h1:a9JDOJc5GMUJ0+UDqmLT86WiEy7iWyIhz8gz8E4e5hE=
golang.org/x/net v0.28.0/go.mod h1:yqtgsTWOOnlGLG9GFRrK3++bGOUEkNBoHZc8MEDWPNg=
golang.org/x/net v0.33.0 h1:74SYHlV8BIgHIFC/LrYkOGIwL19eTYXQ5wc6TBuO36I=
golang.org/x/net v0.33.0/go.mod h1:HXLR5J+9DxmrqMwG9qjGCxZ+zKXxBru04zlTvWlWuN4=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.3.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y=
golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sync v0.10.0 h1:3NQrjDixjgGwUOCaF8w2+VYHv0Ve/vGYSbdkTa98gmQ=
golang.org/x/sync v0.10.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.28.0 h1:Fksou7UEQUWlKvIdsqzJmUmCX3cZuD2+P3XyyzwMhlA=
golang.org/x/sys v0.28.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/telemetry v0.0.0-20240228155512-f48c80bd79b2/go.mod h1:TeRTkGYfJXctD9OcfyVLyj2J3IxLnKwHJR8f4D8a3YE=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
golang.org/x/term v0.8.0/go.mod h1:xPskH00ivmX89bAKVGSKKtLOWNx2+17Eiy94tnKShWo=
golang.org/x/term v0.12.0/go.mod h1:owVbMEjm3cBLCHdkQu9b1opXd4ETQWc3BhuQGKgXgvU=
golang.org/x/term v0.17.0/go.mod h1:lLRBjIVuehSbZlaOtGMbcMncT+aqLLLmKrsjNrUguwk=
golang.org/x/term v0.20.0/go.mod h1:8UkIAJTvZgivsXaD6/pH6U9ecQzZ45awqEOzuCvwpFY=
golang.org/x/term v0.27.0/go.mod h1:iMsnZpn0cago0GOrHO2+Y7u7JPn5AylBrcoWkElMTSM=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
golang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
golang.org/x/text v0.21.0 h1:zyQAAkrwaneQ066sspRyJaG9VNi/YJ1NfzcGB3hZ/qo=
golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ=
golang.org/x/time v0.5.0 h1:o7cqy6amK/52YcAKIPlM3a+Fpj35zvRj2TP+e1xFSfk=
golang.org/x/time v0.5.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
golang.org/x/tools v0.13.0/go.mod h1:HvlwmtVNQAhOuCjW7xxvovg8wbNq7LwfXh/k7wXUl58=
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d/go.mod h1:aiJjzUbINMkxbQROHiO6hDPo2LHcIPhhQsa9DLh0yGk=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
Expand Down
54 changes: 34 additions & 20 deletions backend/internal/tests/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"KonferCA/SPUR/internal/jwt"
"KonferCA/SPUR/internal/server"
"KonferCA/SPUR/internal/v1/v1_auth"
"KonferCA/SPUR/internal/v1/v1_common"

"bytes"
"context"
Expand All @@ -18,6 +17,7 @@ import (
"testing"
"time"

"github.com/PuerkitoBio/goquery"
golangJWT "github.com/golang-jwt/jwt/v5"
"github.com/google/uuid"
"github.com/labstack/echo/v4"
Expand Down Expand Up @@ -400,30 +400,39 @@ func TestServer(t *testing.T) {
s.Echo.ServeHTTP(rec, req)
assert.Equal(t, http.StatusOK, rec.Code)

resBodyBytes, err := io.ReadAll(rec.Body)
assert.Nil(t, err)

var resBody map[string]any
err = json.Unmarshal(resBodyBytes, &resBody)
assert.Nil(t, err)
assert.Equal(t, resBody["verified"], true)
doc, err := goquery.NewDocumentFromReader(rec.Body)
assert.NoError(t, err)
title := doc.Find(`[data-testid="card-title"]`).Text()
assert.Equal(t, title, "Email Verified Successfully")
details := doc.Find(`[data-testid="card-details"]`).Text()
assert.Contains(t, details, "Thank you for verifying your email address")
icon := doc.Find(`[data-testid="check-icon"]`)
assert.Equal(t, 1, icon.Length())
button := doc.Find(`[data-testid="go-to-dashboard"]`)
assert.Equal(t, 1, button.Length())
})

t.Run("/auth/verify-email - 400 Bad Request - missing token query parameter", func(t *testing.T) {
t.Run("/auth/verify-email - missing token query parameter", func(t *testing.T) {
req := httptest.NewRequest(http.MethodGet, "/api/v1/auth/verify-email", nil)
rec := httptest.NewRecorder()

s.Echo.ServeHTTP(rec, req)

var apiErr v1_common.APIError
err := json.NewDecoder(rec.Body).Decode(&apiErr)
assert.Equal(t, http.StatusOK, rec.Code)

doc, err := goquery.NewDocumentFromReader(rec.Body)
assert.NoError(t, err)
assert.Equal(t, http.StatusBadRequest, rec.Code)
assert.Equal(t, v1_common.ErrorTypeBadRequest, apiErr.Type)
assert.Equal(t, "Missing required query parameter: 'token'", apiErr.Message)
title := doc.Find(`[data-testid="card-title"]`).Text()
assert.Equal(t, title, "Failed to Verify Email")
details := doc.Find(`[data-testid="card-details"]`).Text()
assert.Contains(t, details, "Missing validation token")
icon := doc.Find(`[data-testid="x-icon"]`)
assert.Equal(t, 1, icon.Length())
button := doc.Find(`[data-testid="go-to-dashboard"]`)
assert.Equal(t, 1, button.Length())
})

t.Run("/auth/verify-email - 400 Bad Request - deny expired email token", func(t *testing.T) {
t.Run("/auth/verify-email - deny expired email token", func(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), time.Second*30)
defer cancel()
userID, email, _, err := createTestUser(ctx, s)
Expand All @@ -440,13 +449,18 @@ func TestServer(t *testing.T) {
rec := httptest.NewRecorder()

s.Echo.ServeHTTP(rec, req)
assert.Equal(t, http.StatusOK, rec.Code)

var apiErr v1_common.APIError
err = json.NewDecoder(rec.Body).Decode(&apiErr)
doc, err := goquery.NewDocumentFromReader(rec.Body)
assert.NoError(t, err)
assert.Equal(t, http.StatusBadRequest, rec.Code)
assert.Equal(t, v1_common.ErrorTypeBadRequest, apiErr.Type)
assert.Equal(t, "Failed to verify email. Invalid or expired token.", apiErr.Message)
title := doc.Find(`[data-testid="card-title"]`).Text()
assert.Equal(t, title, "Failed to Verify Email")
details := doc.Find(`[data-testid="card-details"]`).Text()
assert.Contains(t, details, "The verification link is invalid or expired")
icon := doc.Find(`[data-testid="x-icon"]`)
assert.Equal(t, 1, icon.Length())
button := doc.Find(`[data-testid="go-to-dashboard"]`)
assert.Equal(t, 1, button.Length())
})

t.Run("/api/v1/auth/logout - 200 OK - successfully logout", func(t *testing.T) {
Expand Down
58 changes: 50 additions & 8 deletions backend/internal/v1/v1_auth/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ import (
"KonferCA/SPUR/internal/middleware"
"KonferCA/SPUR/internal/service"
"KonferCA/SPUR/internal/v1/v1_common"
"KonferCA/SPUR/internal/views"
"context"
"errors"
"fmt"
"net/http"
"os"
"time"

"github.com/labstack/echo/v4"
Expand Down Expand Up @@ -215,52 +217,92 @@ func (h *Handler) handleVerifyEmail(c echo.Context) error {
ctx, cancel := context.WithTimeout(c.Request().Context(), time.Minute)
defer cancel()

viewUrl := fmt.Sprintf("%s/dashboard", os.Getenv("BACKEND_URL"))

tokenStr := c.QueryParam("token")
if tokenStr == "" {
return v1_common.Fail(c, http.StatusBadRequest, "Missing required query parameter: 'token'", nil)
view := views.VerifyEmailPage(views.FailVerifyEmailPage, viewUrl, "Missing validation token. Please get a new link from the dashboard.")
if err := view.Render(c.Request().Context(), c.Response()); err != nil {
return v1_common.Fail(c, http.StatusBadRequest, "Failed to render verify email page", err)
}
return nil
}

claims, err := jwt.VerifyEmailToken(tokenStr)
if err != nil {
return v1_common.Fail(c, http.StatusBadRequest, "Failed to verify email. Invalid or expired token.", err)
logger.Error(err, "Failed to verify email token")
view := views.VerifyEmailPage(views.FailVerifyEmailPage, viewUrl, "The verification link is invalid or expired. You can get a new link in the dashboard.")
if err := view.Render(c.Request().Context(), c.Response()); err != nil {
return v1_common.Fail(c, http.StatusBadRequest, "Failed to render verify email page", err)
}
return nil
}

token, err := db.New(h.server.GetDB()).GetVerifyEmailTokenByID(ctx, claims.ID)
if err != nil {
return v1_common.Fail(c, http.StatusInternalServerError, "Failed to verify email.", err)
logger.Error(err, "Failed to get email token from the database.")
view := views.VerifyEmailPage(views.InternalErrorEmailPage, viewUrl, "")
if err := view.Render(c.Request().Context(), c.Response()); err != nil {
return v1_common.Fail(c, http.StatusBadRequest, "Failed to render verify email page", err)
}
return nil
}

// start transaction to make sure that both user email verified status and the email token are deleted
tx, err := h.server.GetDB().Begin(ctx)
if err != nil {
return v1_common.Fail(c, http.StatusInternalServerError, "Failed to verify email.", err)
logger.Error(err, "Failed to start transaction to update user and remove email token from database.")
view := views.VerifyEmailPage(views.InternalErrorEmailPage, viewUrl, "")
if err := view.Render(c.Request().Context(), c.Response()); err != nil {
return v1_common.Fail(c, http.StatusBadRequest, "Failed to render verify email page", err)
}
return nil
}
q := db.New(h.server.GetDB()).WithTx(tx)
err = q.UpdateUserEmailVerifiedStatus(ctx, db.UpdateUserEmailVerifiedStatusParams{EmailVerified: true, ID: token.UserID})
if err != nil {
logger.Error(err, "Failed to update user in database.")
if err := tx.Rollback(ctx); err != nil {
logger.Error(err, "Failed to rollback")
}
return v1_common.Fail(c, http.StatusInternalServerError, "Failed to verify email.", err)
view := views.VerifyEmailPage(views.InternalErrorEmailPage, viewUrl, "")
if err := view.Render(c.Request().Context(), c.Response()); err != nil {
return v1_common.Fail(c, http.StatusBadRequest, "Failed to render verify email page", err)
}
return nil
}

err = q.RemoveVerifyEmailTokenByID(ctx, token.ID)
if err != nil {
logger.Error(err, "Failed to remove email token from database.")
if err := tx.Rollback(ctx); err != nil {
logger.Error(err, "Failed to rollback")
}
return v1_common.Fail(c, http.StatusInternalServerError, "Failed to verify email.", err)
view := views.VerifyEmailPage(views.InternalErrorEmailPage, viewUrl, "")
if err := view.Render(c.Request().Context(), c.Response()); err != nil {
return v1_common.Fail(c, http.StatusBadRequest, "Failed to render verify email page", err)
}
return nil
}

err = tx.Commit(ctx)
if err != nil {
logger.Error(err, "Failed to commit changes.")
if err := tx.Rollback(ctx); err != nil {
logger.Error(err, "Failed to rollback")
}
return v1_common.Fail(c, http.StatusInternalServerError, "Failed to verify email.", err)
view := views.VerifyEmailPage(views.InternalErrorEmailPage, viewUrl, "")
if err := view.Render(c.Request().Context(), c.Response()); err != nil {
return v1_common.Fail(c, http.StatusBadRequest, "Failed to render verify email page", err)
}
return nil
}

return c.JSON(http.StatusOK, EmailVerifiedStatusResponse{Verified: true})
view := views.VerifyEmailPage(views.SuccessVerifyEmailPage, viewUrl, "")
if err := view.Render(c.Request().Context(), c.Response()); err != nil {
return v1_common.Fail(c, http.StatusBadRequest, "Failed to render verify email page", err)
}
return nil
}

/*
Expand Down
Loading

0 comments on commit 436829a

Please sign in to comment.