mirror of
https://github.com/Foltik/Shimapan
synced 2024-11-15 01:06:32 -05:00
51 lines
1.3 KiB
JavaScript
51 lines
1.3 KiB
JavaScript
var angular = require('angular');
|
|
|
|
angular.module('AuthSvc', []).service('AuthService', ['$http', '$window', function($http, $window) {
|
|
this.login = (displayname, password) => {
|
|
return $http({
|
|
method: 'POST',
|
|
url: '/api/auth/login',
|
|
data: {
|
|
displayname: displayname,
|
|
password: password
|
|
}
|
|
}).then(res => {
|
|
if (res.status === 200)
|
|
$window.location.href = '/home';
|
|
})
|
|
};
|
|
|
|
this.logout = () => {
|
|
$http({
|
|
method: 'GET',
|
|
url: '/api/auth/logout'
|
|
}).then(() => {
|
|
$window.location.href = '/';
|
|
});
|
|
};
|
|
|
|
this.register = (displayname, password, invite) => {
|
|
return $http({
|
|
method: 'POST',
|
|
url: '/api/auth/register',
|
|
data: {
|
|
displayname: displayname,
|
|
password: password,
|
|
invite: invite
|
|
}
|
|
}).then(function(res) {
|
|
if (res.status === 200)
|
|
$window.location.href = '/home';
|
|
});
|
|
};
|
|
|
|
this.whoami = function(cb) {
|
|
return $http({
|
|
method: 'GET',
|
|
url: '/api/auth/whoami'
|
|
}).then(function(res) {
|
|
cb(res.data);
|
|
});
|
|
}
|
|
}]);
|