Commit 4265158e authored by Alexis POYEN's avatar Alexis POYEN
Browse files

Feat : Set IsAdmin field, break on several groupe OAuth

parent 44169b41
Pipeline #5283 passed with stages
in 3 minutes and 26 seconds
...@@ -101,6 +101,11 @@ func (d *DataHandler) AddUser(w http.ResponseWriter, req *http.Request) { ...@@ -101,6 +101,11 @@ func (d *DataHandler) AddUser(w http.ResponseWriter, req *http.Request) {
http.Error(w, "passwords cannot be blank", 400) http.Error(w, "passwords cannot be blank", 400)
return return
} }
if newUser.Role == "ADMIN" {
newUser.IsAdmin = true
} else {
newUser.IsAdmin = false
}
if newUser.Password != "" { if newUser.Password != "" {
hash, err := bcrypt.GenerateFromPassword([]byte(newUser.Password), bcrypt.DefaultCost) hash, err := bcrypt.GenerateFromPassword([]byte(newUser.Password), bcrypt.DefaultCost)
if err != nil { if err != nil {
...@@ -154,6 +159,11 @@ func (d *DataHandler) UpdateUser(w http.ResponseWriter, req *http.Request) { ...@@ -154,6 +159,11 @@ func (d *DataHandler) UpdateUser(w http.ResponseWriter, req *http.Request) {
user.Name = newUser.Name user.Name = newUser.Name
user.Surname = newUser.Surname user.Surname = newUser.Surname
user.Role = newUser.Role user.Role = newUser.Role
if user.Role == "ADMIN" {
user.IsAdmin = true
} else {
user.IsAdmin = false
}
if newUser.Password != "" { if newUser.Password != "" {
hash, err := bcrypt.GenerateFromPassword([]byte(newUser.Password), bcrypt.DefaultCost) hash, err := bcrypt.GenerateFromPassword([]byte(newUser.Password), bcrypt.DefaultCost)
if err != nil { if err != nil {
......
...@@ -163,8 +163,12 @@ func (d *DataHandler) addUserInMemory(userOauth2 UserOAuth2) (User, error) { ...@@ -163,8 +163,12 @@ func (d *DataHandler) addUserInMemory(userOauth2 UserOAuth2) (User, error) {
for _, userRole := range userOauth2.Groups { for _, userRole := range userOauth2.Groups {
if userRole != "" && (userRole == os.Getenv("ADMIN_GROUP")) { if userRole != "" && (userRole == os.Getenv("ADMIN_GROUP")) {
user.Role = "ADMIN" user.Role = "ADMIN"
user.IsAdmin = true
break
} else if userRole != "" && (userRole == os.Getenv("CLIENT_GROUP")) { } else if userRole != "" && (userRole == os.Getenv("CLIENT_GROUP")) {
user.Role = "CLIENT" user.Role = "CLIENT"
user.IsAdmin = false
break
} else { } else {
return user, errors.New("user not in an app group") return user, errors.New("user not in an app group")
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment