NewUser initializes a new user from an email, password and user data.
(phone, email, password, aud string, userData map[string]interface{})
| 106 | |
| 107 | // NewUser initializes a new user from an email, password and user data. |
| 108 | func NewUser(phone, email, password, aud string, userData map[string]interface{}) (*User, error) { |
| 109 | passwordHash := "" |
| 110 | |
| 111 | if password != "" { |
| 112 | pw, err := crypto.GenerateFromPassword(context.Background(), password) |
| 113 | if err != nil { |
| 114 | return nil, err |
| 115 | } |
| 116 | |
| 117 | passwordHash = pw |
| 118 | } |
| 119 | |
| 120 | if userData == nil { |
| 121 | userData = make(map[string]interface{}) |
| 122 | } |
| 123 | |
| 124 | id := uuid.Must(uuid.NewV4()) |
| 125 | user := &User{ |
| 126 | ID: id, |
| 127 | Aud: aud, |
| 128 | Email: storage.NullString(strings.ToLower(email)), |
| 129 | Phone: storage.NullString(phone), |
| 130 | UserMetaData: userData, |
| 131 | EncryptedPassword: &passwordHash, |
| 132 | } |
| 133 | return user, nil |
| 134 | } |
| 135 | |
| 136 | // TableName overrides the table name used by pop |
| 137 | func (User) TableName() string { |