Handle student groups
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
nemunaire 2021-09-16 00:26:09 +02:00
parent 6fb7986a7a
commit 4c46386fff
5 changed files with 41 additions and 20 deletions

11
auth.go
View file

@ -32,16 +32,21 @@ func logout(w http.ResponseWriter, ps httprouter.Params, body []byte) HTTPRespon
return APIResponse{true}
}
func completeAuth(w http.ResponseWriter, username string, email string, firstname string, lastname string, session *Session) (err error) {
func completeAuth(w http.ResponseWriter, username string, email string, firstname string, lastname string, groups string, session *Session) (err error) {
var usr User
if !userExists(username) {
if usr, err = NewUser(username, email, firstname, lastname); err != nil {
if usr, err = NewUser(username, email, firstname, lastname, groups); err != nil {
return err
}
} else if usr, err = getUserByLogin(username); err != nil {
return err
}
if usr.Groups != groups {
usr.Groups = groups
usr.Update()
}
if session == nil {
var s Session
s, err = usr.NewSession()
@ -73,5 +78,5 @@ func dummyAuth(w http.ResponseWriter, _ httprouter.Params, body []byte) (interfa
return nil, err
}
return map[string]string{"status": "OK"}, completeAuth(w, lf["login"], lf["email"], lf["firstname"], lf["lastname"], nil)
return map[string]string{"status": "OK"}, completeAuth(w, lf["login"], lf["email"], lf["firstname"], lf["lastname"], "", nil)
}