28 lines
649 B
Go
Raw Normal View History

2017-06-16 23:32:47 +00:00
package auth
2017-06-11 09:13:59 +00:00
2019-05-07 14:01:51 +00:00
import (
2019-06-01 04:55:49 +00:00
"net/http"
2019-05-07 14:01:51 +00:00
"github.com/aerogo/aero"
2019-11-17 07:48:27 +00:00
"github.com/aerogo/log"
2019-11-17 07:59:34 +00:00
"github.com/animenotifier/notify.moe/arn"
2019-05-07 14:01:51 +00:00
)
2017-06-11 09:13:59 +00:00
2019-11-17 07:48:27 +00:00
// Logout is called when the user clicks the logout button.
// It deletes the "userId" from the session.
func Logout(app *aero.Application, authLog *log.Log) {
2019-06-01 04:55:49 +00:00
app.Get("/logout", func(ctx aero.Context) error {
2017-06-17 20:19:26 +00:00
if ctx.HasSession() {
2019-11-17 07:59:34 +00:00
user := arn.GetUserFromContext(ctx)
2017-06-22 20:26:52 +00:00
if user != nil {
2019-06-01 04:55:49 +00:00
authLog.Info("%s logged out | %s | %s | %s | %s", user.Nick, user.ID, ctx.IP(), user.Email, user.RealName())
2017-06-22 20:26:52 +00:00
}
2019-05-16 10:15:37 +00:00
ctx.Session().Delete("userId")
2017-06-17 20:19:26 +00:00
}
2019-06-03 06:06:57 +00:00
return ctx.Redirect(http.StatusTemporaryRedirect, "/")
2017-06-15 19:59:14 +00:00
})
2017-06-11 09:13:59 +00:00
}