2017-06-17 01:32:47 +02:00
|
|
|
package auth
|
2017-06-11 11:13:59 +02:00
|
|
|
|
2019-05-07 23:01:51 +09:00
|
|
|
import (
|
2019-06-01 13:55:49 +09:00
|
|
|
"net/http"
|
|
|
|
|
2019-05-07 23:01:51 +09:00
|
|
|
"github.com/aerogo/aero"
|
2019-11-17 16:48:27 +09:00
|
|
|
"github.com/aerogo/log"
|
2019-11-17 16:59:34 +09:00
|
|
|
"github.com/animenotifier/notify.moe/arn"
|
2019-05-07 23:01:51 +09:00
|
|
|
)
|
2017-06-11 11:13:59 +02:00
|
|
|
|
2019-11-17 16:48:27 +09: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 13:55:49 +09:00
|
|
|
app.Get("/logout", func(ctx aero.Context) error {
|
2017-06-17 22:19:26 +02:00
|
|
|
if ctx.HasSession() {
|
2019-11-17 16:59:34 +09:00
|
|
|
user := arn.GetUserFromContext(ctx)
|
2017-06-22 22:26:52 +02:00
|
|
|
|
|
|
|
if user != nil {
|
2019-06-01 13:55:49 +09:00
|
|
|
authLog.Info("%s logged out | %s | %s | %s | %s", user.Nick, user.ID, ctx.IP(), user.Email, user.RealName())
|
2017-06-22 22:26:52 +02:00
|
|
|
}
|
|
|
|
|
2019-05-16 19:15:37 +09:00
|
|
|
ctx.Session().Delete("userId")
|
2017-06-17 22:19:26 +02:00
|
|
|
}
|
|
|
|
|
2019-06-03 15:06:57 +09:00
|
|
|
return ctx.Redirect(http.StatusTemporaryRedirect, "/")
|
2017-06-15 21:59:14 +02:00
|
|
|
})
|
2017-06-11 11:13:59 +02:00
|
|
|
}
|