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 {
|
||||
user = &User{Name: username}
|
||||
if err = DbUserGetByName(ctx, user); err != nil {
|
||||
http.Error(response, "bad login1", http.StatusUnauthorized)
|
||||
http.Error(response, "bad login", http.StatusUnauthorized)
|
||||
return
|
||||
}
|
||||
if err = DbUserGetGroups(ctx, user); err != nil {
|
||||
http.Error(response, "bad login1", http.StatusUnauthorized)
|
||||
http.Error(response, "bad login", http.StatusUnauthorized)
|
||||
return
|
||||
}
|
||||
if err = DbUserGetConnections(ctx, user); err != nil {
|
||||
http.Error(response, "bad login1", http.StatusUnauthorized)
|
||||
http.Error(response, "bad login", http.StatusUnauthorized)
|
||||
return
|
||||
}
|
||||
CacheSaveUser(user)
|
||||
@@ -482,7 +482,7 @@ func HttpHandleTokenNew(response http.ResponseWriter, request *http.Request) {
|
||||
|
||||
err = bcrypt.CompareHashAndPassword([]byte(user.PasswordHash), []byte(password))
|
||||
if err != nil {
|
||||
http.Error(response, "bad login2", http.StatusUnauthorized)
|
||||
http.Error(response, "bad login", http.StatusUnauthorized)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -492,8 +492,10 @@ func HttpHandleTokenNew(response http.ResponseWriter, request *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
json, err := json2.Marshal(LoginReturn{Token: token, UserId: user.Id})
|
||||
|
||||
response.WriteHeader(http.StatusCreated)
|
||||
response.Write([]byte(token))
|
||||
response.Write([]byte(json))
|
||||
}
|
||||
|
||||
func HttpHandeGroupCreate(response http.ResponseWriter, request *http.Request) {
|
||||
|
||||
Reference in New Issue
Block a user