2017-10-20 13:30:01 -04:00
|
|
|
var angular = require('angular');
|
|
|
|
|
2018-12-31 17:01:44 -05:00
|
|
|
angular.module('AuthSvc', []).service('AuthService', ['$http', '$window', function($http) {
|
|
|
|
this.login = async (displayname, password) =>
|
|
|
|
$http({
|
2017-10-11 10:15:19 -04:00
|
|
|
method: 'POST',
|
|
|
|
url: '/api/auth/login',
|
2018-08-14 05:14:26 -04:00
|
|
|
data: {
|
|
|
|
displayname: displayname,
|
|
|
|
password: password
|
|
|
|
}
|
2018-12-31 17:01:44 -05:00
|
|
|
}).catch(err => {
|
|
|
|
if (err.status === 401)
|
|
|
|
throw 'unauthorized';
|
|
|
|
else if (err.status === 429)
|
|
|
|
throw 'ratelimited';
|
|
|
|
else
|
|
|
|
throw 'unknown';
|
|
|
|
});
|
2017-10-18 13:31:08 -04:00
|
|
|
|
2018-12-31 17:01:44 -05:00
|
|
|
this.logout = async () =>
|
2017-10-14 17:49:11 -04:00
|
|
|
$http({
|
2018-12-31 17:01:44 -05:00
|
|
|
method: 'POST',
|
2017-10-14 17:49:11 -04:00
|
|
|
url: '/api/auth/logout'
|
|
|
|
});
|
2017-10-11 10:15:19 -04:00
|
|
|
|
2018-12-31 17:01:44 -05:00
|
|
|
this.register = async (displayname, password, invite) =>
|
|
|
|
$http({
|
2017-10-11 10:15:19 -04:00
|
|
|
method: 'POST',
|
|
|
|
url: '/api/auth/register',
|
2018-08-14 05:14:26 -04:00
|
|
|
data: {
|
|
|
|
displayname: displayname,
|
|
|
|
password: password,
|
|
|
|
invite: invite
|
|
|
|
}
|
2018-12-31 17:01:44 -05:00
|
|
|
}).catch(err => {
|
|
|
|
throw err;
|
2017-10-11 10:15:19 -04:00
|
|
|
});
|
|
|
|
|
2018-12-31 17:01:44 -05:00
|
|
|
this.whoami = async () =>
|
|
|
|
$http({
|
2017-10-18 13:31:08 -04:00
|
|
|
method: 'GET',
|
2018-08-14 05:14:26 -04:00
|
|
|
url: '/api/auth/whoami'
|
2018-12-31 17:01:44 -05:00
|
|
|
}).catch(err => {
|
|
|
|
throw err;
|
2017-10-18 13:31:08 -04:00
|
|
|
});
|
2017-10-11 10:15:19 -04:00
|
|
|
}]);
|