Commits

Luke Plant committed d9e3e4a

Implemented login form template

Comments (0)

Files changed (3)

src/Blog/Forms.hs

 import qualified Ella.Forms.Widgets.Textarea as TA
 import qualified Text.XHtml as X
 
+-- Widgets
 
 nameWidget = TextInput { value = ""
                        , size = Just 20
                          , identifier = "id_message"
                          }
 
+-- TODO properly
+passwordWidget = TextInput { value = ""
+                           , size = Just 20
+                           , maxlength = Just 20
+                           , name = "password"
+                           , identifier = "id_password"
+                           }
+
+usernameWidget = nameWidget { TI.name = "username"
+                            , TI.identifier = "id_username"
+                            }
+
 -- | Enum for the different stages of submitting a comment
 data CommentStage = NoComment
                   | CommentPreview
                     , format = format
                     }, Map.fromList errors)
 
+
+emptyLoginData = Map.fromList [("username", "")
+                              ,("password", "")]
+

src/Blog/Templates.hs

 module Blog.Templates
 where
 
-import Blog.Forms (emailWidget, nameWidget, messageWidget, formatWidget, CommentStage(..))
+import Blog.Forms (emailWidget, nameWidget, messageWidget, formatWidget, usernameWidget, passwordWidget, CommentStage(..))
 import Blog.Links
+import Data.List (intersperse)
+import Data.Maybe (fromJust)
+import Ella.Forms.Base
 import Ella.Forms.Widgets (makeLabel)
-import Ella.Forms.Base
-import Data.List (intersperse)
-import qualified Data.Map as Map
+import System.Locale (defaultTimeLocale)
+import System.Time (toUTCTime, formatCalendarTime)
+import System.Time.Utils (epochToClockTime)
 import Text.XHtml
-import qualified Blog.Post as P
 import qualified Blog.Category as C
 import qualified Blog.Comment as Cm
+import qualified Blog.Post as P
 import qualified Blog.Settings as Settings
-import System.Locale (defaultTimeLocale)
-import System.Time.Utils (epochToClockTime)
-import System.Time (toUTCTime, formatCalendarTime)
+import qualified Data.Map as Map
 
 -- | Holds variables for the 'page' template
 --
              }
 
 
+loginPage loginData loginErrors =
+    page $ defaultPageVars
+             { pcontent = (h1 << "Login")
+                          +++
+                          loginForm loginData loginErrors
+             , ptitle = "Login"
+             }
+
+loginForm loginData loginErrors =
+    form ! [ method "post", action ""]
+    << (
+        (table <<
+         (
+          (tr <<
+           (td << makeLabel "User name:" usernameWidget
+            +++
+            td << setVal (fromJust $ Map.lookup "username" loginData) usernameWidget
+           )
+          )
+          +++
+          (tr <<
+           (td << makeLabel "Password: " passwordWidget
+            +++
+            td << setVal (fromJust $ Map.lookup "password" loginData) passwordWidget
+           )
+          )
+         )
+        )
+        +++
+        (submit "login" "Login")
+       )
+
 -- General HTML fragments
 
 -- TODO - fix this to be able to work with URLs that have query

src/Blog/Views.hs

 -- which has pure functions that generally return Html.
 
 import Blog.DB (connect)
-import Blog.Forms (CommentStage(..), validateComment, emptyComment)
+import Blog.Forms (CommentStage(..), validateComment, emptyComment, emptyLoginData)
 import Blog.Links
 import Blog.Model
 import Blog.Templates
                       , cookieValue = loginHash username password timestamp }
      ]
 
-loginPage = undefined :: a -> a -> String -- TODO
-emptyLoginData = undefined -- TODO
-
 
 -- Utilities