From: fr33domlover <[email protected]>
A URL path like `/u/wolftune` is much more convenient than `/u/3`, and
most websites seem to use the former indeed. This is a (mostly, see
below) non-breaking change which:
1. Adds a new handler for `/u/<username>` which returns the usual user
page
2. Makes `/u/<userid>` be a simple redirect to the new route
Hopefully this is the beginning of moving to `/u/<username>` being the
primary path and `/u/<userid>` being secondary or even not existing at
all.
NOTE: If the current production database has a user whose `userIdent`
contains only digits, this change may create a problem. This is
unlikely, but worth checking just in case.
---
config/routes | 3 ++-
src/Handler/NewDesign.hs | 8 +++++++-
2 files changed, 9 insertions(+), 2 deletions(-)
diff --git a/config/routes b/config/routes
index 999f36b..575cff3 100644
--- a/config/routes
+++ b/config/routes
@@ -74,7 +74,8 @@
-- ## Browsing a particular user (may need fleshing out?)
--
-/u/#UserHandle UserR GET
+/u/!#UserHandle UserR GET
+/u/#Text UserByIdentR GET
-- Yesod jibber jabber
/static StaticR Static appStatic
diff --git a/src/Handler/NewDesign.hs b/src/Handler/NewDesign.hs
index 05829ab..dcfd060 100644
--- a/src/Handler/NewDesign.hs
+++ b/src/Handler/NewDesign.hs
@@ -212,9 +212,15 @@ postCreateAccountR = do
-- | Public profile for a user.
getUserR :: UserId -> Handler Html
getUserR user_id = do
+ user <- runYDB $ get404 user_id
+ redirect $ UserByIdentR $ userIdent user
+
+-- | Public profile for a user.
+getUserByIdentR :: Text -> Handler Html
+getUserByIdentR user_ident = do
mviewer_id <- maybeAuthId
- user <- runYDB $ get404 user_id
+ Entity user_id user <- runYDB $ getBy404 $ UniqueUser user_ident
projects_and_roles <- runDB (fetchUserProjectsAndRolesDB user_id)
when ( Just user_id == mviewer_id
--
1.9.1
_______________________________________________
Dev mailing list
[email protected]
https://lists.snowdrift.coop/mailman/listinfo/dev