-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #22 from Delavalom/ft/add-verify-emails-workflow
Ft/add verify emails workflow
- Loading branch information
Showing
27 changed files
with
811 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
DROP TABLE IF EXISTS "verify_emails" CASCADE; | ||
|
||
ALTER TABLE "users" DROP COLUMN "is_email_verified"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
CREATE TABLE "verify_emails" ( | ||
"id" bigserial PRIMARY KEY, | ||
"username" varchar NOT NULL, | ||
"email" varchar NOT NULL, | ||
"secret_code" varchar NOT NULL, | ||
"is_used" bool NOT NULL DEFAULT false, | ||
"created_at" timestamptz NOT NULL DEFAULT (now()), | ||
"expired_at" timestamptz NOT NULL DEFAULT (now() + interval '15 minutes') | ||
); | ||
|
||
ALTER TABLE "verify_emails" ADD FOREIGN KEY ("username") REFERENCES "users" ("username"); | ||
|
||
ALTER TABLE "users" ADD COLUMN "is_email_verified" bool NOT NULL DEFAULT false; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
-- name: CreateVerifyEmail :one | ||
INSERT INTO verify_emails ( | ||
username, | ||
email, | ||
secret_code | ||
) VALUES ( | ||
$1, $2, $3 | ||
) RETURNING *; | ||
|
||
-- name: UpdateVerifyEmail :one | ||
UPDATE verify_emails | ||
SET | ||
is_used = TRUE | ||
WHERE | ||
id = @id | ||
AND secret_code = @secret_code | ||
AND is_used = FALSE | ||
AND expired_at > now() | ||
RETURNING *; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package db | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/jackc/pgx/v5/pgtype" | ||
) | ||
|
||
type VerifyEmailTxParams struct { | ||
EmailId int64 | ||
SecretCode string | ||
} | ||
|
||
type VerifyEmailTxResult struct { | ||
User User | ||
VerifyEmail VerifyEmail | ||
} | ||
|
||
func (store *SQLStore) VerifyEmailTx(ctx context.Context, arg VerifyEmailTxParams) (VerifyEmailTxResult, error) { | ||
var result VerifyEmailTxResult | ||
|
||
err := store.execTx(ctx, func(q *Queries) error { | ||
var err error | ||
|
||
result.VerifyEmail, err = q.UpdateVerifyEmail(ctx, UpdateVerifyEmailParams{ | ||
ID: arg.EmailId, | ||
SecretCode: arg.SecretCode, | ||
}) | ||
|
||
if err != nil { | ||
return err | ||
} | ||
|
||
result.User, err = q.UpdateUser(ctx, UpdateUserParams{ | ||
Username: result.VerifyEmail.Username, | ||
IsEmailVerified: pgtype.Bool{ | ||
Bool: true, | ||
Valid: true, | ||
}, | ||
}) | ||
|
||
return err | ||
}) | ||
|
||
return result, err | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.