OIDC: Retrieve promotion from OIDC claims
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
87b6975383
commit
a48bc1f1bc
4 changed files with 43 additions and 16 deletions
24
auth.go
24
auth.go
|
@ -77,25 +77,41 @@ func logout(c *gin.Context) {
|
|||
c.JSON(http.StatusOK, true)
|
||||
}
|
||||
|
||||
func completeAuth(c *gin.Context, username string, email string, firstname string, lastname string, groups string, session *Session) (usr *User, err error) {
|
||||
func completeAuth(c *gin.Context, username string, email string, firstname string, lastname string, promo uint, groups string, session *Session) (usr *User, err error) {
|
||||
if !userExists(username) {
|
||||
if usr, err = NewUser(username, email, firstname, lastname, groups); err != nil {
|
||||
if promo == 0 {
|
||||
promo = currentPromo
|
||||
}
|
||||
if usr, err = NewUser(username, email, firstname, lastname, promo, groups); err != nil {
|
||||
return
|
||||
}
|
||||
} else if usr, err = getUserByLogin(username); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
upd_user := false
|
||||
|
||||
// Update user's promo if it has changed
|
||||
if promo != 0 && promo != usr.Promo {
|
||||
usr.Promo = promo
|
||||
upd_user = true
|
||||
}
|
||||
|
||||
// Update user's group if they have been modified
|
||||
if len(groups) > 0 {
|
||||
if len(groups) > 255 {
|
||||
groups = groups[:255]
|
||||
}
|
||||
if usr.Groups != groups {
|
||||
usr.Groups = groups
|
||||
usr.Update()
|
||||
upd_user = true
|
||||
}
|
||||
}
|
||||
|
||||
if upd_user {
|
||||
usr.Update()
|
||||
}
|
||||
|
||||
if session == nil {
|
||||
session, err = usr.NewSession()
|
||||
} else {
|
||||
|
@ -137,7 +153,7 @@ func dummyAuth(c *gin.Context) {
|
|||
return
|
||||
}
|
||||
|
||||
if usr, err := completeAuth(c, lf["username"], lf["email"], lf["firstname"], lf["lastname"], "", nil); err != nil {
|
||||
if usr, err := completeAuth(c, lf["username"], lf["email"], lf["firstname"], lf["lastname"], currentPromo, "", nil); err != nil {
|
||||
c.AbortWithStatusJSON(http.StatusUnauthorized, gin.H{"errmsg": err.Error()})
|
||||
return
|
||||
} else {
|
||||
|
|
Reference in a new issue