.. _account_endpoint:


Account Endpoint
----------------

.. _19.1.1| EKB-1281:

The ``<hostname>/account`` endpoint provides addiotnal endpoints:

* ``<hostname>/account/me/`` : returns user details
* ``<hostname>/account/password/`` : allows for password management



Logged-in User Details
......................

The following request and endpoint is available on the API to return
logged-in user details: 

* Request:

  ::

     GET <hostname>/account/me/?format=json


If the request is successful:

* the HTTP response is 200
* the JSON body contains user account details,
  as shown in the example snippet below: 
  

::

   {
     "username": "CS-PAdmin",
     "menu_layout": {
       "pkid": "5c7daa2a7579050013878f83",
       "href": "/api/data/MenuLayout/5c7daa2a7579050013878f83/",
       "name": "HcsProviderMenu"
     },
     "language": "en-us",
     "landing_page": {
       "pkid": "5c7daa157579050013878d88",
       "href": "/api/data/LandingPage/5c7daa157579050013878d88/",
       "name": "HcsProviderLP"
     },
     "pkid": "5c7db7c5757905001387e6a1",
     "account_information": {
       "password_last_change_time": "2019-03-05T00:54:27.277Z",
       "last_login_time": "2019-03-05T08:01:11.184Z"
     },
     "hierarchy": {
       "pkid": "5c7db7b5757905001387e2d6",
       "node_type": "Provider",
       "href": "/api/data/HierarchyNode/5c7db7b5757905001387e2d6/",
       "name": "CS-P",
       "hierarchy_path": "sys.hcs.CS-P"
     },
     "theme": {
       "pkid": "5c7db13d757905001387c33b",
       "href": "/api/data/Theme/5c7db13d757905001387c33b/",
       "name": "default"
     },
     "role": {
     
     ...

Password Change
...............

An API endpoint is available to request the details needed for a user password 
change and to submit a password change.

To get details of the POST request and the JSON schema of the payload to
change the password, use the request:

::

   GET https://hostname/account/password/change?hierarchy=[hierarchy]&format=json


To change a user password, the request will then be of the format:

::

   POST https://hostname/account/password/change?hierarchy=[hierarchy]&format=json

The payload is in JSON format and contains user details, old password and new password.

A successful password change request returns a response of the format:

::

   {"meta": {
        "uri": "/account/password/change/"
        }, 
        "success": true
   }


The request format if a user changes their own password on the GUI,
payload parameters include the token, for example:

::

   csrfmiddlewaretoken=am9lOmJsb2dncw==

In this instance, the ``user_pkid`` a part of the payload, as it is
hidden in the GUI.

For a successful password change from the GUI, the user's
browser client is redirected to the endpoint:

::

   https://hostname/account/password/change/done/
  

This presents the user with a message and request to log in with the 
new password.


.. |VOSS-4-UC| replace:: VOSS-4-UC
.. |Unified CM| replace:: Unified CM