diff --git a/Handler/Shared.hs b/Handler/Shared.hs index 0ce6b5f..c18ed05 100644 --- a/Handler/Shared.hs +++ b/Handler/Shared.hs @@ -357,3 +357,8 @@ nonceGen = unsafePerformIO Nonce.new -- | Randomly create a new verification key. newToken :: MonadIO m => m Text newToken = Nonce.nonce128urlT nonceGen + +enableTriggerToken _ (Just _) = return () +enableTriggerToken userId Nothing = do + token <- newToken + runDB $ update userId [UserTriggerToken =. Just token] diff --git a/Handler/ShowChallenge.hs b/Handler/ShowChallenge.hs index 855655b..d4a40c2 100644 --- a/Handler/ShowChallenge.hs +++ b/Handler/ShowChallenge.hs @@ -75,6 +75,16 @@ getChallengeHowToR :: Text -> Handler Html getChallengeHowToR name = do (Entity _ challenge) <- runDB $ getBy404 $ UniqueName name maybeUser <- maybeAuth + + case maybeUser of + Just (Entity userId user) -> do + enableTriggerToken userId (userTriggerToken user) + Nothing -> return () + + let mToken = case maybeUser of + Just (Entity _ user) -> userTriggerToken user + Nothing -> Nothing + let isIDSet = case maybeUser of Just (Entity _ user) -> isJust $ userLocalId user Nothing -> False @@ -83,7 +93,7 @@ getChallengeHowToR name = do keys <- runDB $ selectList [PublicKeyUser ==. userId] [] return $ not (null keys) Nothing -> return False - challengeLayout False challenge (challengeHowTo challenge (idToBeShown challenge maybeUser) isIDSet isSSHUploaded) + challengeLayout False challenge (challengeHowTo challenge (idToBeShown challenge maybeUser) isIDSet isSSHUploaded mToken) idToBeShown challenge maybeUser = case maybeUser of @@ -95,7 +105,7 @@ idToBeShown challenge maybeUser = defaultRepo challenge maybeUser = "ssh://gitolite@gonito.net/" ++ (idToBeShown challenge maybeUser) ++ "/" ++ (challengeName challenge) -challengeHowTo challenge idToBeShown isIDSet isSSHUploaded = $(widgetFile "challenge-how-to") +challengeHowTo challenge idToBeShown isIDSet isSSHUploaded mToken = $(widgetFile "challenge-how-to") getChallengeSubmissionR :: Text -> Handler Html getChallengeSubmissionR name = do diff --git a/Handler/YourAccount.hs b/Handler/YourAccount.hs index 51cf333..086d6e3 100644 --- a/Handler/YourAccount.hs +++ b/Handler/YourAccount.hs @@ -50,12 +50,6 @@ postYourAccountR = do setTitle "Your account" $(widgetFile "your-account") - -enableTriggerToken _ (Just _) = return () -enableTriggerToken userId Nothing = do - token <- newToken - runDB $ update userId [UserTriggerToken =. Just token] - checkPassword :: Maybe Text -> Bool checkPassword Nothing = True checkPassword (Just "") = True diff --git a/templates/challenge-how-to.hamlet b/templates/challenge-how-to.hamlet index 00fcbf3..0bd6bbb 100644 --- a/templates/challenge-how-to.hamlet +++ b/templates/challenge-how-to.hamlet @@ -47,9 +47,9 @@ $if not isIDSet || not isSSHUploaded cd #{challengeName challenge} geval --test-name dev-0 -

Submit your solution +

Push your solution to the git repo -

Push out.tsv files to your repo. It is also recommended to push your source codes along with out.tsv files. +

Commit and push out.tsv files to your repo. It is also recommended to push your source codes along with out.tsv files.

   cd #{challengeName challenge}
@@ -57,4 +57,19 @@ $if not isIDSet || not isSSHUploaded
   git commit -m 'my brilliant solution'
   git push origin master
 
-

If you use a repo hosted on Gonito.net, a submission and evaluation is triggered automatically. Otherwise, you need to tell Gonito.net to evaluate your submission (go to the submit form in such a case). +

Repos hosted on Gonito.net + +

If you use a repo hosted here, a submission and evaluation is triggered automatically. You'll see the evaluation results in your console while pushing. + +

External repos + +

If you use an external repo (e.g. at your own of Gitolite or at GitHub), you can configure a webhook. +$maybe token <- mToken +

Your webook is: +

+     https://gonito.net/trigger-remotely?token=#{token}&branch=master&challenge=#{challengeName challenge}&url=URL_TO_YOUR_REPO
+   

(must be POSTed) + +

Manual submission + +

In case other methods fail, you can submit your solution manually — go to the submit form.