fathom/commands/users.go

35 lines
769 B
Go
Raw Normal View History

package commands
2016-12-11 13:50:01 +00:00
import (
"github.com/dannyvankooten/ana/db"
"github.com/dannyvankooten/ana/models"
"golang.org/x/crypto/bcrypt"
"log"
)
func createUser() {
2016-12-11 13:50:01 +00:00
if emailArg == "" || passwordArg == "" {
log.Fatal("Please supply -email and -password values")
}
2016-12-11 13:50:01 +00:00
hash, _ := bcrypt.GenerateFromPassword([]byte(passwordArg), 10)
user := models.User{
Email: emailArg,
Password: string(hash),
}
user.Save(db.Conn)
2016-12-11 13:50:01 +00:00
log.Printf("User %s #%d created", emailArg, user.ID)
}
func deleteUser() {
2016-12-11 13:50:01 +00:00
if emailArg == "" && idArg == 0 {
log.Fatal("Please supply an -email or -id value")
}
2016-12-11 13:50:01 +00:00
stmt2, _ := db.Conn.Prepare("DELETE FROM users WHERE email = ? OR id = ?")
stmt2.Exec(emailArg, idArg)
2016-12-11 13:50:01 +00:00
log.Printf("User with email %s or ID %d deleted", emailArg, idArg)
}