fathom/pkg/commands/users.go

26 lines
564 B
Go
Raw Normal View History

package commands
2016-12-11 13:50:01 +00:00
import (
"github.com/usefathom/fathom/pkg/datastore"
"github.com/usefathom/fathom/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)
user := &models.User{
Email: email,
2016-12-11 13:50:01 +00:00
Password: string(hash),
}
err := datastore.SaveUser(user)
2018-04-23 08:50:31 +00:00
if err != nil {
log.Printf("Error creating user: %s", err)
} else {
log.Printf("User %s #%d created.\n", email, user.ID)
}
}