yesod-auth-pam (empty) → 1.0.0.0
raw patch · 4 files changed
+161/−0 lines, 4 filesdep +basedep +hamletdep +pamsetup-changed
Dependencies added: base, hamlet, pam, text, yesod-auth, yesod-core, yesod-form
Files
- LICENSE +19/−0
- Setup.hs +2/−0
- src/Yesod/Auth/Pam.hs +68/−0
- yesod-auth-pam.cabal +72/−0
+ LICENSE view
@@ -0,0 +1,19 @@+Copyright (c) 2013, Kazuo Koga <obiwanko@me.com>++Permission is hereby granted, free of charge, to any person obtaining a copy+of this software and associated documentation files (the "Software"), to deal+in the Software without restriction, including without limitation the rights+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell+copies of the Software, and to permit persons to whom the Software is+furnished to do so, subject to the following conditions:++The above copyright notice and this permission notice shall be included in+all copies or substantial portions of the Software.++THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN+THE SOFTWARE.
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ src/Yesod/Auth/Pam.hs view
@@ -0,0 +1,68 @@+{-# LANGUAGE OverloadedStrings #-}+{-# LANGUAGE QuasiQuotes #-}++module Yesod.Auth.Pam (authPam) where++import Control.Applicative ((<$>), (<*>))+import Data.Text (unpack)+import System.Posix.PAM (authenticate)+import Text.Hamlet (hamlet)+import Yesod.Auth (+ AuthPlugin(..),+ Creds(..),+ Route(..),+ loginErrorMessage,+ setCreds)+import Yesod.Core (+ lift,+ liftIO,+ notFound,+ toWidget)+import Yesod.Form (+ iopt,+ runInputPost,+ textField)++pid = "posixpam"++authPam =+ AuthPlugin pid dispatch login+ where+ dispatch "POST" [] = do+ input <- lift $ runInputPost $ (,)+ <$> iopt textField "ident"+ <*> iopt textField "password"+ case input of+ (Just ident, Just password) -> do+ auth <- validate ident password+ either failed (success ident) auth+ _ ->+ failed undefined+ dispatch _ _ = notFound++ validate ident password =+ liftIO $ authenticate "auth" (unpack ident) (unpack password)++ success ident _ =+ lift $ setCreds True $ Creds pid ident []+ failed _ =+ loginErrorMessage LoginR "Login failed."++ url = PluginR pid []+ login toMaster =+ toWidget [hamlet|+$newline never+ <div #pamlogin>+ <form method=post action=@{toMaster url} .form-horizontal>+ <div .control-group>+ <label .control-label>+ Username+ <div .controls>+ <input type=text name=ident required>+ <div .control-group>+ <label .control-label>+ Password+ <div .controls>+ <input type=password name=password required>+ <div .form-actions>+ <input type=submit .btn .btn-primary value="Login">|]
+ yesod-auth-pam.cabal view
@@ -0,0 +1,72 @@+-- Initial yesod-auth-pam.cabal generated by cabal init. For further+-- documentation, see http://haskell.org/cabal/users-guide/++-- The name of the package.+name: yesod-auth-pam++-- The package version. See the Haskell package versioning policy (PVP)+-- for standards guiding when and how versions should be incremented.+-- http://www.haskell.org/haskellwiki/Package_versioning_policy+-- PVP summary: +-+------- breaking API changes+-- | | +----- non-breaking API additions+-- | | | +--- code changes with no API change+version: 1.0.0.0++-- A short (one-line) description of the package.+synopsis: Provides PAM authentication module++-- A longer description of the package.+description: Provides PAM authentication module that simply+ lets a user specify his/her identifier.+ .+ This is not intended for real world use,+ just for private network.++-- The license under which the package is released.+license: MIT++-- The file containing the license text.+license-file: LICENSE++-- The package author(s).+author: Kazuo Koga <obiwanko@me.com>++-- An email address to which users can send suggestions, bug reports, and+-- patches.+maintainer: Kazuo Koga <obiwanko@me.com>++-- A copyright notice.+-- copyright:++category: Web, Yesod++build-type: Simple++-- Constraint on the version of Cabal needed to build this package.+cabal-version: >=1.14++library+ default-language: Haskell2010+ hs-source-dirs: src+ ghc-options: -Wall+ -fno-warn-missing-signatures++ -- Modules exported by the library.+ exposed-modules: Yesod.Auth.Pam++ -- Modules included in this library but not exported.+ -- other-modules:++ -- Other library packages from which modules are imported.+ build-depends: base <5+ , hamlet+ , pam+ , text+ , yesod-auth+ , yesod-core+ , yesod-form++source-repository this+ type: git+ location: https://github.com/kkazuo/yesod-auth-pam.git+ tag: 1.0.0.0