aboutsummaryrefslogtreecommitdiff
path: root/handlers.go
diff options
context:
space:
mode:
authorSimon Ser <contact@emersion.fr>2019-12-09 19:25:45 +0100
committerSimon Ser <contact@emersion.fr>2019-12-09 19:35:15 +0100
commitc5afd1a61b06b3d5bd7287d1596b05d4c18ac138 (patch)
tree27a5a58779bbac4ddba8b8fda45baafdf1489d2f /handlers.go
parent7702925497a8230f50d2317c9ad41a73de0683ae (diff)
downloadalps-c5afd1a61b06b3d5bd7287d1596b05d4c18ac138.tar.gz
alps-c5afd1a61b06b3d5bd7287d1596b05d4c18ac138.zip
Reconnect to IMAP server when logged out
The session manager has been upgraded to deal with reconnections. Each session has its own expiration timer. Each time a request is received, the expiration timer is reset. A session can be closed (this is used when the user wants to logout). When the IMAP connection is closed by the server, it's set to nil in the session. The next time an IMAP command needs to be issued, the connection is re-established. Closes: https://todo.sr.ht/~sircmpwn/koushin/30
Diffstat (limited to 'handlers.go')
-rw-r--r--handlers.go12
1 files changed, 3 insertions, 9 deletions
diff --git a/handlers.go b/handlers.go
index 869e1c1..4e127b4 100644
--- a/handlers.go
+++ b/handlers.go
@@ -81,14 +81,14 @@ func handleLogin(ectx echo.Context) error {
username := ctx.FormValue("username")
password := ctx.FormValue("password")
if username != "" && password != "" {
- token, err := ctx.server.sessions.Put(username, password)
+ s, err := ctx.server.sessions.Put(username, password)
if err != nil {
if _, ok := err.(AuthError); ok {
return ctx.Render(http.StatusOK, "login.html", nil)
}
return fmt.Errorf("failed to put connection in pool: %v", err)
}
- ctx.setToken(token)
+ ctx.setToken(s.Token)
return ctx.Redirect(http.StatusFound, "/mailbox/INBOX")
}
@@ -99,13 +99,7 @@ func handleLogin(ectx echo.Context) error {
func handleLogout(ectx echo.Context) error {
ctx := ectx.(*context)
- err := ctx.session.Do(func(c *imapclient.Client) error {
- return c.Logout()
- })
- if err != nil {
- return fmt.Errorf("failed to logout: %v", err)
- }
-
+ ctx.session.Close()
ctx.setToken("")
return ctx.Redirect(http.StatusFound, "/login")
}