2
pkg/coredata/migrations/20250311T145900Z.sql
Normal file
2
pkg/coredata/migrations/20250311T145900Z.sql
Normal file
@@ -0,0 +1,2 @@
|
||||
ALTER TABLE users ADD COLUMN email_address_verified BOOLEAN NOT NULL DEFAULT FALSE;
|
||||
ALTER TABLE users ALTER COLUMN email_address_verified DROP DEFAULT;
|
||||
@@ -70,6 +70,7 @@ SELECT
|
||||
id,
|
||||
email_address,
|
||||
hashed_password,
|
||||
email_address_verified,
|
||||
fullname,
|
||||
created_at,
|
||||
updated_at
|
||||
@@ -111,6 +112,7 @@ SELECT
|
||||
id,
|
||||
email_address,
|
||||
hashed_password,
|
||||
email_address_verified,
|
||||
fullname,
|
||||
created_at,
|
||||
updated_at
|
||||
@@ -148,11 +150,12 @@ func (u *User) Insert(
|
||||
) error {
|
||||
q := `
|
||||
INSERT INTO
|
||||
users (id, email_address, hashed_password, fullname, created_at, updated_at)
|
||||
users (id, email_address, hashed_password, email_address_verified, fullname, created_at, updated_at)
|
||||
VALUES (
|
||||
@user_id,
|
||||
@email_address,
|
||||
@hashed_password,
|
||||
@email_address_verified,
|
||||
@fullname,
|
||||
@created_at,
|
||||
@updated_at
|
||||
@@ -160,12 +163,13 @@ VALUES (
|
||||
`
|
||||
|
||||
args := pgx.StrictNamedArgs{
|
||||
"user_id": u.ID,
|
||||
"email_address": u.EmailAddress,
|
||||
"hashed_password": u.HashedPassword,
|
||||
"fullname": u.FullName,
|
||||
"created_at": u.CreatedAt,
|
||||
"updated_at": u.UpdatedAt,
|
||||
"user_id": u.ID,
|
||||
"email_address": u.EmailAddress,
|
||||
"hashed_password": u.HashedPassword,
|
||||
"fullname": u.FullName,
|
||||
"created_at": u.CreatedAt,
|
||||
"updated_at": u.UpdatedAt,
|
||||
"email_address_verified": u.EmailAddressVerified,
|
||||
}
|
||||
|
||||
_, err := conn.Exec(ctx, q, args)
|
||||
@@ -185,3 +189,35 @@ VALUES (
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (u *User) UpdateEmailVerification(
|
||||
ctx context.Context,
|
||||
conn pg.Conn,
|
||||
verified bool,
|
||||
) error {
|
||||
q := `
|
||||
UPDATE
|
||||
users
|
||||
SET
|
||||
email_address_verified = @email_address_verified,
|
||||
updated_at = @updated_at
|
||||
WHERE
|
||||
id = @user_id
|
||||
`
|
||||
|
||||
args := pgx.StrictNamedArgs{
|
||||
"user_id": u.ID,
|
||||
"email_address_verified": verified,
|
||||
"updated_at": time.Now(),
|
||||
}
|
||||
|
||||
_, err := conn.Exec(ctx, q, args)
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot update user email verification: %w", err)
|
||||
}
|
||||
|
||||
u.EmailAddressVerified = verified
|
||||
u.UpdatedAt = args["updated_at"].(time.Time)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user