improved admin and events tables
This commit is contained in:
@@ -11,6 +11,11 @@ type User struct {
|
||||
Admin bool `db:"admin" json:"admin"`
|
||||
}
|
||||
|
||||
type UserChangePassword struct {
|
||||
UserName string `json:"userName" validate:"required" db:"userName"`
|
||||
Password string `json:"password" validate:"required,min=12"`
|
||||
}
|
||||
|
||||
// hashes a password
|
||||
func hashPassword(password string) ([]byte, error) {
|
||||
return bcrypt.GenerateFromPassword([]byte(password), bcrypt.DefaultCost)
|
||||
@@ -64,11 +69,6 @@ func Add(user UserAdd) error {
|
||||
}
|
||||
}
|
||||
|
||||
type UserChangePassword struct {
|
||||
UserName string `json:"userName" validate:"required" db:"userName"`
|
||||
Password string `json:"password" validate:"required,min=12"`
|
||||
}
|
||||
|
||||
func ChangePassword(user UserChangePassword) (string, error) {
|
||||
// try to hash teh password
|
||||
if hash, err := hashPassword(user.Password); err != nil {
|
||||
@@ -103,3 +103,9 @@ func SetAdmin(userName string, admin bool) error {
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
func Delete(userName string) error {
|
||||
_, err := db.DB.Exec("DELETE FROM USERS WHERE name = $1", userName)
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user