forked from pterodactyl/panel
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuser.js
More file actions
51 lines (50 loc) · 1.32 KB
/
user.js
File metadata and controls
51 lines (50 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
export default class User {
/**
* Get a new user model by hitting the Panel API using the authentication token
* provided. If no user can be retrieved null will be returned.
*
* @param {string} token
* @param {string} cookie
* @return {User|null}
*/
static fromCookie(token, cookie = 'pterodactyl_session') {
window.axios.get('/api/client/account', {
headers: {
Cookie: `${cookie}=${token}`,
}
})
.then(response => {
return new User(response.data.attributes);
})
.catch(err => {
console.error(err);
return null;
})
}
/**
* Create a new user model.
*
* @param {Boolean} admin
* @param {String} username
* @param {String} email
* @param {String} first_name
* @param {String} last_name
* @param {String} language
*/
constructor({
admin,
username,
email,
first_name,
last_name,
language,
}) {
this.admin = admin;
this.username = username;
this.email = email;
this.name = `${first_name} ${last_name}`;
this.first_name = first_name;
this.last_name = last_name;
this.language = language;
}
}