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
|
||||
}
|
||||
|
||||
if data.Secret == "" {
|
||||
utils.HttpBadRequest(w, "Secret cannot be empty.")
|
||||
return
|
||||
}
|
||||
|
||||
if data.Name == "" {
|
||||
utils.HttpBadRequest(w, "Name cannot be empty.")
|
||||
return
|
||||
|
@ -14,11 +14,11 @@ var CookieExpirationDate = time.Now().Add(365 * 24 * time.Hour)
|
||||
var UnsecureCookies = os.Getenv("DISABLE_SECURE_COOKIES") == "true"
|
||||
|
||||
type SessionLoginPayload struct {
|
||||
ID string `json:"id"`
|
||||
Secret string `json:"secret"`
|
||||
Username string `json:"username"`
|
||||
Password string `json:"password"`
|
||||
}
|
||||
|
||||
type SessionWhoamiPayload struct {
|
||||
type SessionDataPayload struct {
|
||||
ID string `json:"id"`
|
||||
Profile types.MemberProfile `json:"profile"`
|
||||
State types.SessionState `json:"state"`
|
||||
@ -31,8 +31,8 @@ func (api *ApiManagerCtx) Login(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
// TODO: Proper login.
|
||||
session, token, err := api.sessions.Create(data.ID, types.MemberProfile{
|
||||
Name: data.ID,
|
||||
session, token, err := api.sessions.Create(data.Username, types.MemberProfile{
|
||||
Name: data.Username,
|
||||
IsAdmin: true,
|
||||
CanLogin: true,
|
||||
CanConnect: true,
|
||||
@ -60,7 +60,7 @@ func (api *ApiManagerCtx) Login(w http.ResponseWriter, r *http.Request) {
|
||||
HttpOnly: true,
|
||||
})
|
||||
|
||||
utils.HttpSuccess(w, SessionWhoamiPayload{
|
||||
utils.HttpSuccess(w, SessionDataPayload{
|
||||
ID: session.ID(),
|
||||
Profile: session.GetProfile(),
|
||||
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) {
|
||||
session := auth.GetSession(r)
|
||||
|
||||
utils.HttpSuccess(w, SessionWhoamiPayload{
|
||||
utils.HttpSuccess(w, SessionDataPayload{
|
||||
ID: session.ID(),
|
||||
Profile: session.GetProfile(),
|
||||
State: session.GetState(),
|
||||
|
@ -56,9 +56,7 @@ func (session *SessionCtx) CanAccessClipboard() bool {
|
||||
}
|
||||
|
||||
func (session *SessionCtx) GetProfile() types.MemberProfile {
|
||||
profile := session.profile
|
||||
profile.Secret = ""
|
||||
return profile
|
||||
return session.profile
|
||||
}
|
||||
|
||||
func (session *SessionCtx) profileChanged() {
|
||||
|
@ -3,7 +3,6 @@ package types
|
||||
import "net/http"
|
||||
|
||||
type MemberProfile struct {
|
||||
Secret string `json:"secret,omitempty"`
|
||||
Name string `json:"name"`
|
||||
IsAdmin bool `json:"is_admin"`
|
||||
CanLogin bool `json:"can_login"`
|
||||
|
Loading…
Reference in New Issue
Block a user