token-validator: Add automatic mail challenge
continuous-integration/drone/push Build was killed Details

This commit is contained in:
nemunaire 2022-02-19 11:38:34 +01:00
parent 313597aede
commit e39586338e
1 changed files with 20 additions and 0 deletions

View File

@ -210,6 +210,25 @@ func challengeEMail(s *adlin.Student, t *givenToken, chid int) error {
return errors.New("This is not the expected token.")
}
func challengeAPIEMail(_ httprouter.Params, body []byte) (interface{}, error) {
var st map[string]string
if err := json.Unmarshal(body, &st); err != nil {
return nil, err
}
if std, err := adlin.GetStudentByLogin(st["login"]); err != nil {
return nil, err
} else {
if _, err := std.UnlockNewChallenge(8, st["token"]); err != nil {
log.Println(err)
return nil, err
}
log.Printf("%s just unlock ch#%d\n", std.Login, 8)
return "Success", nil
}
}
var challenges []Challenge
func init() {
@ -288,6 +307,7 @@ func init() {
router.POST("/echorequest", rawHandler(responseHandler(definedChallengeHandler(receiveToken, 7))))
router.POST("/testdisk", rawHandler(responseHandler(definedChallengeHandler(receiveToken, 8))))
router.POST("/wg-step", rawHandler(responseHandler(definedChallengeHandler(receiveToken, 10))))
router.POST("/api/recv-mail", remoteValidatorHandler(apiHandler(challengeAPIEMail)))
}
type givenToken struct {