added a bunch of customer columns
This commit is contained in:
1 parent
f380dfe58d
commit
173c01b01b
8 files changed
+71
-62
No files matched your search
@@ -58,10 +58,10 @@ func ValidatePasswordPlaintext(v *validator.Validator, password string) {
|
||||
func ValidateUserIdentity(v *validator.Validator, userIdentity *UserIdentity) {
|
||||
v.Check(userIdentity.ProviderID == int64(ProviderLocal), "provider_id", "must be 1");
|
||||
|
||||
if userIdentity.ProviderID == int64(ProviderLocal) {
|
||||
v.Check(userIdentity.ProviderUserID != "", "username", "must be provided")
|
||||
v.Check(len(userIdentity.ProviderUserID) <= 500, "username", "must not be more than 500 bytes long")
|
||||
}
|
||||
// if userIdentity.ProviderID == int64(ProviderLocal) {
|
||||
// v.Check(userIdentity.ProviderUserID != "", "username", "must be provided")
|
||||
// v.Check(len(userIdentity.ProviderUserID) <= 500, "username", "must not be more than 500 bytes long")
|
||||
// }
|
||||
|
||||
if userIdentity.Password.plaintext != nil {
|
||||
ValidatePasswordPlaintext(v,
|
||||
|
||||
+41
-47
@@ -18,14 +18,18 @@ var (
|
||||
var AnonymousUser = &User{}
|
||||
|
||||
type User struct {
|
||||
ID int64 `json:"id"`
|
||||
Email string `json:"email"`
|
||||
Name string `json:"name"`
|
||||
AltName sql.NullString `json:"alt_name"`
|
||||
Created time.Time `json:"created"`
|
||||
LastLogin time.Time `json:"last_login"`
|
||||
Activated bool `json:"activated"`
|
||||
Version int32 `json:"-"`
|
||||
ID int64 `json:"id"`
|
||||
Email string `json:"email"`
|
||||
PhoneNumber string `json:"phone_number"`
|
||||
Country string `json:"country"`
|
||||
Name string `json:"name"`
|
||||
AltName sql.NullString `json:"alt_name"`
|
||||
DateOfBirth time.Time `json:"date_of_birth"`
|
||||
Address string `json:"address"`
|
||||
Created time.Time `json:"created"`
|
||||
LastLogin time.Time `json:"last_login"`
|
||||
Activated bool `json:"activated"`
|
||||
Version int32 `json:"-"`
|
||||
}
|
||||
|
||||
func (u *User) IsAnonymous() bool {
|
||||
@@ -56,14 +60,18 @@ func (m UserModel) ExecuteRegistrationTx(user *User, userIdentity *UserIdentity)
|
||||
defer tx.Rollback()
|
||||
|
||||
query := `
|
||||
INSERT INTO users (email, name, alt_name)
|
||||
VALUES ($1, $2, $3)
|
||||
INSERT INTO users (email, phone_number, country, name, alt_name, date_of_birth, address)
|
||||
VALUES ($1, $2, $3, $4, $5, $6, $7)
|
||||
RETURNING id, created, last_login, version`
|
||||
|
||||
args := []interface{}{
|
||||
user.Email,
|
||||
user.PhoneNumber,
|
||||
user.Country,
|
||||
user.Name,
|
||||
user.AltName,
|
||||
user.DateOfBirth,
|
||||
user.Address,
|
||||
}
|
||||
|
||||
err = tx.QueryRowContext(ctx, query, args...).Scan(&user.ID, &user.Created, &user.LastLogin, &user.Version)
|
||||
@@ -113,36 +121,6 @@ RETURNING id, version`
|
||||
return nil
|
||||
}
|
||||
|
||||
// func (m UserModel) Insert(user *User) error {
|
||||
// query := `
|
||||
// INSERT INTO users (email, name, alt_name, activated)
|
||||
// VALUES ($1, $2, $3, $4)
|
||||
// RETURNING id, created, last_login, version`
|
||||
|
||||
// args := []interface{}{
|
||||
// user.Email,
|
||||
// user.Name,
|
||||
// user.AltName,
|
||||
// user.Activated,
|
||||
// }
|
||||
|
||||
// ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
|
||||
// defer cancel()
|
||||
|
||||
// err := m.DB.QueryRowContext(ctx, query, args...).Scan(&user.ID, &user.Created, &user.LastLogin, &user.Version)
|
||||
// if err != nil {
|
||||
// switch {
|
||||
// case err.Error() ==
|
||||
// `pq: duplicate key value violates unique constraint "users_email_key"`:
|
||||
// return ErrDuplicateEmail
|
||||
// default:
|
||||
// return err
|
||||
// }
|
||||
// }
|
||||
|
||||
// return nil
|
||||
// }
|
||||
|
||||
func (m UserModel) Get(id int64) (*User, error) {
|
||||
if id < 1 {
|
||||
return nil, ErrRecordNotFound
|
||||
@@ -150,7 +128,7 @@ func (m UserModel) Get(id int64) (*User, error) {
|
||||
|
||||
// Define the SQL query for retrieving the issue data.
|
||||
query :=`
|
||||
SELECT id, email, name, alt_name, created, last_login, activated, version
|
||||
SELECT id, email, phone_number, country, name, alt_name, date_of_birth, address, created, last_login, activated, version
|
||||
FROM users
|
||||
WHERE id = $1`
|
||||
|
||||
@@ -160,8 +138,12 @@ WHERE id = $1`
|
||||
err := m.DB.QueryRow(query, id).Scan(
|
||||
&user.ID,
|
||||
&user.Email,
|
||||
&user.PhoneNumber,
|
||||
&user.Country,
|
||||
&user.Name,
|
||||
&user.AltName,
|
||||
&user.DateOfBirth,
|
||||
&user.Address,
|
||||
&user.Created,
|
||||
&user.LastLogin,
|
||||
&user.Activated,
|
||||
@@ -181,7 +163,7 @@ WHERE id = $1`
|
||||
|
||||
func (m UserModel) GetByEmail(email string) (*User, error) {
|
||||
query :=`
|
||||
SELECT id, email, name, alt_name, created, last_login, activated, version
|
||||
SELECT id, email, phone, country, name, alt_name, date_of_birth, address, created, last_login, activated, version
|
||||
FROM users
|
||||
WHERE email = $1`
|
||||
|
||||
@@ -192,8 +174,12 @@ WHERE email = $1`
|
||||
err := m.DB.QueryRowContext(ctx, query, email).Scan(
|
||||
&user.ID,
|
||||
&user.Email,
|
||||
&user.PhoneNumber,
|
||||
&user.Country,
|
||||
&user.Name,
|
||||
&user.AltName,
|
||||
&user.DateOfBirth,
|
||||
&user.Address,
|
||||
&user.Created,
|
||||
&user.LastLogin,
|
||||
&user.Activated,
|
||||
@@ -219,7 +205,7 @@ func (m UserModel) GetForToken(tokenScope, tokenPlaintext string) (*User, error)
|
||||
|
||||
// Set up the SQL query.
|
||||
query :=`
|
||||
SELECT users.id, users.created, users.name, users.email, users.activated, users.version
|
||||
SELECT users.id, users.email, user.phone_number, user.country, users.name, users.date_of_birth, users.address, users.created, users.activated, users.version
|
||||
FROM users
|
||||
INNER JOIN tokens ON users.id = tokens.user_id
|
||||
WHERE tokens.hash = $1
|
||||
@@ -239,9 +225,13 @@ AND tokens.expiry > $3`
|
||||
// record is found we return an ErrRecordNotFound error.
|
||||
err := m.DB.QueryRowContext(ctx, query, args...).Scan(
|
||||
&user.ID,
|
||||
&user.Created,
|
||||
&user.Name,
|
||||
&user.Email,
|
||||
&user.PhoneNumber,
|
||||
&user.Country,
|
||||
&user.Name,
|
||||
&user.DateOfBirth,
|
||||
&user.Address,
|
||||
&user.Created,
|
||||
&user.Activated,
|
||||
&user.Version,
|
||||
)
|
||||
@@ -261,15 +251,19 @@ AND tokens.expiry > $3`
|
||||
func (m UserModel) Update(user *User) error {
|
||||
query := `
|
||||
UPDATE users
|
||||
SET email = $1, name = $2, alt_name = $3, activated = $4, version = version + 1
|
||||
WHERE id = $5 AND version = $6
|
||||
SET email = $1, phone_number = $2, country = $3, name = $4, alt_name = $5, date_of_birth = $6, address = $7, activated = $8, version = version + 1
|
||||
WHERE id = $9 AND version = $10
|
||||
RETURNING version`
|
||||
|
||||
// Create an args slice containing the values for the placeholder parameters.
|
||||
args := []interface{}{
|
||||
user.Email,
|
||||
user.PhoneNumber,
|
||||
user.Country,
|
||||
user.Name,
|
||||
user.AltName,
|
||||
user.DateOfBirth,
|
||||
user.Address,
|
||||
user.Activated,
|
||||
user.ID,
|
||||
user.Version,
|
||||
|
||||
Reference in new issue
Block a user