Add logout route

This commit is contained in:
Simon Ser 2019-12-03 13:24:46 +01:00
parent 23e3e85251
commit f4808eb4c5
No known key found for this signature in database
GPG key ID: 0FDE7BE0E88F5E48
2 changed files with 11 additions and 0 deletions

View file

@ -2,6 +2,8 @@
<h1>koushin</h1>
<a href="/logout">Logout</a>
<h2>{{.Mailbox.Name}}</h2>
<p>Mailboxes:</p>

View file

@ -238,6 +238,15 @@ func New(imapURL string) *echo.Echo {
e.GET("/login", handleLogin)
e.POST("/login", handleLogin)
e.GET("/logout", func(ectx echo.Context) error {
ctx := ectx.(*context)
if err := ctx.conn.Logout(); err != nil {
return err
}
ctx.setToken("")
return ctx.Redirect(http.StatusFound, "/login")
})
e.Static("/assets", "public/assets")
return e