A simple file sharing site with an easy to use API and online panel.
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.

48 satır
1.2KB

  1. var angular = require('angular');
  2. angular.module('AuthSvc', []).service('AuthService', ['$http', '$window', function($http) {
  3. this.login = async (displayname, password) =>
  4. $http({
  5. method: 'POST',
  6. url: '/api/auth/login',
  7. data: {
  8. displayname: displayname,
  9. password: password
  10. }
  11. }).catch(err => {
  12. if (err.status === 401)
  13. throw 'unauthorized';
  14. else if (err.status === 429)
  15. throw 'ratelimited';
  16. else
  17. throw 'unknown';
  18. });
  19. this.logout = async () =>
  20. $http({
  21. method: 'POST',
  22. url: '/api/auth/logout'
  23. });
  24. this.register = async (displayname, password, invite) =>
  25. $http({
  26. method: 'POST',
  27. url: '/api/auth/register',
  28. data: {
  29. displayname: displayname,
  30. password: password,
  31. invite: invite
  32. }
  33. }).catch(err => {
  34. throw err;
  35. });
  36. this.whoami = async () =>
  37. $http({
  38. method: 'GET',
  39. url: '/api/auth/whoami'
  40. }).catch(err => {
  41. throw err;
  42. });
  43. }]);