token-validator: get challenge id also via json
This commit is contained in:
parent
87599668b9
commit
9a821276e0
1 changed files with 20 additions and 8 deletions
|
@ -216,10 +216,6 @@ func accessibleChallenge(r *http.Request, ps httprouter.Params, _ []byte) (inter
|
||||||
}
|
}
|
||||||
|
|
||||||
func receiveToken(r *http.Request, ps httprouter.Params, body []byte) (interface{}, error) {
|
func receiveToken(r *http.Request, ps httprouter.Params, body []byte) (interface{}, error) {
|
||||||
if _, err := accessibleChallenge(r, ps, body); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
var gt givenToken
|
var gt givenToken
|
||||||
if err := json.Unmarshal(body, >); err != nil {
|
if err := json.Unmarshal(body, >); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -230,11 +226,27 @@ func receiveToken(r *http.Request, ps httprouter.Params, body []byte) (interface
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if chid, err := strconv.Atoi(string(ps.ByName("chid"))); err != nil {
|
// Find challenge ID
|
||||||
return nil, err
|
var chid int
|
||||||
} else if chid == 0 || chid > len(challenges) {
|
var err error
|
||||||
|
if chid, err = strconv.Atoi(string(ps.ByName("chid"))); err != nil {
|
||||||
|
if gt.Challenge > 0 {
|
||||||
|
chid = gt.Challenge
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if chid == 0 || chid > len(challenges) {
|
||||||
return nil, errors.New("This challenge doesn't exist")
|
return nil, errors.New("This challenge doesn't exist")
|
||||||
} else if std, err := getStudentByLogin(gt.Login); err != nil {
|
}
|
||||||
|
|
||||||
|
// Is the challenge accessible?
|
||||||
|
for _, a := range challenges[chid - 1].Accessible {
|
||||||
|
if err := a(nil, r); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if std, err := getStudentByLogin(gt.Login); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
} else {
|
} else {
|
||||||
if err := challenges[chid - 1].Check(&std, >, chid); err != nil {
|
if err := challenges[chid - 1].Check(&std, >, chid); err != nil {
|
||||||
|
|
Reference in a new issue