Нет описания

local.ts 1.3KB

123456789101112131415161718192021222324252627282930313233343536
  1. import { joinUrl } from './utils';
  2. import Config from './config';
  3. import Shared from './shared';
  4. class Local {
  5. static $inject = ['$http', 'SatellizerConfig', 'SatellizerShared'];
  6. constructor(private $http: angular.IHttpService,
  7. private SatellizerConfig: Config,
  8. private SatellizerShared: Shared) {}
  9. login(user: string|Object, options: any = {}): angular.IHttpPromise<any> {
  10. options.url = options.url ? options.url : joinUrl(this.SatellizerConfig.baseUrl, this.SatellizerConfig.loginUrl);
  11. options.data = user || options.data;
  12. options.method = options.method || 'POST';
  13. options.withCredentials = options.withCredentials || this.SatellizerConfig.withCredentials;
  14. return this.$http(options).then((response) => {
  15. this.SatellizerShared.setToken(response);
  16. return response;
  17. });
  18. }
  19. signup(user: string|Object, options: any = {}): angular.IHttpPromise<any> {
  20. options.url = options.url ? options.url : joinUrl(this.SatellizerConfig.baseUrl, this.SatellizerConfig.signupUrl);
  21. options.data = user || options.data;
  22. options.method = options.method || 'POST';
  23. options.withCredentials = options.withCredentials || this.SatellizerConfig.withCredentials;
  24. return this.$http(options);
  25. }
  26. }
  27. export default Local;