|
|
@ -3,6 +3,7 @@ package controllers |
|
|
|
import ( |
|
|
|
"encoding/json" |
|
|
|
"net/http" |
|
|
|
"time" |
|
|
|
|
|
|
|
"git.aiterp.net/lucifer/lucifer/internal/respond" |
|
|
|
"git.aiterp.net/lucifer/lucifer/models" |
|
|
@ -16,7 +17,10 @@ type UserController struct { |
|
|
|
|
|
|
|
// getUsers (`GET /`): List users
|
|
|
|
func (c *UserController) getUsers(w http.ResponseWriter, r *http.Request) { |
|
|
|
// TODO: Check session
|
|
|
|
if session := models.SessionFromContext(r.Context()); session == nil { |
|
|
|
respond.Error(w, 403, "permission_denied", "You must log in") |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
users, err := c.users.List(r.Context()) |
|
|
|
if err != nil { |
|
|
@ -51,7 +55,13 @@ func (c *UserController) login(w http.ResponseWriter, r *http.Request) { |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
// TODO: Open session
|
|
|
|
session := models.Session{ |
|
|
|
Expires: time.Now().Add(7 * 24 * time.Hour), |
|
|
|
UserID: user.ID, |
|
|
|
} |
|
|
|
session.GenerateID() |
|
|
|
|
|
|
|
http.SetCookie(w, session.Cookie()) |
|
|
|
|
|
|
|
respond.JSON(w, 200, user) |
|
|
|
} |
|
|
|