implement Email as username
This commit is contained in:
@@ -27,7 +27,7 @@ func (db *InMemoryDb) GetCustomer(id CustomerId) (*Customer, error) {
|
||||
return &customer, nil
|
||||
}
|
||||
|
||||
func (db *InMemoryDb) GetUser(username Username, customerId CustomerId) (*User, error) {
|
||||
func (db *InMemoryDb) GetUser(username Email, customerId CustomerId) (*User, error) {
|
||||
key := userIdKey(customerId, username)
|
||||
userId, exists := db.userIdMap[key]
|
||||
if !exists {
|
||||
@@ -53,14 +53,14 @@ func (db *InMemoryDb) WriteNewCustomer(customer Customer) error {
|
||||
func (db *InMemoryDb) WriteNewUser(user User) error {
|
||||
_, exists := db.Customers[user.CustomerId]
|
||||
if !exists {
|
||||
return errors.New(fmt.Sprintf("can't add user %s to customer %s: customer dne", user.Username, user.CustomerId))
|
||||
return errors.New(fmt.Sprintf("can't add user %s to customer %s: customer dne", user.Email, user.CustomerId))
|
||||
}
|
||||
userExists, _ := db.GetUser(user.Username, user.CustomerId)
|
||||
userExists, _ := db.GetUser(user.Email, user.CustomerId)
|
||||
|
||||
if userExists != nil {
|
||||
return errors.New(fmt.Sprintf("can't write new user %s, alread exists", user.Username))
|
||||
return errors.New(fmt.Sprintf("can't write new user %s, alread exists", user.Email))
|
||||
}
|
||||
key := userIdKey(user.CustomerId, user.Username)
|
||||
key := userIdKey(user.CustomerId, user.Email)
|
||||
db.userIdMap[key] = user.Id
|
||||
db.Users[user.Id] = user
|
||||
return nil
|
||||
@@ -125,7 +125,7 @@ func (db *InMemoryDb) GetSvgStringInterface(idxs SvgIdInterface) ([]string, erro
|
||||
return make([]string, len(idxs)), nil
|
||||
}
|
||||
|
||||
func userIdKey(customerId CustomerId, username Username) string {
|
||||
func userIdKey(customerId CustomerId, username Email) string {
|
||||
key := fmt.Sprintf("%s:%s", customerId, username)
|
||||
return key
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user