| 1 |
= cockpit.js: User Session |
| 2 |
|
| 3 |
User information and login session state |
| 4 |
|
| 5 |
[[cockpit-logout]] |
| 6 |
== cockpit.logout() |
| 7 |
|
| 8 |
.... |
| 9 |
cockpit.logout([reload]) |
| 10 |
.... |
| 11 |
|
| 12 |
Logout of Cockpit. Unless `+reload+` is `+false+` this will also cause |
| 13 |
the page to be reloaded, so that the user can see the logged out state. |
| 14 |
|
| 15 |
[[cockpit-user]] |
| 16 |
== cockpit.user() |
| 17 |
|
| 18 |
.... |
| 19 |
var promise = cockpit.user(); |
| 20 |
promise.then(user => { ... }); |
| 21 |
.... |
| 22 |
|
| 23 |
This object contains information about the user that's currently logged |
| 24 |
into cockpit. The following fields are defined: |
| 25 |
|
| 26 |
`+"id"+`:: |
| 27 |
This is unix user id. |
| 28 |
`+"gid"+`:: |
| 29 |
This is unix user group id. |
| 30 |
`+"name"+`:: |
| 31 |
This is the unix user name like `+"root"+`. |
| 32 |
`+"full_name"+`:: |
| 33 |
This is a readable name for the user. |
| 34 |
`+"groups"+`:: |
| 35 |
This is an array of group names to which the user belongs. Since |
| 36 |
version 318, the first item in this list is the primary group. |
| 37 |
`+"home"+`:: |
| 38 |
This is user's home directory. |
| 39 |
`+"shell"+`:: |
| 40 |
This is unix user shell. |
| 41 |
|
| 42 |
Returns a promise that completes once the user information is available. |
| 43 |
|
| 44 |
[WARNING] |
| 45 |
==== |
| 46 |
`+cockpit.user()+` is soft-deprecated since Cockpit 336, if your page |
| 47 |
does not need to maintain compatibility with older Cockpit versions you |
| 48 |
can use xref:cockpit-util.adoc#cockpit-info[cockpit.info] to obtain the user information. |
| 49 |
==== |
| 50 |
|
| 51 |
[[cockpit-permission]] |
| 52 |
== Permission lookup |
| 53 |
|
| 54 |
Cockpit provides a mechanism for checking if the current user satisfies |
| 55 |
a given criteria. This is meant for updating UI elements based on what |
| 56 |
actions the user can perform. It is _not an access control mechanism_. |
| 57 |
|
| 58 |
[[cockpit-permission-constructor]] |
| 59 |
=== cockpit.permission() |
| 60 |
|
| 61 |
.... |
| 62 |
permission = cockpit.permission([options]) |
| 63 |
.... |
| 64 |
|
| 65 |
Create a new permission object to check if the current user has a |
| 66 |
particular permission specified by `+options+`: |
| 67 |
|
| 68 |
`+admin: true+`:: |
| 69 |
True if the session has superuser privileges, i.e. can run channels as |
| 70 |
root with `+{ superuser: "require" }+`. |
| 71 |
`+group:+` _name_:: |
| 72 |
True if the currently logged user is a member of group _name_. |
| 73 |
|
| 74 |
The permission result is always true for the "root" user. When |
| 75 |
`+options+` is not given, check if the current user is root. |
| 76 |
|
| 77 |
[[cockpit-permission-allowed]] |
| 78 |
=== permission.allowed |
| 79 |
|
| 80 |
A boolean value which indicates if the permission is allowed or not. |
| 81 |
This will be `+null+` if the permission is unknown, or there was an |
| 82 |
error checking the permission or the permission data has not yet loaded. |
| 83 |
This property will update asynchronously and if you wish to be notified |
| 84 |
of changes connect to the |
| 85 |
link:#cockpit-permission-changed[permission.onchanged] event. |
| 86 |
|
| 87 |
[[cockpit-permission-changed]] |
| 88 |
=== permission.onchanged |
| 89 |
|
| 90 |
.... |
| 91 |
permission.addEventListener("changed", function() { ... }) |
| 92 |
.... |
| 93 |
|
| 94 |
This event is fired when the permission changes. In particular the |
| 95 |
link:#cockpit-permission-allowed[permission.allowed] property. |
| 96 |
|
| 97 |
[[cockpit-permission-close]] |
| 98 |
=== permission.close() |
| 99 |
|
| 100 |
.... |
| 101 |
permission.close() |
| 102 |
.... |
| 103 |
|
| 104 |
Closes the permission object and tears down any registered callbacks and |
| 105 |
dbus subscriptions. |