rf/disables verify_email sender in development

This commit is contained in:
itsscb 2023-10-23 23:11:03 +02:00
parent 80f97ac3a0
commit c996d83334
5 changed files with 83 additions and 69 deletions

View File

@ -3,40 +3,40 @@ package db
import (
"context"
"database/sql"
"github.com/google/uuid"
)
type UpdateAccountInfoTxParams struct {
AccountID uint64 `json:"account_id"`
Changer string `json:"changer"`
Firstname sql.NullString `json:"firstname"`
Lastname sql.NullString `json:"lastname"`
Birthday sql.NullTime `json:"birthday"`
Phone sql.NullString `json:"phone"`
City sql.NullString `json:"city"`
Zip sql.NullString `json:"zip"`
Street sql.NullString `json:"street"`
Country sql.NullString `json:"country"`
type UpdateAccountTxParams struct {
UpdateAccountParams
AfterUpdate func(Account) error
}
type UpdateAccountInfoTxResult struct {
AccountInfo AccountInfo `json:"account_info"`
type UpdateAccountTxResult struct {
Account Account `json:"account"`
}
func (store *SQLStore) UpdateAccountInfoTx(ctx context.Context, arg UpdateAccountInfoTxParams) (AccountInfo, error) {
var result UpdateAccountInfoTxResult
func (store *SQLStore) UpdateAccountTx(ctx context.Context, arg UpdateAccountTxParams) (Account, error) {
var result UpdateAccountTxResult
var err error
// if arg.Passwordhash.Valid {
// arg.Passwordhash.String, err = util.HashPassword(arg.Passwordhash.String)
// if err != nil {
// return Account{}, nil
// }
// }
uid, _ := uuid.NewUUID()
err := store.execTx(ctx, func(q *Queries) error {
arg.SecretKey = sql.NullString{
Valid: uid.String() != "",
String: uid.String(),
}
err = store.execTx(ctx, func(q *Queries) error {
var err error
result.AccountInfo, err = q.UpdateAccountInfo(ctx, UpdateAccountInfoParams(arg))
return err
result.Account, err = q.UpdateAccount(ctx, arg.UpdateAccountParams)
if err != nil {
return err
}
return arg.AfterUpdate(result.Account)
})
return result.AccountInfo, err
return result.Account, err
}

View File

@ -0,0 +1,42 @@
package db
import (
"context"
"database/sql"
)
type UpdateAccountInfoTxParams struct {
AccountID uint64 `json:"account_id"`
Changer string `json:"changer"`
Firstname sql.NullString `json:"firstname"`
Lastname sql.NullString `json:"lastname"`
Birthday sql.NullTime `json:"birthday"`
Phone sql.NullString `json:"phone"`
City sql.NullString `json:"city"`
Zip sql.NullString `json:"zip"`
Street sql.NullString `json:"street"`
Country sql.NullString `json:"country"`
}
type UpdateAccountInfoTxResult struct {
AccountInfo AccountInfo `json:"account_info"`
}
func (store *SQLStore) UpdateAccountInfoTx(ctx context.Context, arg UpdateAccountInfoTxParams) (AccountInfo, error) {
var result UpdateAccountInfoTxResult
// if arg.Passwordhash.Valid {
// arg.Passwordhash.String, err = util.HashPassword(arg.Passwordhash.String)
// if err != nil {
// return Account{}, nil
// }
// }
err := store.execTx(ctx, func(q *Queries) error {
var err error
result.AccountInfo, err = q.UpdateAccountInfo(ctx, UpdateAccountInfoParams(arg))
return err
})
return result.AccountInfo, err
}

View File

@ -1,42 +0,0 @@
package db
import (
"context"
"database/sql"
"github.com/google/uuid"
)
type UpdateAccountTxParams struct {
UpdateAccountParams
AfterUpdate func(Account) error
}
type UpdateAccountTxResult struct {
Account Account `json:"account"`
}
func (store *SQLStore) UpdateAccountTx(ctx context.Context, arg UpdateAccountTxParams) (Account, error) {
var result UpdateAccountTxResult
var err error
uid, _ := uuid.NewUUID()
arg.SecretKey = sql.NullString{
Valid: uid.String() != "",
String: uid.String(),
}
err = store.execTx(ctx, func(q *Queries) error {
var err error
result.Account, err = q.UpdateAccount(ctx, arg.UpdateAccountParams)
if err != nil {
return err
}
return arg.AfterUpdate(result.Account)
})
return result.Account, err
}

View File

@ -36,6 +36,13 @@ func (server *Server) CreateAccount(ctx context.Context, req *pb.CreateAccountRe
},
}
if server.config.Environment == "development" {
arg.AfterCreate = func(a db.Account) error {
slog.Info("create_account (verify_account)", slog.String("secret_key", a.SecretKey.String))
return nil
}
}
account, err := server.store.CreateAccountTx(ctx, arg)
if err != nil {
slog.Error("create_account (db)", slog.String("invoked_by", req.GetEmail()), slog.String("error", err.Error()))

View File

@ -62,8 +62,15 @@ func (server *Server) UpdateAccount(ctx context.Context, req *pb.UpdateAccountRe
}
if req.Email != nil {
arg.AfterUpdate = func(a db.Account) error {
return server.mailSender.SendEmail("Verify your E-Mail Address", fmt.Sprintf("Hello %s,</br></br>please verify your E-Mail Addres by clicking on the following link:</br><a href=\"http://localhost:8080/v1/verify_email/%d/%s\">Verification Link</a></br></br></br>Your Team of DF", req.GetEmail(), a.ID, a.SecretKey.String), []string{req.GetEmail()}, nil, nil, nil)
if server.config.Environment == "development" {
arg.AfterUpdate = func(a db.Account) error {
slog.Info("update_account (verify_account)", slog.String("secret_key", a.SecretKey.String))
return nil
}
} else {
arg.AfterUpdate = func(a db.Account) error {
return server.mailSender.SendEmail("Verify your E-Mail Address", fmt.Sprintf("Hello %s,</br></br>please verify your E-Mail Addres by clicking on the following link:</br><a href=\"http://localhost:8080/v1/verify_email/%d/%s\">Verification Link</a></br></br></br>Your Team of DF", req.GetEmail(), a.ID, a.SecretKey.String), []string{req.GetEmail()}, nil, nil, nil)
}
}
}