token-validator: Add automatic mail challenge
Some checks reported errors
continuous-integration/drone/push Build was killed
Some checks reported errors
continuous-integration/drone/push Build was killed
This commit is contained in:
parent
313597aede
commit
e39586338e
@ -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 {
|
||||
|
Reference in New Issue
Block a user