Message ID send from Client
Remove commentary code Correct Empty answer
This commit is contained in:
parent
815e9bfe2a
commit
0ca6a159b2
38
directory.go
38
directory.go
@ -34,6 +34,10 @@ type Results struct {
|
||||
MessageID uint32 `json:"id"`
|
||||
}
|
||||
|
||||
type UniqueID struct {
|
||||
Id int `json:"id"`
|
||||
}
|
||||
|
||||
func handleSearch(w http.ResponseWriter, r *http.Request) {
|
||||
//Get input value by user
|
||||
input := mux.Vars(r)["input"]
|
||||
@ -43,10 +47,10 @@ func handleSearch(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
session, err := store.Get(r, SESSION_NAME)
|
||||
/**session, err := store.Get(r, SESSION_NAME)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
}**/
|
||||
|
||||
//Search values with ldap and filter
|
||||
searchRequest := ldap.NewSearchRequest(
|
||||
@ -79,21 +83,27 @@ func handleSearch(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//Convert interface to uint32 with Type Assertions and not a simple convert for messageID
|
||||
if val_Raw, ok_raw := session.Values["MessageID"]; ok_raw {
|
||||
if val, ok := val_Raw.(uint32); ok {
|
||||
val += 1
|
||||
session.Values["MessageID"] = val
|
||||
result.MessageID = val
|
||||
err = session.Save(r, w)
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
if result.Search == nil {
|
||||
result = Results{
|
||||
Search: append(result.Search, SearchResult{
|
||||
Identifiant: "",
|
||||
Name: "",
|
||||
Email: "",
|
||||
Description: "",
|
||||
DN: "",
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
var id UniqueID
|
||||
//Decode JSON body
|
||||
err = json.NewDecoder(r.Body).Decode(&id)
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
result.MessageID = uint32(id.Id)
|
||||
|
||||
//Send JSON through xhttp
|
||||
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
|
||||
w.WriteHeader(http.StatusCreated)
|
||||
|
@ -1,4 +1,5 @@
|
||||
var perso_id = 0;
|
||||
var last_id = 0;
|
||||
|
||||
function searchDirectory() {
|
||||
var input = document.getElementById("search").value;
|
||||
@ -10,8 +11,8 @@ function searchDirectory() {
|
||||
//Response from Request Ajax
|
||||
var jsonResponse = JSON.parse(xhttp.responseText);
|
||||
|
||||
if (perso_id < jsonResponse.id) {
|
||||
perso_id = jsonResponse.id
|
||||
if (last_id < jsonResponse.id) {
|
||||
last_id = jsonResponse.id
|
||||
//We get the old table element, we create an new table element then we increment this new table.
|
||||
//After the new add, we replace the old table by the new one.
|
||||
var old_table = document.getElementById("users");
|
||||
@ -29,19 +30,16 @@ function searchDirectory() {
|
||||
identifiant.innerHTML = `<a href="/admin/ldap/${jsonResponse.search[i].dn}">${jsonResponse.search[i].identifiant}</a>`
|
||||
name.innerHTML = jsonResponse.search[i].name
|
||||
email.innerHTML = jsonResponse.search[i].email
|
||||
description.innerHTML = `${jsonResponse.search[i].description}`
|
||||
description.innerHTML = jsonResponse.search[i].description
|
||||
|
||||
}
|
||||
old_table.parentNode.replaceChild(table, old_table)
|
||||
}
|
||||
}
|
||||
};
|
||||
perso_id += 1
|
||||
xhttp.overrideMimeType("application/json");
|
||||
xhttp.open("GET", "/search/".concat(input), true);
|
||||
xhttp.send();
|
||||
xhttp.open("POST", "/search/".concat(input), true);
|
||||
xhttp.send(JSON.stringify({"id": perso_id}));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user