Remove unused Profile controller, from the scaffolding

This commit is contained in:
Danielle McLean 2017-10-03 13:37:24 +11:00
parent 0a230e7644
commit a2a0ec5127
Signed by: 00dani
GPG key ID: 3844A6973C6058F1
5 changed files with 2 additions and 72 deletions

View file

@ -5,5 +5,3 @@
/robots.txt RobotsR GET /robots.txt RobotsR GET
/ HomeR GET / HomeR GET
/profile ProfileR GET

View file

@ -49,7 +49,6 @@ import System.Log.FastLogger (defaultBufSize, newStdoutLoggerSet,
-- Don't forget to add new modules to your cabal file! -- Don't forget to add new modules to your cabal file!
import Handler.Common import Handler.Common
import Handler.Home import Handler.Home
import Handler.Profile
-- This line actually creates our YesodDispatch instance. It is the second half -- This line actually creates our YesodDispatch instance. It is the second half
-- of the call to mkYesodData which occurs in Foundation.hs. Please see the -- of the call to mkYesodData which occurs in Foundation.hs. Please see the

View file

@ -100,35 +100,14 @@ instance Yesod App where
master <- getYesod master <- getYesod
mmsg <- getMessage mmsg <- getMessage
muser <- maybeAuthPair -- muser <- maybeAuthPair
mcurrentRoute <- getCurrentRoute mcurrentRoute <- getCurrentRoute
-- Get the breadcrumbs, as defined in the YesodBreadcrumbs instance. -- Get the breadcrumbs, as defined in the YesodBreadcrumbs instance.
(title, parents) <- breadcrumbs (title, parents) <- breadcrumbs
-- Define the menu items of the header. -- Define the menu items of the header.
let menuItems = let menuItems = []
[ NavbarLeft $ MenuItem
{ menuItemLabel = "Home"
, menuItemRoute = HomeR
, menuItemAccessCallback = True
}
, NavbarLeft $ MenuItem
{ menuItemLabel = "Profile"
, menuItemRoute = ProfileR
, menuItemAccessCallback = isJust muser
}
, NavbarRight $ MenuItem
{ menuItemLabel = "Login"
, menuItemRoute = AuthR LoginR
, menuItemAccessCallback = isNothing muser
}
, NavbarRight $ MenuItem
{ menuItemLabel = "Logout"
, menuItemRoute = AuthR LogoutR
, menuItemAccessCallback = isJust muser
}
]
let navbarLeftMenuItems = [x | NavbarLeft x <- menuItems] let navbarLeftMenuItems = [x | NavbarLeft x <- menuItems]
let navbarRightMenuItems = [x | NavbarRight x <- menuItems] let navbarRightMenuItems = [x | NavbarRight x <- menuItems]
@ -155,8 +134,6 @@ instance Yesod App where
isAuthorized RobotsR _ = return Authorized isAuthorized RobotsR _ = return Authorized
isAuthorized (StaticR _) _ = return Authorized isAuthorized (StaticR _) _ = return Authorized
isAuthorized ProfileR _ = isAuthenticated
-- This function creates static content files in the static folder -- This function creates static content files in the static folder
-- and names them based on a hash of their content. This allows -- and names them based on a hash of their content. This allows
-- expiration dates to be set far in the future without worry of -- expiration dates to be set far in the future without worry of
@ -189,7 +166,6 @@ instance Yesod App where
instance YesodBreadcrumbs App where instance YesodBreadcrumbs App where
breadcrumb HomeR = return ("Home", Nothing) breadcrumb HomeR = return ("Home", Nothing)
breadcrumb (AuthR _) = return ("Login", Just HomeR) breadcrumb (AuthR _) = return ("Login", Just HomeR)
breadcrumb ProfileR = return ("Profile", Just HomeR)
breadcrumb _ = return ("home", Nothing) breadcrumb _ = return ("home", Nothing)
-- How to run database actions. -- How to run database actions.

View file

@ -1,15 +0,0 @@
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE TypeFamilies #-}
module Handler.Profile where
import Import
getProfileR :: Handler Html
getProfileR = do
(_, user) <- requireAuthPair
defaultLayout $ do
setTitle . toHtml $ userIdent user <> "'s User page"
$(widgetFile "profile")

View file

@ -1,28 +0,0 @@
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE OverloadedStrings #-}
module Handler.ProfileSpec (spec) where
import TestImport
spec :: Spec
spec = withApp $ do
describe "Profile page" $ do
it "asserts no access to my-account for anonymous users" $ do
get ProfileR
statusIs 403
it "asserts access to my-account for authenticated users" $ do
userEntity <- createUser "foo"
authenticateAs userEntity
get ProfileR
statusIs 200
it "asserts user's information is shown" $ do
userEntity <- createUser "bar"
authenticateAs userEntity
get ProfileR
let (Entity _ user) = userEntity
htmlAnyContain ".username" . unpack $ userIdent user