flyve-mdm / web-mdm-dashboard

New generation of the Flyve MDM Dashboard
http://flyve.org/web-mdm-dashboard/
GNU General Public License v3.0
85 stars 50 forks source link

Profiles pictures #279

Closed Gianfranco97 closed 6 years ago

Gianfranco97 commented 6 years ago

Expected behavior:

It is necessary to get a way to render the profile images of the user in the dashboard.   For the avatar in the list use this format: https://dev.flyve.org/glpi/front/document.send.php?file=_pictures/24/221_5a084effc6624_min.jpg

For the avatar in the user page us this format: https://dev.flyve.org/glpi/front/document.send.php?file=_pictures/24/221_5a084effc6624.jpg

There is a problem with these links and it is the lack of a session cookie in the request. This has a format similar to the following:

glpi_30b8c5aa4d3246b20f0eae2e09f476fa = f05cgo5i7g2cprpci8la8dtqi1

This is returned by the backend at the time of making a login

captura de pantalla 2018-01-31 a la s 2 41 23 p m

Reference: https://github.com/flyve-mdm/web-mdm-dashboard/issues/20

ajsb85 commented 6 years ago

You must request it via the Document itemtype

Gianfranco97 commented 6 years ago

@ajsb85 Yes I know, but I still need the id of the document.

Ref: https://dev.flyve.org/glpi/apirest.php#special-cases

btry commented 6 years ago

Curently the REST API does not allows to get the user picture.

I think we can workaround until the API satisfies this need.

Here is the HTML code to get the user picture when we use the GLPI UI

<img class="user_picture_small" alt="Image" src="/glpi-flyvemdm-92/front/document.send.php?file=_pictures/f2/2_5a6b3e06acef2_min.jpg">

Take inspiration from this, and inspect in the GLPI UI how is built the cookie. I know the session token is the value used in the cookie. Then, you can build a cookie for the above mentioned request and you can download the raw picture.

ajsb85 commented 6 years ago
`${url_base_api}/initSession`
// Store: ${session_token}

`${url_base_api}/getGlpiConfig`
// Store: ${url_base} & ${url_base_api}

`${url_base_api}/User/:id`
// Store: ${picture}
// Generate Thumbnail URL with the suffix _min.jpg
// Store: ${picture_thumbnail}

fetch(`${url_base}`, {
    method: 'HEAD'
})

// Change the value of the cookie with start in glpi_ with the ${session_token}

fetch(`${url_base}/front/document.send.php?file=_pictures/a5/${picture}`, {
    method: 'GET',
    credentials: 'same-origin'
})

fetch(`${url_base}/front/document.send.php?file=_pictures/a5/${picture_thumbnail}`, {
    method: 'GET',
    credentials: 'same-origin'
})