mirror of
https://github.com/ClusterCockpit/cc-backend
synced 2024-11-10 08:57:25 +01:00
Fix auth.AddUser method
This commit is contained in:
parent
dc4c7f0033
commit
dc0bf80742
@ -157,7 +157,8 @@ func (auth *Authentication) Login(onsuccess http.Handler, onfailure func(rw http
|
||||
user := (*User)(nil)
|
||||
if username != "" {
|
||||
if user, _ = auth.GetUser(username); err != nil {
|
||||
log.Warnf("login of unkown user %#v", username)
|
||||
// log.Warnf("login of unkown user %#v", username)
|
||||
_ = err
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -11,6 +11,7 @@ import (
|
||||
"github.com/ClusterCockpit/cc-backend/pkg/log"
|
||||
sq "github.com/Masterminds/squirrel"
|
||||
"github.com/jmoiron/sqlx"
|
||||
"golang.org/x/crypto/bcrypt"
|
||||
)
|
||||
|
||||
func (auth *Authentication) GetUser(username string) (*User, error) {
|
||||
@ -36,8 +37,14 @@ func (auth *Authentication) GetUser(username string) (*User, error) {
|
||||
|
||||
func (auth *Authentication) AddUser(user *User) error {
|
||||
rolesJson, _ := json.Marshal(user.Roles)
|
||||
|
||||
password, err := bcrypt.GenerateFromPassword([]byte(user.Password), bcrypt.DefaultCost)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
cols := []string{"username", "password", "roles"}
|
||||
vals := []interface{}{user.Username, user.Password, string(rolesJson)}
|
||||
vals := []interface{}{user.Username, string(password), string(rolesJson)}
|
||||
if user.Name != "" {
|
||||
cols = append(cols, "name")
|
||||
vals = append(vals, user.Name)
|
||||
|
Loading…
Reference in New Issue
Block a user