Skip to content

Commit

Permalink
Added check for if the email is actually a valid email
Browse files Browse the repository at this point in the history
  • Loading branch information
justinfarrelldev committed Aug 29, 2024
1 parent fe5fbb2 commit 7c78557
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion internal/account/create_account.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"fmt"
"log"
"net/http"
"net/mail"

"encoding/hex"

Expand Down Expand Up @@ -37,10 +38,15 @@ const ERROR_PASSWORD_TOO_SHORT = "password must be longer than 6 characters"
const ERROR_PASSWORD_REQUIRED_BUT_NO_PASSWORD = "password is required"

func isEmailValid(email string, db *sql.DB) (bool, error) {
_, err := mail.ParseAddress(email)
if err != nil {
return false, errors.New("an error occurred while checking whether the email for the account is valid: " + err.Error())
}

result, err := db.Query("SELECT * from account WHERE email = $1", email)

if err != nil {
return false, errors.New("an error occurred while checking whether the email for the account is unique:" + err.Error())
return false, errors.New("an error occurred while checking whether the email for the account is unique: " + err.Error())
}

defer result.Close()
Expand Down

0 comments on commit 7c78557

Please sign in to comment.