restart UI

Browser behavior is not ideal; a new tab is opened on restart.
Browsers won't let me redirect to a file:// so I cannot use the old tab.
This commit is contained in:
Joey Hess 2013-01-03 18:50:30 -04:00
parent e09b7198d4
commit bad9b6761d
9 changed files with 56 additions and 34 deletions

View file

@ -10,6 +10,8 @@
module Utility.WebApp where
import Common
import Utility.TempFile
import Utility.FileMode
import qualified Yesod
import qualified Network.Wai as Wai
@ -188,3 +190,23 @@ insertAuthToken extractToken predicate webapp root pathbits params =
params'
| predicate pathbits = authparam:params
| otherwise = params
{- Creates a html shim file that's used to redirect into the webapp,
- to avoid exposing the secret token when launching the web browser. -}
writeHtmlShim :: String -> String -> FilePath -> IO ()
writeHtmlShim title url file = viaTmp writeFileProtected file $ genHtmlShim title url
{- TODO: generate this static file using Yesod. -}
genHtmlShim :: String -> String -> String
genHtmlShim title url = unlines
[ "<html>"
, "<head>"
, "<title>"++ title ++ "</title>"
, "<meta http-equiv=\"refresh\" content=\"1; URL="++url++"\">"
, "<body>"
, "<p>"
, "<a href=\"" ++ url ++ "\">" ++ title ++ "</a>"
, "</p>"
, "</body>"
, "</html>"
]