1
0
mirror of https://github.com/Foltik/Shimapan synced 2024-11-16 01:28:07 -05:00
shimapan/app/public/services/AuthSvc.js

51 lines
1.3 KiB
JavaScript
Raw Normal View History

var angular = require('angular');
2017-10-11 10:15:19 -04:00
angular.module('AuthSvc', []).service('AuthService', ['$http', '$window', function($http, $window) {
2018-08-14 05:14:26 -04:00
this.login = (displayname, password) => {
2017-10-11 10:15:19 -04:00
return $http({
method: 'POST',
url: '/api/auth/login',
2018-08-14 05:14:26 -04:00
data: {
displayname: displayname,
password: password
}
}).then(res => {
if (res.status === 200)
2018-01-13 19:06:52 -05:00
$window.location.href = '/home';
2017-10-11 10:15:19 -04:00
})
};
2017-10-18 13:31:08 -04:00
2018-08-14 05:14:26 -04:00
this.logout = () => {
2017-10-14 17:49:11 -04:00
$http({
method: 'GET',
url: '/api/auth/logout'
2018-08-14 05:14:26 -04:00
}).then(() => {
2017-10-14 17:49:11 -04:00
$window.location.href = '/';
});
2017-10-11 10:15:19 -04:00
};
2018-08-14 05:14:26 -04:00
this.register = (displayname, password, invite) => {
2017-10-11 10:15:19 -04:00
return $http({
method: 'POST',
url: '/api/auth/register',
2018-08-14 05:14:26 -04:00
data: {
displayname: displayname,
password: password,
invite: invite
}
2017-10-11 10:15:19 -04:00
}).then(function(res) {
if (res.status === 200)
$window.location.href = '/home';
2017-10-11 10:15:19 -04:00
});
};
2018-08-14 05:14:26 -04:00
this.whoami = function(cb) {
2017-10-18 13:31:08 -04:00
return $http({
method: 'GET',
2018-08-14 05:14:26 -04:00
url: '/api/auth/whoami'
2017-10-18 13:31:08 -04:00
}).then(function(res) {
cb(res.data);
});
2017-10-14 15:16:58 -04:00
}
2017-10-11 10:15:19 -04:00
}]);