2016-12-08 20:45:26 +01:00
|
|
|
package commands
|
|
|
|
|
2016-12-11 14:50:01 +01:00
|
|
|
import (
|
2018-04-24 10:28:23 +02:00
|
|
|
"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"
|
2017-01-25 15:17:24 +01:00
|
|
|
"log"
|
2016-12-08 20:45:26 +01:00
|
|
|
)
|
|
|
|
|
2017-01-24 20:28:22 +01:00
|
|
|
// Register creates a new user with the given email & password
|
|
|
|
func Register(email string, password string) {
|
|
|
|
hash, _ := bcrypt.GenerateFromPassword([]byte(password), 10)
|
2018-04-25 13:25:34 +02:00
|
|
|
user := &models.User{
|
2017-01-24 20:28:22 +01:00
|
|
|
Email: email,
|
2016-12-11 14:50:01 +01:00
|
|
|
Password: string(hash),
|
|
|
|
}
|
2018-04-25 13:25:34 +02:00
|
|
|
err := datastore.SaveUser(user)
|
|
|
|
|
2018-04-23 10:50:31 +02:00
|
|
|
if err != nil {
|
|
|
|
log.Printf("Error creating user: %s", err)
|
|
|
|
} else {
|
|
|
|
log.Printf("User %s #%d created.\n", email, user.ID)
|
|
|
|
}
|
2016-12-08 20:57:44 +01:00
|
|
|
|
2016-12-08 20:45:26 +01:00
|
|
|
}
|