2016-12-08 19:45:26 +00:00
|
|
|
package commands
|
|
|
|
|
2016-12-11 13:50:01 +00:00
|
|
|
import (
|
2018-04-20 11:12:23 +00:00
|
|
|
"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"
|
2017-01-25 14:17:24 +00:00
|
|
|
"log"
|
2016-12-08 19:45:26 +00:00
|
|
|
)
|
|
|
|
|
2017-01-24 19:28:22 +00:00
|
|
|
// 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{
|
2017-01-24 19:28:22 +00:00
|
|
|
Email: email,
|
2016-12-11 13:50:01 +00:00
|
|
|
Password: string(hash),
|
|
|
|
}
|
2017-01-25 12:46:43 +00:00
|
|
|
user.Save(datastore.DB)
|
2016-12-08 19:57:44 +00:00
|
|
|
|
2017-01-25 14:17:24 +00:00
|
|
|
log.Printf("User %s #%d created.\n", email, user.ID)
|
2016-12-08 19:45:26 +00:00
|
|
|
}
|