Closed nurpax closed 10 years ago
Here's a patch I used to modify the default project template to add "remember me" checkbox into the login screen. However, I'm not including it in a PR because it doesn't work ideally. It shows the "Remember me?" checkbox for both the login screen and the "add new user" screen. I wanted to leave it out in the "create new user" form, but seems like Heist doesn't allow conditionally leaving out portions of a template without backing it up with some Haskell code. I nowadays define most of my templates client-side w/ Handlebars.js, so I suck at Heist templating.
nurpax@nurpax:~/dev/snap$ git diff
diff --git a/project_template/default/snaplets/heist/templates/userform.tpl b/project_templat
index 0f8a8fc..c0bfcb3 100644
--- a/project_template/default/snaplets/heist/templates/userform.tpl
+++ b/project_template/default/snaplets/heist/templates/userform.tpl
@@ -8,6 +8,14 @@
</tr>
<tr>
<td></td>
+ <td>
+ <label>
+ <input type="checkbox" id="remember" name="remember"> Remember me
+ </label>
+ <td>
+ </tr>
+ <tr>
+ <td></td>
<td><input type="submit" value="${submitText}" /></td>
</tr>
</table>
diff --git a/project_template/default/src/Site.hs b/project_template/default/src/Site.hs
index cefdc45..61da460 100644
--- a/project_template/default/src/Site.hs
+++ b/project_template/default/src/Site.hs
@@ -38,7 +38,7 @@ handleLogin authError = heistLocal (I.bindSplices errs) $ render "login"
-- | Handle login submit
handleLoginSubmit :: Handler App (AuthManager App) ()
handleLoginSubmit =
- loginUser "login" "password" Nothing
+ loginUser "login" "password" (Just "remember")
(\_ -> handleLogin err) (redirect "/")
where
err = Just "Unknown user or password"
BTW if you skip the template patch in comments, this pull request should be fine to merge.
Tested by adding a remember checkbox into the project default template login. I verified that a "remember_token" gets saved to a non-null value in the users.json after login.
I've copy&pasted my patch for adding "remember me" functionality into the comments of this pull request.