mirror of
https://github.com/m1k1o/neko.git
synced 2024-07-24 14:40:50 +12:00
autogenerate token.
This commit is contained in:
parent
a6b66e4d55
commit
93ac4e8332
@ -65,7 +65,10 @@ func (h *MembersHandler) membersCreate(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
session, err := h.sessions.Create(data.ID, *data.MemberProfile)
|
// TODO: Refactor.
|
||||||
|
// data.ID
|
||||||
|
|
||||||
|
session, err := h.sessions.Create(*data.MemberProfile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
utils.HttpInternalServerError(w, err)
|
utils.HttpInternalServerError(w, err)
|
||||||
return
|
return
|
||||||
|
@ -30,10 +30,8 @@ func (api *ApiManagerCtx) Login(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
token := data.Secret
|
|
||||||
|
|
||||||
// TODO: Proper login.
|
// TODO: Proper login.
|
||||||
session, err := api.sessions.Create(token, types.MemberProfile{
|
session, err := api.sessions.Create(types.MemberProfile{
|
||||||
Name: data.ID,
|
Name: data.ID,
|
||||||
IsAdmin: true,
|
IsAdmin: true,
|
||||||
CanLogin: true,
|
CanLogin: true,
|
||||||
@ -55,7 +53,7 @@ func (api *ApiManagerCtx) Login(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
http.SetCookie(w, &http.Cookie{
|
http.SetCookie(w, &http.Cookie{
|
||||||
Name: "NEKO_SESSION",
|
Name: "NEKO_SESSION",
|
||||||
Value: token,
|
Value: session.ID(),
|
||||||
Expires: CookieExpirationDate,
|
Expires: CookieExpirationDate,
|
||||||
Secure: !UnsecureCookies,
|
Secure: !UnsecureCookies,
|
||||||
SameSite: sameSite,
|
SameSite: sameSite,
|
||||||
|
@ -35,9 +35,13 @@ type SessionManagerCtx struct {
|
|||||||
emmiter events.EventEmmiter
|
emmiter events.EventEmmiter
|
||||||
}
|
}
|
||||||
|
|
||||||
func (manager *SessionManagerCtx) Create(id string, profile types.MemberProfile) (types.Session, error) {
|
func (manager *SessionManagerCtx) Create(profile types.MemberProfile) (types.Session, error) {
|
||||||
manager.sessionsMu.Lock()
|
id, err := utils.NewUID(32)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
manager.sessionsMu.Lock()
|
||||||
_, ok := manager.sessions[id]
|
_, ok := manager.sessions[id]
|
||||||
if ok {
|
if ok {
|
||||||
manager.sessionsMu.Unlock()
|
manager.sessionsMu.Unlock()
|
||||||
|
@ -59,7 +59,7 @@ type Session interface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type SessionManager interface {
|
type SessionManager interface {
|
||||||
Create(id string, profile MemberProfile) (Session, error)
|
Create(profile MemberProfile) (Session, error)
|
||||||
Update(id string, profile MemberProfile) error
|
Update(id string, profile MemberProfile) error
|
||||||
Get(id string) (Session, bool)
|
Get(id string) (Session, bool)
|
||||||
Delete(id string) error
|
Delete(id string) error
|
||||||
|
Loading…
x
Reference in New Issue
Block a user