Implemented logout
This commit is contained in:
parent
1790bce104
commit
938057a626
20
google.go
20
google.go
@ -81,18 +81,22 @@ func EnableGoogleLogin(app *aero.Application) {
|
||||
return ctx.Error(http.StatusBadRequest, "Failed parsing user data (JSON)", err)
|
||||
}
|
||||
|
||||
// Try to find an existing user by the associated e-mail address
|
||||
email := googleUser.Email
|
||||
user, getErr := arn.GetUserByEmail(email)
|
||||
// Try to find an existing user by the Google user ID
|
||||
user, getErr := arn.GetUserFromTable("GoogleToUser", googleUser.Sub)
|
||||
|
||||
if getErr != nil {
|
||||
return ctx.Error(http.StatusForbidden, "Email not registered", err)
|
||||
if getErr == nil && user != nil {
|
||||
session.Set("userId", user.ID)
|
||||
return ctx.Redirect("/")
|
||||
}
|
||||
|
||||
// Login
|
||||
session.Set("userId", user.ID)
|
||||
// Try to find an existing user by the associated e-mail address
|
||||
user, getErr = arn.GetUserByEmail(googleUser.Email)
|
||||
|
||||
// Redirect back to frontpage
|
||||
if getErr == nil && user != nil {
|
||||
session.Set("userId", user.ID)
|
||||
return ctx.Redirect("/")
|
||||
}
|
||||
|
||||
return ctx.Error(http.StatusForbidden, "Account does not exist", err)
|
||||
})
|
||||
}
|
||||
|
@ -12,11 +12,11 @@ import (
|
||||
)
|
||||
|
||||
func init() {
|
||||
err := log.NewChannel("error")
|
||||
err := log.NewLog()
|
||||
err.AddOutput(log.File("logs/error.log"))
|
||||
err.AddOutput(os.Stderr)
|
||||
|
||||
request := log.NewChannel("request")
|
||||
request := log.NewLog()
|
||||
request.AddOutput(log.File("logs/request.log"))
|
||||
|
||||
app.Use(func(ctx *aero.Context, next func()) {
|
||||
|
6
login.go
6
login.go
@ -7,6 +7,12 @@ func EnableLogin(app *aero.Application) {
|
||||
// Google
|
||||
EnableGoogleLogin(app)
|
||||
|
||||
// Logout
|
||||
app.Get("/logout", func(ctx *aero.Context) string {
|
||||
ctx.Session().Set("userId", nil)
|
||||
return ctx.Redirect("/")
|
||||
})
|
||||
|
||||
// Session middleware
|
||||
app.Use(func(ctx *aero.Context, next func()) {
|
||||
// Handle the request first
|
||||
|
Loading…
Reference in New Issue
Block a user