forked from phc/website
Added logout and some logging
This commit is contained in:
@@ -1,5 +1,9 @@
|
||||
package auth
|
||||
|
||||
import "fmt"
|
||||
|
||||
var ErrInvalidSession = fmt.Errorf(`invalid session token`)
|
||||
|
||||
type User interface {
|
||||
GetUsername() string
|
||||
GetName() string
|
||||
|
||||
+9
-1
@@ -4,6 +4,7 @@ import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
"path"
|
||||
"time"
|
||||
@@ -59,15 +60,22 @@ func (a *LDAPAuthService) doGetRequest(url string, response interface{}) error {
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
log.Printf(`GET %q resulted in %v`, url, err)
|
||||
return err
|
||||
}
|
||||
|
||||
res, err := http.DefaultClient.Do(req)
|
||||
if err != nil {
|
||||
log.Printf(`GET %q resulted in %v`, url, err)
|
||||
return err
|
||||
}
|
||||
|
||||
return json.NewDecoder(res.Body).Decode(response)
|
||||
if err := json.NewDecoder(res.Body).Decode(response); err != nil {
|
||||
log.Printf(`GET %q resulted in %v`, url, err)
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a *LDAPAuthService) doPostRequest(url string, request interface{}, response interface{}) error {
|
||||
|
||||
+1
-1
@@ -89,7 +89,7 @@ func (m *Memory) GetUsers() ([]User, error) {
|
||||
func (m *Memory) GetSession(token string) (Session, error) {
|
||||
session, ok := m.Sessions[token]
|
||||
if !ok {
|
||||
return nil, fmt.Errorf(`invalid session token`)
|
||||
return nil, ErrInvalidSession
|
||||
}
|
||||
|
||||
return session, nil
|
||||
|
||||
@@ -147,7 +147,7 @@ func main() {
|
||||
app.Get("/profilo", func(c *fiber.Ctx) error {
|
||||
user, ok := c.Locals("user").(auth.User)
|
||||
if !ok || user == nil {
|
||||
return fmt.Errorf(`no logged in user`)
|
||||
return fmt.Errorf(`user not logged in`)
|
||||
}
|
||||
|
||||
c.Type("html")
|
||||
@@ -156,6 +156,16 @@ func main() {
|
||||
})
|
||||
})
|
||||
|
||||
app.Get("/logout", func(c *fiber.Ctx) error {
|
||||
c.Cookie(&fiber.Cookie{
|
||||
Name: "session-token",
|
||||
Path: "/",
|
||||
Value: "",
|
||||
Expires: time.Now(),
|
||||
})
|
||||
return c.Redirect("/")
|
||||
})
|
||||
|
||||
app.Get("/news/:article", func(c *fiber.Ctx) error {
|
||||
articleID := c.Params("article")
|
||||
|
||||
|
||||
@@ -9,6 +9,9 @@
|
||||
<p>
|
||||
Lorem ipsum dolor sit amet consectetur adipisicing elit. Quae earum amet delectus cumque obcaecati minus quos aliquid fugiat reprehenderit voluptatum?
|
||||
</p>
|
||||
<p class="center">
|
||||
<a href="/logout">Logout</a>
|
||||
</p>
|
||||
<h2>Recupero Credenziali Poisson</h2>
|
||||
<p>
|
||||
Per il recupero credenziali vieni direttamente al PHC a parlarne con calma con noi altrimenti puoi inviaci una email all'indirizzo <a href="mailto:{{ .Config.Email }}">{{ .Config.Email }}</a> e poi recuperare le nuove credenziali sul sito <a href="https://credenziali.phc.dm.unipi.it/">credenziali.phc.dm.unipi.it</a>.
|
||||
|
||||
Reference in New Issue
Block a user