1
0
mirror of https://github.com/Foltik/Shimapan synced 2024-11-15 01:06:32 -05:00
shimapan/app/public/services/AuthSvc.js
2018-12-31 18:37:34 -05:00

48 lines
1.2 KiB
JavaScript

const angular = require('angular');
angular.module('AuthSvc', []).service('AuthService', ['$http', '$window', function($http) {
this.login = async (displayname, password) =>
$http({
method: 'POST',
url: '/api/auth/login',
data: {
displayname: displayname,
password: password
}
}).catch(err => {
if (err.status === 401)
throw 'unauthorized';
else if (err.status === 429)
throw 'ratelimited';
else
throw 'unknown';
});
this.logout = async () =>
$http({
method: 'POST',
url: '/api/auth/logout'
});
this.register = async (displayname, password, invite) =>
$http({
method: 'POST',
url: '/api/auth/register',
data: {
displayname: displayname,
password: password,
invite: invite
}
}).catch(err => {
throw err;
});
this.whoami = async () =>
$http({
method: 'GET',
url: '/api/auth/whoami'
}).catch(err => {
throw err;
});
}]);