mirror of
https://github.com/m1k1o/neko.git
synced 2024-07-24 14:40:50 +12:00
use member id or create new.
This commit is contained in:
parent
123fbd8317
commit
5541675f57
@ -28,13 +28,20 @@ func (h *MembersHandler) membersCreate(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
id, err := utils.NewUID(32)
|
||||
if err != nil {
|
||||
if data.ID == "" {
|
||||
var err error
|
||||
if data.ID, err = utils.NewUID(32); err != nil {
|
||||
utils.HttpInternalServerError(w, err)
|
||||
return
|
||||
}
|
||||
} else {
|
||||
if _, ok := h.sessions.Get(data.ID); ok {
|
||||
utils.HttpBadRequest(w, "Member ID already exists.")
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
session := h.sessions.Create(id, types.MemberProfile{
|
||||
session := h.sessions.Create(data.ID, types.MemberProfile{
|
||||
Secret: data.Secret,
|
||||
Name: data.Name,
|
||||
IsAdmin: data.IsAdmin,
|
||||
@ -51,7 +58,7 @@ func (h *MembersHandler) membersRead(w http.ResponseWriter, r *http.Request) {
|
||||
utils.HttpSuccess(w, MemberDataPayload{
|
||||
ID: member.ID(),
|
||||
Name: member.Name(),
|
||||
IsAdmin: member.Admin(),
|
||||
IsAdmin: member.IsAdmin(),
|
||||
})
|
||||
}
|
||||
|
||||
@ -66,7 +73,7 @@ func (h *MembersHandler) membersUpdate(w http.ResponseWriter, r *http.Request) {
|
||||
utils.HttpSuccess(w, MemberDataPayload{
|
||||
ID: member.ID(),
|
||||
Name: member.Name(),
|
||||
IsAdmin: member.Admin(),
|
||||
IsAdmin: member.IsAdmin(),
|
||||
})
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user