MFlow  Create and maintain dynamic Web applications as easy and fast as console applications
Thou shall not write request handlers
 This release: 11/06/2014.  agocorona@gmail.com (@agocorona) <>< . issues & bugs .  Mflow Source code,     source code of this site




Controlling backtracking

sometimes it is dangerous to go back in the flow,  when a transaction that can not be undone has been done. For example a payment. For this purpose, it is necessary a cut in backtracking. 

 I added preventGoingBack. It perform this cut in backtracking when going back in the flow. When this condition is detected, ir executes the parameter, that is a subflow . Usually this subflow consist of a single ask statement that present a single page with an error. When going forward, the statement is transparent.

preventGoingBack :: (Functor m, MonadIO m, FormInput v) => FlowM v m () -> FlowM v m ()

Here preventGoingBack does not permit to navigate back to code before himself. The user can go back in the browser, but what the user will see when he press a button or link in the flow, is the message of preventGoingBack and their available options. After that, the flow will continue normally.
"

Running example

(in the light red box):
press here to pay 100000 $


Source code:

{-# OPTIONS -XCPP #-} 
module PreventGoingBack ( preventBack) where
import System.IO.Unsafe
import Control.Concurrent.MVar

-- #define ALONE -- to execute it alone, uncomment this
#ifdef ALONE
import MFlow.Wai.Blaze.Html.All
main= runNavigation "" $ transientNav preventBack
#else
import MFlow.Wai.Blaze.Html.All hiding(page)
import Menu
#endif

rpaid= unsafePerformIO $ newMVar (0 :: Int)


preventBack= do
    page  $ wlink "don't care" << b << "press here to pay 100000 $ "
    payIt
    paid  <- liftIO $ readMVar rpaid
    preventGoingBack . page  $ p << "You already paid 100000 before"
                           ++> p << "you can not go back until the end of the buy process"
                           ++> wlink () << p << "Please press here to continue"
                           
    page  $   p << ("you paid "++ show paid)
        ++> wlink () << p << "Press here to go to the menu or press the back button to verify that you can not pay again"
    where
    payIt= liftIO $ do
      print "paying"
      paid <- takeMVar  rpaid
      putMVar rpaid $ paid + 100000

-- to run it alone, change page by ask and uncomment this:
--main= runNavigation "" $ transientNav preventBack

comments powered by Disqus