From d2e2ce5fc653f326a0e8e036f228046f7cb33734 Mon Sep 17 00:00:00 2001 From: nek0 Date: Tue, 12 Aug 2014 14:37:31 +0200 Subject: [PATCH] own user auth --- Application.hs | 5 ++++- Foundation.hs | 38 +++++++++++++++++++------------------- Handler/Home.hs | 26 ++++---------------------- config/models | 26 ++++++++++++++++++-------- config/routes | 4 +++- eidolon.cabal | 3 +++ templates/homepage.hamlet | 38 -------------------------------------- templates/homepage.julius | 1 - templates/homepage.lucius | 6 ------ 9 files changed, 51 insertions(+), 96 deletions(-) delete mode 100644 templates/homepage.hamlet delete mode 100644 templates/homepage.julius delete mode 100644 templates/homepage.lucius diff --git a/Application.hs b/Application.hs index d2cc784..4729d58 100644 --- a/Application.hs +++ b/Application.hs @@ -7,7 +7,7 @@ module Application import Import import Settings -import Yesod.Auth +-- import Yesod.Auth import Yesod.Default.Config import Yesod.Default.Main import Yesod.Default.Handlers @@ -28,6 +28,9 @@ import Yesod.Core.Types (loggerSet, Logger (Logger)) -- Import all relevant handler modules here. -- Don't forget to add new modules to your cabal file! import Handler.Home +import Handler.Signup +import Handler.Login +import Handler.Activate -- 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 diff --git a/Foundation.hs b/Foundation.hs index 2cbd028..4ce8d7b 100644 --- a/Foundation.hs +++ b/Foundation.hs @@ -3,8 +3,8 @@ module Foundation where import Prelude import Yesod import Yesod.Static -import Yesod.Auth -import Yesod.Auth.BrowserId +-- import Yesod.Auth +-- import Yesod.Auth.BrowserId import Yesod.Default.Config import Yesod.Default.Util (addStaticContentExternal) import Network.HTTP.Client.Conduit (Manager, HasHttpManager (getHttpManager)) @@ -14,7 +14,7 @@ import qualified Database.Persist import Database.Persist.Sql (SqlPersistT) import Settings.StaticFiles import Settings (widgetFile, Extra (..)) -import Model +-- import Model import Text.Jasmine (minifym) import Text.Hamlet (hamletFile) import Yesod.Core.Types (Logger) @@ -85,7 +85,7 @@ instance Yesod App where urlRenderOverride _ _ = Nothing -- The page to be redirected to when authentication is required. - authRoute _ = Just $ AuthR LoginR + -- authRoute _ = Just $ AuthR LoginR -- This function creates static content files in the static folder -- and names them based on a hash of their content. This allows @@ -116,28 +116,28 @@ instance YesodPersist App where instance YesodPersistRunner App where getDBRunner = defaultGetDBRunner connPool -instance YesodAuth App where - type AuthId App = UserId +-- instance YesodAuth App where +-- type AuthId App = UserId -- Where to send a user after successful login - loginDest _ = HomeR +-- loginDest _ = HomeR -- Where to send a user after logout - logoutDest _ = HomeR +-- logoutDest _ = HomeR - getAuthId creds = runDB $ do - x <- getBy $ UniqueUser $ credsIdent creds - case x of - Just (Entity uid _) -> return $ Just uid - Nothing -> do - fmap Just $ insert User - { userIdent = credsIdent creds - , userPassword = Nothing - } +-- getAuthId creds = runDB $ do +-- x <- getBy $ UniqueUser $ credsIdent creds +-- case x of +-- Just (Entity uid _) -> return $ Just uid +-- Nothing -> do +-- fmap Just $ insert User +-- { userIdent = credsIdent creds +-- , userPassword = Nothing +-- } -- You can add other plugins like BrowserID, email or OAuth here - authPlugins _ = [authBrowserId def] +-- authPlugins _ = [authBrowserId def] - authHttpManager = httpManager +-- authHttpManager = httpManager -- This instance is required to use forms. You can modify renderMessage to -- achieve customized and internationalized form validation messages. diff --git a/Handler/Home.hs b/Handler/Home.hs index 917bdf1..cdec41c 100644 --- a/Handler/Home.hs +++ b/Handler/Home.hs @@ -12,28 +12,10 @@ import Import -- inclined, or create a single monolithic file. getHomeR :: Handler Html getHomeR = do - (formWidget, formEnctype) <- generateFormPost sampleForm - let submission = Nothing :: Maybe (FileInfo, Text) - handlerName = "getHomeR" :: Text - defaultLayout $ do - aDomId <- newIdent - setTitle "Welcome To Yesod!" - $(widgetFile "homepage") + recentMedia <- runDB $ selectList [] [Desc MediaTime] + defaultLayout $ do + $(widgetFile "home") postHomeR :: Handler Html postHomeR = do - ((result, formWidget), formEnctype) <- runFormPost sampleForm - let handlerName = "postHomeR" :: Text - submission = case result of - FormSuccess res -> Just res - _ -> Nothing - - defaultLayout $ do - aDomId <- newIdent - setTitle "Welcome To Yesod!" - $(widgetFile "homepage") - -sampleForm :: Form (FileInfo, Text) -sampleForm = renderDivs $ (,) - <$> fileAFormReq "Choose a file" - <*> areq textField "What's on the file?" Nothing + error "not yet implemented" diff --git a/config/models b/config/models index cd7d6ca..6f924e8 100644 --- a/config/models +++ b/config/models @@ -1,12 +1,22 @@ User - ident Text - password Text Maybe - UniqueUser ident - deriving Typeable -Email + name Text email Text - user UserId Maybe - verkey Text Maybe - UniqueEmail email + password Text + deriving Typeable +-- Email +-- email Text +-- user UserId Maybe +-- verkey Text Maybe +-- UniqueEmail email +Token + token Text + user User +Media + title Text + path FilePath + thumbPath FilePath + time UTCTime + description Text + tags Texts -- By default this file is used in Model.hs (which is imported by Foundation.hs) diff --git a/config/routes b/config/routes index c1f7063..6a73369 100644 --- a/config/routes +++ b/config/routes @@ -1,7 +1,9 @@ /static StaticR Static getStatic -/auth AuthR Auth getAuth /favicon.ico FaviconR GET /robots.txt RobotsR GET / HomeR GET POST +/signup SignupR GET POST +/login LoginR GET POST +/activate/#String ActivateR GET diff --git a/eidolon.cabal b/eidolon.cabal index 8e68ab4..0bec6c2 100644 --- a/eidolon.cabal +++ b/eidolon.cabal @@ -20,6 +20,9 @@ library Settings.StaticFiles Settings.Development Handler.Home + Handler.Signup + Handler.Login + Handler.Activate if flag(dev) || flag(library-only) cpp-options: -DDEVELOPMENT diff --git a/templates/homepage.hamlet b/templates/homepage.hamlet deleted file mode 100644 index 9180bfc..0000000 --- a/templates/homepage.hamlet +++ /dev/null @@ -1,38 +0,0 @@ -

_{MsgHello} - -
    -
  1. Now that you have a working project you should use the # - \Yesod book to learn more. # - You can also use this scaffolded site to explore some basic concepts. - -
  2. This page was generated by the #{handlerName} handler in # - \Handler/Home.hs. - -
  3. The #{handlerName} handler is set to generate your site's home screen in Routes file # - config/routes - -
  4. The HTML you are seeing now is actually composed by a number of widgets, # - most of them are brought together by the defaultLayout function which # - is defined in the Foundation.hs module, and used by #{handlerName}. # - All the files for templates and wigdets are in templates. - -
  5. - A Widget's Html, Css and Javascript are separated in three files with the # - \.hamlet, .lucius and .julius extensions. - -
  6. If you had javascript enabled then you wouldn't be seeing this. - -
  7. - This is an example trivial Form. Read the # - \Forms chapter # - on the yesod book to learn more about them. - $maybe (info,con) <- submission -
    - Your file's type was #{fileContentType info}. You say it has: #{con} -
    - ^{formWidget} - - -
  8. And last but not least, Testing. In tests/main.hs you will find a # - test suite that performs tests on this page. # - You can run your tests by doing:
    yesod test
    diff --git a/templates/homepage.julius b/templates/homepage.julius deleted file mode 100644 index 22920d4..0000000 --- a/templates/homepage.julius +++ /dev/null @@ -1 +0,0 @@ -document.getElementById(#{toJSON aDomId}).innerHTML = "This text was added by the Javascript part of the homepage widget."; diff --git a/templates/homepage.lucius b/templates/homepage.lucius deleted file mode 100644 index 54986f8..0000000 --- a/templates/homepage.lucius +++ /dev/null @@ -1,6 +0,0 @@ -h1 { - text-align: center -} -h2##{aDomId} { - color: #990 -}