mirror of
				https://github.com/ClusterCockpit/cc-backend
				synced 2025-10-31 07:55:06 +01:00 
			
		
		
		
	Fix auth.AddUser method
This commit is contained in:
		| @@ -157,7 +157,8 @@ func (auth *Authentication) Login(onsuccess http.Handler, onfailure func(rw http | |||||||
| 		user := (*User)(nil) | 		user := (*User)(nil) | ||||||
| 		if username != "" { | 		if username != "" { | ||||||
| 			if user, _ = auth.GetUser(username); err != nil { | 			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" | 	"github.com/ClusterCockpit/cc-backend/pkg/log" | ||||||
| 	sq "github.com/Masterminds/squirrel" | 	sq "github.com/Masterminds/squirrel" | ||||||
| 	"github.com/jmoiron/sqlx" | 	"github.com/jmoiron/sqlx" | ||||||
|  | 	"golang.org/x/crypto/bcrypt" | ||||||
| ) | ) | ||||||
|  |  | ||||||
| func (auth *Authentication) GetUser(username string) (*User, error) { | 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 { | func (auth *Authentication) AddUser(user *User) error { | ||||||
| 	rolesJson, _ := json.Marshal(user.Roles) | 	rolesJson, _ := json.Marshal(user.Roles) | ||||||
|  |  | ||||||
|  | 	password, err := bcrypt.GenerateFromPassword([]byte(user.Password), bcrypt.DefaultCost) | ||||||
|  | 	if err != nil { | ||||||
|  | 		return err | ||||||
|  | 	} | ||||||
|  |  | ||||||
| 	cols := []string{"username", "password", "roles"} | 	cols := []string{"username", "password", "roles"} | ||||||
| 	vals := []interface{}{user.Username, user.Password, string(rolesJson)} | 	vals := []interface{}{user.Username, string(password), string(rolesJson)} | ||||||
| 	if user.Name != "" { | 	if user.Name != "" { | ||||||
| 		cols = append(cols, "name") | 		cols = append(cols, "name") | ||||||
| 		vals = append(vals, user.Name) | 		vals = append(vals, user.Name) | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user