1
0
Fork 0
mirror of synced 2024-08-08 14:58:47 +12:00
appwrite/app/sdks/node/lib/services/account.js

187 lines
4.5 KiB
JavaScript
Raw Normal View History

2019-06-10 06:13:55 +12:00
const Service = require('../service.js');
class Account extends Service {
/**
* Get Account
*
2019-10-09 21:40:02 +13:00
* Get currently logged in user data as JSON object.
2019-06-10 06:13:55 +12:00
*
* @throws Exception
* @return {}
*/
async get() {
let path = '/account';
2019-10-20 06:21:36 +13:00
return await this.client.call('get', path, {
'content-type': 'application/json',
},
{
2019-06-10 06:13:55 +12:00
});
}
/**
* Delete Account
*
2019-10-09 21:40:02 +13:00
* Delete currently logged in user account.
2019-06-10 06:13:55 +12:00
*
* @throws Exception
* @return {}
*/
async delete() {
let path = '/account';
2019-10-20 06:21:36 +13:00
return await this.client.call('delete', path, {
'content-type': 'application/json',
},
{
2019-06-10 06:13:55 +12:00
});
}
/**
* Update Account Email
*
2019-10-09 21:40:02 +13:00
* Update currently logged in user account email address. After changing user
* address, user confirmation status is being reset and a new confirmation
* mail is sent. For security measures, user password is required to complete
* this request.
2019-06-10 06:13:55 +12:00
*
* @param string email
* @param string password
* @throws Exception
* @return {}
*/
async updateEmail(email, password) {
let path = '/account/email';
2019-10-20 06:21:36 +13:00
return await this.client.call('patch', path, {
'content-type': 'application/json',
},
{
2019-06-10 06:13:55 +12:00
'email': email,
'password': password
});
}
/**
* Update Account Name
*
2019-10-09 21:40:02 +13:00
* Update currently logged in user account name.
2019-06-10 06:13:55 +12:00
*
* @param string name
* @throws Exception
* @return {}
*/
async updateName(name) {
let path = '/account/name';
2019-10-20 06:21:36 +13:00
return await this.client.call('patch', path, {
'content-type': 'application/json',
},
{
2019-06-10 06:13:55 +12:00
'name': name
});
}
/**
* Update Account Password
*
2019-10-09 21:40:02 +13:00
* Update currently logged in user password. For validation, user is required
* to pass the password twice.
2019-06-10 06:13:55 +12:00
*
* @param string password
* @param string oldPassword
* @throws Exception
* @return {}
*/
async updatePassword(password, oldPassword) {
let path = '/account/password';
2019-10-20 06:21:36 +13:00
return await this.client.call('patch', path, {
'content-type': 'application/json',
},
{
2019-06-10 06:13:55 +12:00
'password': password,
'old-password': oldPassword
});
}
/**
* Get Account Preferences
*
2019-10-09 21:40:02 +13:00
* Get currently logged in user preferences key-value object.
2019-06-10 06:13:55 +12:00
*
* @throws Exception
* @return {}
*/
async getPrefs() {
let path = '/account/prefs';
2019-10-20 06:21:36 +13:00
return await this.client.call('get', path, {
'content-type': 'application/json',
},
{
2019-06-10 06:13:55 +12:00
});
}
/**
* Update Account Prefs
*
2019-10-09 21:40:02 +13:00
* Update currently logged in user account preferences. You can pass only the
* specific settings you wish to update.
2019-06-10 06:13:55 +12:00
*
* @param string prefs
* @throws Exception
* @return {}
*/
async updatePrefs(prefs) {
let path = '/account/prefs';
2019-10-20 06:21:36 +13:00
return await this.client.call('patch', path, {
'content-type': 'application/json',
},
{
2019-06-10 06:13:55 +12:00
'prefs': prefs
});
}
/**
* Get Account Security Log
*
2019-10-09 21:40:02 +13:00
* Get currently logged in user list of latest security activity logs. Each
* log returns user IP address, location and date and time of log.
2019-06-10 06:13:55 +12:00
*
* @throws Exception
* @return {}
*/
async getSecurity() {
let path = '/account/security';
2019-10-20 06:21:36 +13:00
return await this.client.call('get', path, {
'content-type': 'application/json',
},
{
2019-06-10 06:13:55 +12:00
});
}
/**
* Get Account Active Sessions
*
2019-10-09 21:40:02 +13:00
* Get currently logged in user list of active sessions across different
* devices.
2019-06-10 06:13:55 +12:00
*
* @throws Exception
* @return {}
*/
async getSessions() {
let path = '/account/sessions';
2019-10-20 06:21:36 +13:00
return await this.client.call('get', path, {
'content-type': 'application/json',
},
{
2019-06-10 06:13:55 +12:00
});
}
}
module.exports = Account;