make login return id of user also
This commit is contained in:
@@ -466,15 +466,15 @@ func HttpHandleTokenNew(response http.ResponseWriter, request *http.Request) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
user = &User{Name: username}
|
user = &User{Name: username}
|
||||||
if err = DbUserGetByName(ctx, user); err != nil {
|
if err = DbUserGetByName(ctx, user); err != nil {
|
||||||
http.Error(response, "bad login1", http.StatusUnauthorized)
|
http.Error(response, "bad login", http.StatusUnauthorized)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if err = DbUserGetGroups(ctx, user); err != nil {
|
if err = DbUserGetGroups(ctx, user); err != nil {
|
||||||
http.Error(response, "bad login1", http.StatusUnauthorized)
|
http.Error(response, "bad login", http.StatusUnauthorized)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if err = DbUserGetConnections(ctx, user); err != nil {
|
if err = DbUserGetConnections(ctx, user); err != nil {
|
||||||
http.Error(response, "bad login1", http.StatusUnauthorized)
|
http.Error(response, "bad login", http.StatusUnauthorized)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
CacheSaveUser(user)
|
CacheSaveUser(user)
|
||||||
@@ -482,7 +482,7 @@ func HttpHandleTokenNew(response http.ResponseWriter, request *http.Request) {
|
|||||||
|
|
||||||
err = bcrypt.CompareHashAndPassword([]byte(user.PasswordHash), []byte(password))
|
err = bcrypt.CompareHashAndPassword([]byte(user.PasswordHash), []byte(password))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(response, "bad login2", http.StatusUnauthorized)
|
http.Error(response, "bad login", http.StatusUnauthorized)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -492,8 +492,10 @@ func HttpHandleTokenNew(response http.ResponseWriter, request *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
json, err := json2.Marshal(LoginReturn{Token: token, UserId: user.Id})
|
||||||
|
|
||||||
response.WriteHeader(http.StatusCreated)
|
response.WriteHeader(http.StatusCreated)
|
||||||
response.Write([]byte(token))
|
response.Write([]byte(json))
|
||||||
}
|
}
|
||||||
|
|
||||||
func HttpHandeGroupCreate(response http.ResponseWriter, request *http.Request) {
|
func HttpHandeGroupCreate(response http.ResponseWriter, request *http.Request) {
|
||||||
|
|||||||
@@ -35,3 +35,8 @@ type Group struct {
|
|||||||
Color [3]uint8 `json:"color"`
|
Color [3]uint8 `json:"color"`
|
||||||
EnableUserColors bool `json:"enableUserColors"`
|
EnableUserColors bool `json:"enableUserColors"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type LoginReturn struct {
|
||||||
|
Token string `json:"token"`
|
||||||
|
UserId uint32 `json:"userId"`
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user