1
0
mirror of https://github.com/Foltik/Shimapan synced 2024-11-15 09:08:06 -05:00
shimapan/app/public/services/AuthSvc.js

48 lines
1.2 KiB
JavaScript
Raw Normal View History

2018-12-31 18:37:34 -05:00
const angular = require('angular');
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
}
}).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
this.logout = async () =>
2017-10-14 17:49:11 -04:00
$http({
method: 'POST',
2017-10-14 17:49:11 -04:00
url: '/api/auth/logout'
});
2017-10-11 10:15:19 -04: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
}
}).catch(err => {
throw err;
2017-10-11 10:15:19 -04: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'
}).catch(err => {
throw err;
2017-10-18 13:31:08 -04:00
});
2017-10-11 10:15:19 -04:00
}]);