haskell - Yesod admin auth with BrowserId and the scaffolded website -
i'm trying simple app yesod (a blog app) following https://www.youtube.com/watch?v=sadfv-qbvg8 (i used scaffolded website)
i want add simple authentification secure access of creation of article.
following http://www.yesodweb.com/book/authentication-and-authorization, added:
-- routes not requiring authentication. isauthorized (authr _) _ = return authorized isauthorized faviconr _ = return authorized isauthorized robotsr _ = return authorized isauthorized publisharticler _ = isadmin -- default authorized now. isauthorized _ _ = return authorized
my new route publisharticler. isadmin function same in book:
isadmin = mu <- maybeauthid return $ case mu of nothing -> authenticationrequired "admin" -> authorized _ -> unauthorized "you must admin"
and doesn't compile :(
foundation.hs:76:38: no instance (isstring userid) arising use of ‘isadmin’ in expression: isadmin in equation ‘isauthorized’: isauthorized publisharticler _ = isadmin in instance declaration ‘yesod app’
i don't understand i'm doing wrong…
thanks,
edit:
more information authid, it's defined this:
type authid app = userid
my model is:
user ident text password text maybe uniqueuser ident deriving typeable
and want check if ident property equal (like email address example) authorize publish new articles.
maybeauthid
return authid
object if user authenticated. in example yesod book, authid
synonym text
: it's user name. text
objects (and other types have isstring
instances) can built string literals, why example code works: haskell knows how transform
"admin"
into text
object.
you're using more complex type represent logged in user, either need provide isstring instance user (which build user without password, say):
instance isstring user fromstring s = user (pack s) ""
or, maybe easier, modify isadmin
function ident
part of user
object, like:
isadmin = mu <- maybeauthid return $ case mu of nothing -> authenticationrequired (user ident _) -> case ident of "admin" -> authorized _ -> unauthorized "you must admin"
edit misread definition of authid, thought
type authid app = user
in fact, have userid, ids of user objects in database. can 2 things: precompute list of ids of users have admin privilege , see if user id maybeauthid gives 1 of them, or read user in db given id , see if has rights...
Comments
Post a Comment