fathom/pkg/commands/users.go

25 lines
565 B
Go
Raw Normal View History

package commands
2016-12-11 13:50:01 +00:00
import (
"github.com/dannyvankooten/ana/pkg/datastore"
"github.com/dannyvankooten/ana/pkg/models"
2016-12-11 13:50:01 +00:00
"golang.org/x/crypto/bcrypt"
"log"
)
// Register creates a new user with the given email & password
func Register(email string, password string) {
hash, _ := bcrypt.GenerateFromPassword([]byte(password), 10)
2016-12-11 13:50:01 +00:00
user := models.User{
Email: email,
2016-12-11 13:50:01 +00:00
Password: string(hash),
}
2018-04-23 08:50:31 +00:00
err := user.Save(datastore.DB)
if err != nil {
log.Printf("Error creating user: %s", err)
} else {
log.Printf("User %s #%d created.\n", email, user.ID)
}
}