2019-06-10 06:13:55 +12:00
|
|
|
const Service = require('../service.js');
|
|
|
|
|
|
|
|
class Auth extends Service {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Login User
|
|
|
|
*
|
2019-10-09 17:16:38 +13:00
|
|
|
* /docs/references/auth/login.md
|
2019-06-10 06:13:55 +12:00
|
|
|
*
|
|
|
|
* @param string email
|
|
|
|
* @param string password
|
|
|
|
* @param string success
|
|
|
|
* @param string failure
|
|
|
|
* @throws Exception
|
|
|
|
* @return {}
|
|
|
|
*/
|
2019-09-20 18:33:11 +12:00
|
|
|
async login(email, password, success, failure) {
|
2019-06-10 06:13:55 +12:00
|
|
|
let path = '/auth/login';
|
2019-10-04 06:58:18 +13:00
|
|
|
|
2019-06-10 06:13:55 +12:00
|
|
|
return await this.client.call('post', path, {'content-type': 'application/json'},
|
|
|
|
{
|
|
|
|
'email': email,
|
|
|
|
'password': password,
|
|
|
|
'success': success,
|
|
|
|
'failure': failure
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Logout Current Session
|
|
|
|
*
|
2019-10-09 17:16:38 +13:00
|
|
|
* /docs/references/auth/logout.md
|
2019-06-10 06:13:55 +12:00
|
|
|
*
|
|
|
|
* @throws Exception
|
|
|
|
* @return {}
|
|
|
|
*/
|
|
|
|
async logout() {
|
|
|
|
let path = '/auth/logout';
|
2019-10-04 06:58:18 +13:00
|
|
|
|
2019-06-10 06:13:55 +12:00
|
|
|
return await this.client.call('delete', path, {'content-type': 'application/json'},
|
|
|
|
{
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Logout Specific Session
|
|
|
|
*
|
2019-10-09 17:16:38 +13:00
|
|
|
* /docs/references/auth/logout-by-session.md
|
2019-06-10 06:13:55 +12:00
|
|
|
*
|
2019-07-21 23:54:45 +12:00
|
|
|
* @param string id
|
2019-06-10 06:13:55 +12:00
|
|
|
* @throws Exception
|
|
|
|
* @return {}
|
|
|
|
*/
|
2019-07-21 23:54:45 +12:00
|
|
|
async logoutBySession(id) {
|
|
|
|
let path = '/auth/logout/{id}'.replace(new RegExp('{id}', 'g'), id);
|
2019-10-04 06:58:18 +13:00
|
|
|
|
2019-06-10 06:13:55 +12:00
|
|
|
return await this.client.call('delete', path, {'content-type': 'application/json'},
|
|
|
|
{
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-09-04 01:40:42 +12:00
|
|
|
/**
|
|
|
|
* OAuth Login
|
|
|
|
*
|
|
|
|
* @param string provider
|
|
|
|
* @param string success
|
|
|
|
* @param string failure
|
|
|
|
* @throws Exception
|
|
|
|
* @return {}
|
|
|
|
*/
|
|
|
|
async oauth(provider, success = '', failure = '') {
|
|
|
|
let path = '/auth/oauth/{provider}'.replace(new RegExp('{provider}', 'g'), provider);
|
2019-10-04 06:58:18 +13:00
|
|
|
|
2019-09-04 01:40:42 +12:00
|
|
|
return await this.client.call('get', path, {'content-type': 'application/json'},
|
|
|
|
{
|
|
|
|
'success': success,
|
|
|
|
'failure': failure
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-06-10 06:13:55 +12:00
|
|
|
/**
|
|
|
|
* Password Recovery
|
|
|
|
*
|
2019-10-09 17:16:38 +13:00
|
|
|
* /docs/references/auth/recovery.md
|
2019-06-10 06:13:55 +12:00
|
|
|
*
|
|
|
|
* @param string email
|
2019-10-02 07:10:33 +13:00
|
|
|
* @param string reset
|
2019-06-10 06:13:55 +12:00
|
|
|
* @throws Exception
|
|
|
|
* @return {}
|
|
|
|
*/
|
2019-10-02 07:10:33 +13:00
|
|
|
async recovery(email, reset) {
|
2019-06-10 06:13:55 +12:00
|
|
|
let path = '/auth/recovery';
|
2019-10-04 06:58:18 +13:00
|
|
|
|
2019-06-10 06:13:55 +12:00
|
|
|
return await this.client.call('post', path, {'content-type': 'application/json'},
|
|
|
|
{
|
|
|
|
'email': email,
|
2019-10-02 07:10:33 +13:00
|
|
|
'reset': reset
|
2019-06-10 06:13:55 +12:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Password Reset
|
|
|
|
*
|
2019-10-09 17:16:38 +13:00
|
|
|
* /docs/references/auth/recovery-reset.md
|
2019-06-10 06:13:55 +12:00
|
|
|
*
|
|
|
|
* @param string userId
|
|
|
|
* @param string token
|
|
|
|
* @param string passwordA
|
|
|
|
* @param string passwordB
|
|
|
|
* @throws Exception
|
|
|
|
* @return {}
|
|
|
|
*/
|
|
|
|
async recoveryReset(userId, token, passwordA, passwordB) {
|
|
|
|
let path = '/auth/recovery/reset';
|
2019-10-04 06:58:18 +13:00
|
|
|
|
2019-06-10 06:13:55 +12:00
|
|
|
return await this.client.call('put', path, {'content-type': 'application/json'},
|
|
|
|
{
|
|
|
|
'userId': userId,
|
|
|
|
'token': token,
|
|
|
|
'password-a': passwordA,
|
|
|
|
'password-b': passwordB
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Register User
|
|
|
|
*
|
2019-10-09 17:16:38 +13:00
|
|
|
* /docs/references/auth/register.md
|
2019-06-10 06:13:55 +12:00
|
|
|
*
|
|
|
|
* @param string email
|
|
|
|
* @param string password
|
2019-10-02 07:10:33 +13:00
|
|
|
* @param string confirm
|
2019-06-10 06:13:55 +12:00
|
|
|
* @param string success
|
|
|
|
* @param string failure
|
2019-09-20 18:33:11 +12:00
|
|
|
* @param string name
|
2019-06-10 06:13:55 +12:00
|
|
|
* @throws Exception
|
|
|
|
* @return {}
|
|
|
|
*/
|
2019-10-02 07:10:33 +13:00
|
|
|
async register(email, password, confirm, success = '', failure = '', name = '') {
|
2019-06-10 06:13:55 +12:00
|
|
|
let path = '/auth/register';
|
2019-10-04 06:58:18 +13:00
|
|
|
|
2019-06-10 06:13:55 +12:00
|
|
|
return await this.client.call('post', path, {'content-type': 'application/json'},
|
|
|
|
{
|
|
|
|
'email': email,
|
|
|
|
'password': password,
|
2019-10-02 07:10:33 +13:00
|
|
|
'confirm': confirm,
|
2019-06-10 06:13:55 +12:00
|
|
|
'success': success,
|
2019-09-20 18:33:11 +12:00
|
|
|
'failure': failure,
|
|
|
|
'name': name
|
2019-06-10 06:13:55 +12:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Confirm User
|
|
|
|
*
|
2019-10-09 17:16:38 +13:00
|
|
|
* /docs/references/auth/confirm.md
|
2019-06-10 06:13:55 +12:00
|
|
|
*
|
|
|
|
* @param string userId
|
|
|
|
* @param string token
|
|
|
|
* @throws Exception
|
|
|
|
* @return {}
|
|
|
|
*/
|
|
|
|
async confirm(userId, token) {
|
|
|
|
let path = '/auth/register/confirm';
|
2019-10-04 06:58:18 +13:00
|
|
|
|
2019-06-10 06:13:55 +12:00
|
|
|
return await this.client.call('post', path, {'content-type': 'application/json'},
|
|
|
|
{
|
|
|
|
'userId': userId,
|
|
|
|
'token': token
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Resend Confirmation
|
|
|
|
*
|
2019-10-09 17:16:38 +13:00
|
|
|
* /docs/references/auth/confirm-resend.md
|
2019-06-10 06:13:55 +12:00
|
|
|
*
|
2019-10-02 07:10:33 +13:00
|
|
|
* @param string confirm
|
2019-06-10 06:13:55 +12:00
|
|
|
* @throws Exception
|
|
|
|
* @return {}
|
|
|
|
*/
|
2019-10-02 07:10:33 +13:00
|
|
|
async confirmResend(confirm) {
|
2019-06-10 06:13:55 +12:00
|
|
|
let path = '/auth/register/confirm/resend';
|
2019-10-04 06:58:18 +13:00
|
|
|
|
2019-06-10 06:13:55 +12:00
|
|
|
return await this.client.call('post', path, {'content-type': 'application/json'},
|
|
|
|
{
|
2019-10-02 07:10:33 +13:00
|
|
|
'confirm': confirm
|
2019-06-10 06:13:55 +12:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-04 06:58:18 +13:00
|
|
|
module.exports = Auth;
|