Merge branch 'master' of github.com:yesodweb/yesod

Conflicts:
	yesod-core/ChangeLog.md
	yesod-core/yesod-core.cabal
This commit is contained in:
Greg Weber 2015-10-13 06:39:26 -07:00
commit 3f15e2a20e
9 changed files with 54 additions and 15 deletions

View File

@ -1,4 +1,4 @@
resolver: lts-2.17 resolver: lts-3.7
packages: packages:
- ./yesod-core - ./yesod-core
- ./yesod-static - ./yesod-static
@ -13,6 +13,3 @@ packages:
- ./yesod - ./yesod
- ./yesod-eventsource - ./yesod-eventsource
- ./yesod-websockets - ./yesod-websockets
extra-deps:
- wai-app-static-3.1.0
- nonce-1.0.2

View File

@ -1,3 +1,7 @@
## 1.4.8
* GoogleEmail2: proper error message when permission denied
## 1.4.7 ## 1.4.7
* add a runHttpRequest function for handling HTTP errors * add a runHttpRequest function for handling HTTP errors

View File

@ -50,14 +50,17 @@ module Yesod.Auth.GoogleEmail2
import Yesod.Auth (Auth, AuthPlugin (AuthPlugin), import Yesod.Auth (Auth, AuthPlugin (AuthPlugin),
AuthRoute, Creds (Creds), AuthRoute, Creds (Creds),
Route (PluginR), YesodAuth, Route (PluginR), YesodAuth,
runHttpRequest, setCredsRedirect) runHttpRequest, setCredsRedirect,
logoutDest)
import qualified Yesod.Auth.Message as Msg import qualified Yesod.Auth.Message as Msg
import Yesod.Core (HandlerSite, HandlerT, MonadHandler, import Yesod.Core (HandlerSite, HandlerT, MonadHandler,
TypedContent, getRouteToParent, TypedContent, getRouteToParent,
getUrlRender, invalidArgs, getUrlRender, invalidArgs,
lift, liftIO, lookupGetParam, lift, liftIO, lookupGetParam,
lookupSession, notFound, redirect, lookupSession, notFound, redirect,
setSession, whamlet, (.:)) setSession, whamlet, (.:),
setMessage, getYesod, authRoute,
toHtml)
import Blaze.ByteString.Builder (fromByteString, toByteString) import Blaze.ByteString.Builder (fromByteString, toByteString)
@ -187,7 +190,18 @@ authPlugin storeToken clientID clientSecret =
mcode <- lookupGetParam "code" mcode <- lookupGetParam "code"
code <- code <-
case mcode of case mcode of
Nothing -> invalidArgs ["Missing code paramter"] Nothing -> do
merr <- lookupGetParam "error"
case merr of
Nothing -> invalidArgs ["Missing code paramter"]
Just err -> do
master <- lift getYesod
let msg =
case err of
"access_denied" -> "Access denied"
_ -> "Unknown error occurred: " `T.append` err
setMessage $ toHtml msg
lift $ redirect $ logoutDest master
Just c -> return c Just c -> return c
render <- getUrlRender render <- getUrlRender

View File

@ -27,7 +27,7 @@ getRootR = getAfterLoginR
getAfterLoginR :: Handler RepHtml getAfterLoginR :: Handler RepHtml
getAfterLoginR = do getAfterLoginR = do
mauth <- maybeAuthId mauth <- maybeAuthId
defaultLayout $ addHamlet [hamlet| defaultLayout [whamlet|
<p>Auth: #{show mauth} <p>Auth: #{show mauth}
$maybe _ <- mauth $maybe _ <- mauth
<p> <p>
@ -38,21 +38,22 @@ $nothing
|] |]
instance Yesod BID where instance Yesod BID where
approot = ApprootStatic "http://localhost:3000" approot = guessApproot
instance YesodAuth BID where instance YesodAuth BID where
type AuthId BID = Text type AuthId BID = Text
loginDest _ = AfterLoginR loginDest _ = AfterLoginR
logoutDest _ = AuthR LoginR logoutDest _ = AuthR LoginR
getAuthId = return . Just . credsIdentClaimed getAuthId = return . Just . credsIdentClaimed
authPlugins _ = [authOpenId] authPlugins _ = [authOpenId Claimed []]
authHttpManager = httpManager authHttpManager = httpManager
maybeAuthId = lookupSession credsKey
instance RenderMessage BID FormMessage where instance RenderMessage BID FormMessage where
renderMessage _ _ = defaultFormMessage renderMessage _ _ = defaultFormMessage
main :: IO () main :: IO ()
main = do main = do
m <- newManager def m <- newManager tlsManagerSettings
toWaiApp (BID m) >>= run 3000 toWaiApp (BID m) >>= run 3000

View File

@ -1,5 +1,5 @@
name: yesod-auth name: yesod-auth
version: 1.4.7 version: 1.4.8
license: MIT license: MIT
license-file: LICENSE license-file: LICENSE
author: Michael Snoyman, Patrick Brisbin author: Michael Snoyman, Patrick Brisbin

View File

@ -1,4 +1,8 @@
## 1.4.16.1 ## 1.4.16
* Add `guessApproot`
## 1.4.15.1
* bugfix neverExpires leaked threads * bugfix neverExpires leaked threads

View File

@ -71,6 +71,8 @@ module Yesod.Core
, MonadWidget (..) , MonadWidget (..)
, getRouteToParent , getRouteToParent
, defaultLayoutSub , defaultLayoutSub
-- * Approot
, guessApproot
-- * Misc -- * Misc
, yesodVersion , yesodVersion
, yesodRender , yesodRender

View File

@ -56,6 +56,7 @@ import Yesod.Core.Internal.Session
import Yesod.Core.Widget import Yesod.Core.Widget
import Control.Monad.Trans.Class (lift) import Control.Monad.Trans.Class (lift)
import Data.CaseInsensitive (CI) import Data.CaseInsensitive (CI)
import qualified Network.Wai.Request
-- | Define settings for a Yesod applications. All methods have intelligent -- | Define settings for a Yesod applications. All methods have intelligent
-- defaults, and therefore no implementation is required. -- defaults, and therefore no implementation is required.
@ -826,3 +827,19 @@ fileLocationToString loc = (loc_package loc) ++ ':' : (loc_module loc) ++
where where
line = show . fst . loc_start line = show . fst . loc_start
char = show . snd . loc_start char = show . snd . loc_start
-- | Guess the approot based on request headers. For more information, see
-- "Network.Wai.Middleware.Approot"
--
-- In the case of headers being unavailable, it falls back to 'ApprootRelative'
--
-- Since 1.4.16
guessApproot :: Approot site
guessApproot = ApprootRequest $ \_master req ->
case W.requestHeaderHost req of
Nothing -> ""
Just host ->
(if Network.Wai.Request.appearsSecure req
then "https://"
else "http://")
`T.append` TE.decodeUtf8With TEE.lenientDecode host

View File

@ -1,5 +1,5 @@
name: yesod-core name: yesod-core
version: 1.4.15.1 version: 1.4.16
license: MIT license: MIT
license-file: LICENSE license-file: LICENSE
author: Michael Snoyman <michael@snoyman.com> author: Michael Snoyman <michael@snoyman.com>
@ -25,7 +25,7 @@ library
build-depends: base >= 4.3 && < 5 build-depends: base >= 4.3 && < 5
, time >= 1.1.4 , time >= 1.1.4
, wai >= 3.0 , wai >= 3.0
, wai-extra >= 3.0.5 , wai-extra >= 3.0.7
, bytestring >= 0.9.1.4 , bytestring >= 0.9.1.4
, text >= 0.7 , text >= 0.7
, template-haskell , template-haskell