mirror of
https://github.com/m1k1o/neko.git
synced 2024-07-24 14:40:50 +12:00
login username password.
This commit is contained in:
parent
5101f0a9c3
commit
7d4f7694b9
@ -42,11 +42,6 @@ func (h *MembersHandler) membersCreate(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if data.Secret == "" {
|
|
||||||
utils.HttpBadRequest(w, "Secret cannot be empty.")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if data.Name == "" {
|
if data.Name == "" {
|
||||||
utils.HttpBadRequest(w, "Name cannot be empty.")
|
utils.HttpBadRequest(w, "Name cannot be empty.")
|
||||||
return
|
return
|
||||||
|
@ -14,11 +14,11 @@ var CookieExpirationDate = time.Now().Add(365 * 24 * time.Hour)
|
|||||||
var UnsecureCookies = os.Getenv("DISABLE_SECURE_COOKIES") == "true"
|
var UnsecureCookies = os.Getenv("DISABLE_SECURE_COOKIES") == "true"
|
||||||
|
|
||||||
type SessionLoginPayload struct {
|
type SessionLoginPayload struct {
|
||||||
ID string `json:"id"`
|
Username string `json:"username"`
|
||||||
Secret string `json:"secret"`
|
Password string `json:"password"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type SessionWhoamiPayload struct {
|
type SessionDataPayload struct {
|
||||||
ID string `json:"id"`
|
ID string `json:"id"`
|
||||||
Profile types.MemberProfile `json:"profile"`
|
Profile types.MemberProfile `json:"profile"`
|
||||||
State types.SessionState `json:"state"`
|
State types.SessionState `json:"state"`
|
||||||
@ -31,8 +31,8 @@ func (api *ApiManagerCtx) Login(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Proper login.
|
// TODO: Proper login.
|
||||||
session, token, err := api.sessions.Create(data.ID, types.MemberProfile{
|
session, token, err := api.sessions.Create(data.Username, types.MemberProfile{
|
||||||
Name: data.ID,
|
Name: data.Username,
|
||||||
IsAdmin: true,
|
IsAdmin: true,
|
||||||
CanLogin: true,
|
CanLogin: true,
|
||||||
CanConnect: true,
|
CanConnect: true,
|
||||||
@ -60,7 +60,7 @@ func (api *ApiManagerCtx) Login(w http.ResponseWriter, r *http.Request) {
|
|||||||
HttpOnly: true,
|
HttpOnly: true,
|
||||||
})
|
})
|
||||||
|
|
||||||
utils.HttpSuccess(w, SessionWhoamiPayload{
|
utils.HttpSuccess(w, SessionDataPayload{
|
||||||
ID: session.ID(),
|
ID: session.ID(),
|
||||||
Profile: session.GetProfile(),
|
Profile: session.GetProfile(),
|
||||||
State: session.GetState(),
|
State: session.GetState(),
|
||||||
@ -97,7 +97,7 @@ func (api *ApiManagerCtx) Logout(w http.ResponseWriter, r *http.Request) {
|
|||||||
func (api *ApiManagerCtx) Whoami(w http.ResponseWriter, r *http.Request) {
|
func (api *ApiManagerCtx) Whoami(w http.ResponseWriter, r *http.Request) {
|
||||||
session := auth.GetSession(r)
|
session := auth.GetSession(r)
|
||||||
|
|
||||||
utils.HttpSuccess(w, SessionWhoamiPayload{
|
utils.HttpSuccess(w, SessionDataPayload{
|
||||||
ID: session.ID(),
|
ID: session.ID(),
|
||||||
Profile: session.GetProfile(),
|
Profile: session.GetProfile(),
|
||||||
State: session.GetState(),
|
State: session.GetState(),
|
||||||
|
@ -56,9 +56,7 @@ func (session *SessionCtx) CanAccessClipboard() bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (session *SessionCtx) GetProfile() types.MemberProfile {
|
func (session *SessionCtx) GetProfile() types.MemberProfile {
|
||||||
profile := session.profile
|
return session.profile
|
||||||
profile.Secret = ""
|
|
||||||
return profile
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (session *SessionCtx) profileChanged() {
|
func (session *SessionCtx) profileChanged() {
|
||||||
|
@ -3,7 +3,6 @@ package types
|
|||||||
import "net/http"
|
import "net/http"
|
||||||
|
|
||||||
type MemberProfile struct {
|
type MemberProfile struct {
|
||||||
Secret string `json:"secret,omitempty"`
|
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
IsAdmin bool `json:"is_admin"`
|
IsAdmin bool `json:"is_admin"`
|
||||||
CanLogin bool `json:"can_login"`
|
CanLogin bool `json:"can_login"`
|
||||||
|
Loading…
Reference in New Issue
Block a user