update
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
|
||||
import { environment } from '../../environments/environment';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class AppService {
|
||||
|
||||
constructor(private http: HttpClient) {
|
||||
}
|
||||
|
||||
apps() {
|
||||
return this.http.get(environment.apiUrl + "/apps");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { BehaviorSubject, of } from 'rxjs';
|
||||
import { HttpClient, HttpHeaders } from '@angular/common/http';
|
||||
|
||||
import { environment } from './../../environments/environment';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class AuthService {
|
||||
|
||||
auth: BehaviorSubject<any> = new BehaviorSubject(undefined);
|
||||
|
||||
constructor(private http: HttpClient) {
|
||||
}
|
||||
|
||||
getAuth() {
|
||||
return this.authMe().toPromise().then((data: any) => {
|
||||
this.auth.next(data);
|
||||
return data;
|
||||
}, error => {
|
||||
throw new Error(error);
|
||||
});
|
||||
}
|
||||
|
||||
authMe() {
|
||||
return this.http.get(environment.apiUrl + "/auth/me");
|
||||
}
|
||||
|
||||
login(username, password) {
|
||||
return this.http.post(environment.apiUrl + "/auth/login", { username: username, password: password });
|
||||
}
|
||||
|
||||
logout() {
|
||||
return this.http.post(environment.apiUrl + "/auth/logout", {});
|
||||
}
|
||||
|
||||
passwordRequest() {
|
||||
return this.http.post(environment.apiUrl + "/auth/password/request", {});
|
||||
}
|
||||
|
||||
passwordReset(model) {
|
||||
const headers = new HttpHeaders().set('Content-Type', 'text/plain; charset=utf-8');
|
||||
return this.http.post(environment.apiUrl + "/auth/password/reset", model,
|
||||
{ headers, responseType: 'text' });
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { isEmpty } from 'rxjs/operators';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class I18nService {
|
||||
|
||||
locale: String;
|
||||
i18n: any;
|
||||
|
||||
constructor(private http: HttpClient) {
|
||||
let browserLocale = navigator.language;
|
||||
|
||||
if (browserLocale.indexOf("-") != -1) {
|
||||
browserLocale = browserLocale.split("-")[0];
|
||||
}
|
||||
|
||||
let locale = localStorage.getItem("bstly.locale") || browserLocale || 'en';
|
||||
|
||||
if (locale == 'de') {
|
||||
locale = 'de-informal';
|
||||
}
|
||||
|
||||
this.setLocale(locale);
|
||||
}
|
||||
|
||||
getLocale() {
|
||||
return this.locale;
|
||||
}
|
||||
|
||||
setLocale(locale) {
|
||||
this.locale = locale;
|
||||
}
|
||||
|
||||
async fetch(locale) {
|
||||
this.i18n = await this.http.get("./assets/i18n/" + locale + ".json").toPromise();
|
||||
}
|
||||
|
||||
get(key, args: any[]): String {
|
||||
return this.getInternal(key, args, this.i18n);
|
||||
}
|
||||
|
||||
getInternal(key, args: any[], from): String {
|
||||
if (!from) {
|
||||
return key;
|
||||
} else if (from[key]) {
|
||||
if (from[key]["."]) {
|
||||
return this.insertArguments(from[key]["."], args);
|
||||
}
|
||||
return this.insertArguments(from[key], args);
|
||||
} else {
|
||||
let keys = key.split(".");
|
||||
if (from[keys[0]]) {
|
||||
key = keys.slice(1, keys.length).join(".");
|
||||
return this.getInternal(key, args, from[keys[0]])
|
||||
}
|
||||
}
|
||||
|
||||
return key;
|
||||
}
|
||||
|
||||
insertArguments(label: String, args: any[]) {
|
||||
if (args) {
|
||||
for (let index in args) {
|
||||
label = label.replace(`{${index}}`, args[index]);
|
||||
}
|
||||
}
|
||||
return label;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
|
||||
import { environment } from '../../environments/environment';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class ItemService {
|
||||
|
||||
constructor(private http: HttpClient) {
|
||||
}
|
||||
|
||||
items() {
|
||||
return this.http.get(environment.apiUrl + "/items");
|
||||
}
|
||||
|
||||
redeemSecret(secret) {
|
||||
return this.http.put(environment.apiUrl + "/items", JSON.stringify(secret));
|
||||
}
|
||||
|
||||
removeSecret(secret: String) {
|
||||
return this.http.request('delete', environment.apiUrl + "/items", {
|
||||
body: JSON.stringify(secret)
|
||||
});
|
||||
}
|
||||
|
||||
redeem() {
|
||||
return this.http.post(environment.apiUrl + "/items", {});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
|
||||
import { environment } from '../../environments/environment';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class PermissionService {
|
||||
|
||||
constructor(private http: HttpClient) {
|
||||
}
|
||||
|
||||
permissions() {
|
||||
return this.http.get(environment.apiUrl + "/permissions");
|
||||
}
|
||||
|
||||
permissionsNew() {
|
||||
return this.http.get(environment.apiUrl + "/permissions/new");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
|
||||
import { environment } from '../../environments/environment';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class QuotaService {
|
||||
|
||||
constructor(private http: HttpClient) {
|
||||
}
|
||||
|
||||
quotas() {
|
||||
return this.http.get(environment.apiUrl + "/quotas");
|
||||
}
|
||||
|
||||
quotasNew() {
|
||||
return this.http.get(environment.apiUrl + "/quotas/new");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
|
||||
import { environment } from '../../environments/environment';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class UserService {
|
||||
|
||||
constructor(private http: HttpClient) {
|
||||
}
|
||||
|
||||
register(userModel) {
|
||||
return this.http.post(environment.apiUrl + "/users", userModel);
|
||||
}
|
||||
|
||||
password(passwordModel) {
|
||||
return this.http.patch(environment.apiUrl + "/users/password", passwordModel);
|
||||
}
|
||||
|
||||
update(userModel) {
|
||||
return this.http.patch(environment.apiUrl + "/users", userModel);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
|
||||
import { environment } from '../../environments/environment';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class VoucherService {
|
||||
|
||||
constructor(private http: HttpClient) {
|
||||
}
|
||||
|
||||
registration() {
|
||||
return this.http.post(environment.apiUrl + "/vouchers/registration", {});
|
||||
}
|
||||
|
||||
addon() {
|
||||
return this.http.post(environment.apiUrl + "/vouchers/addon", {});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user