fathom/pkg/commands/users.go

25 lines
561 B
Go
Raw Normal View History

package commands
2016-12-11 14:50:01 +01:00
import (
"github.com/usefathom/fathom/pkg/datastore"
"github.com/usefathom/fathom/pkg/models"
2016-12-11 14:50:01 +01: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 14:50:01 +01:00
user := models.User{
Email: email,
2016-12-11 14:50:01 +01:00
Password: string(hash),
}
2018-04-23 10:50:31 +02: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)
}
}