aboutsummaryrefslogtreecommitdiff
path: root/plugins/base
diff options
context:
space:
mode:
authorDrew DeVault <sir@cmpwn.com>2020-05-20 13:05:05 -0400
committerSimon Ser <contact@emersion.fr>2020-05-20 19:07:47 +0200
commit9465f8db6d12a2bb8707f62ccb7d668059ec1cf1 (patch)
tree479c7dcca50c06008a85e5b95d6b36c8c713003c /plugins/base
parentee3f66c24c3a8fba4ee1867e15f7c0814abdb100 (diff)
downloadalps-9465f8db6d12a2bb8707f62ccb7d668059ec1cf1.tar.gz
alps-9465f8db6d12a2bb8707f62ccb7d668059ec1cf1.zip
login: set encrypted "remember me" token
Diffstat (limited to 'plugins/base')
-rw-r--r--plugins/base/routes.go20
1 files changed, 19 insertions, 1 deletions
diff --git a/plugins/base/routes.go b/plugins/base/routes.go
index 3b47668..d023b4b 100644
--- a/plugins/base/routes.go
+++ b/plugins/base/routes.go
@@ -160,6 +160,12 @@ func handleGetMailbox(ctx *alps.Context) error {
func handleLogin(ctx *alps.Context) error {
username := ctx.FormValue("username")
password := ctx.FormValue("password")
+ remember := ctx.FormValue("remember-me")
+
+ if username == "" && password == "" {
+ username, password = ctx.GetLoginToken()
+ }
+
if username != "" && password != "" {
s, err := ctx.Server.Sessions.Put(username, password)
if err != nil {
@@ -170,18 +176,30 @@ func handleLogin(ctx *alps.Context) error {
}
ctx.SetSession(s)
+ if remember == "on" {
+ ctx.SetLoginToken(username, password)
+ }
+
if path := ctx.QueryParam("next"); path != "" && path[0] == '/' && path != "/login" {
return ctx.Redirect(http.StatusFound, path)
}
return ctx.Redirect(http.StatusFound, "/mailbox/INBOX")
}
- return ctx.Render(http.StatusOK, "login.html", alps.NewBaseRenderData(ctx))
+ return ctx.Render(http.StatusOK, "login.html",
+ &struct {
+ alps.BaseRenderData
+ CanRememberMe bool
+ }{
+ BaseRenderData: *alps.NewBaseRenderData(ctx),
+ CanRememberMe: ctx.Server.Options.LoginKey != nil,
+ })
}
func handleLogout(ctx *alps.Context) error {
ctx.Session.Close()
ctx.SetSession(nil)
+ ctx.SetLoginToken("", "")
return ctx.Redirect(http.StatusFound, "/login")
}