Heavily improved sessions
This commit is contained in:
parent
340f4d1f9c
commit
15e2717ea8
@ -9,7 +9,10 @@ func Install(app *aero.Application) {
|
||||
|
||||
// Logout
|
||||
app.Get("/logout", func(ctx *aero.Context) string {
|
||||
ctx.Session().Set("userId", nil)
|
||||
if ctx.HasSession() {
|
||||
ctx.Session().Set("userId", nil)
|
||||
}
|
||||
|
||||
return ctx.Redirect("/")
|
||||
})
|
||||
}
|
||||
|
@ -50,6 +50,10 @@ func InstallGoogleAuth(app *aero.Application) {
|
||||
|
||||
// Auth Callback
|
||||
app.Get("/auth/google/callback", func(ctx *aero.Context) string {
|
||||
if !ctx.HasSession() {
|
||||
return ctx.Error(http.StatusUnauthorized, "Session does not exist", errors.New("Google login failed: Session does not exist"))
|
||||
}
|
||||
|
||||
session := ctx.Session()
|
||||
|
||||
if session.ID() != ctx.Query("state") {
|
||||
|
5
main.go
5
main.go
@ -31,8 +31,9 @@ func main() {
|
||||
// CSS
|
||||
app.SetStyle(components.CSS())
|
||||
|
||||
// Session store
|
||||
app.Sessions.Store = arn.NewAerospikeStore("Session")
|
||||
// Sessions
|
||||
app.Sessions.Duration = 3600 * 24
|
||||
app.Sessions.Store = arn.NewAerospikeStore("Session", app.Sessions.Duration)
|
||||
|
||||
// Layout
|
||||
app.Layout = layout.Render
|
||||
|
@ -6,6 +6,6 @@ component FrontPage
|
||||
p
|
||||
a(href="https://github.com/animenotifier/notify.moe", target="_blank", rel="noopener") Source on GitHub
|
||||
|
||||
//- .login-buttons
|
||||
//- a.login-button(href="/auth/google")
|
||||
//- img.login-button-image(src="/images/login/google", alt="Google Login", title="Login with your Google account")
|
||||
.login-buttons
|
||||
a.login-button(href="/auth/google")
|
||||
img.login-button-image(src="/images/login/google", alt="Google Login", title="Login with your Google account")
|
@ -7,6 +7,10 @@ import (
|
||||
|
||||
// GetUser ...
|
||||
func GetUser(ctx *aero.Context) *arn.User {
|
||||
if !ctx.HasSession() {
|
||||
return nil
|
||||
}
|
||||
|
||||
userID := ctx.Session().GetString("userId")
|
||||
|
||||
if userID == "" {
|
||||
|
Loading…
Reference in New Issue
Block a user