Integrate with new backend
This commit is contained in:
parent
68d03b6602
commit
79e73ec89d
16 changed files with 79 additions and 86 deletions
|
@ -6,7 +6,6 @@ const userSchema = mongoose.Schema({
|
||||||
blocktime: {type: Number, required:true},
|
blocktime: {type: Number, required:true},
|
||||||
pin: {type: String, required:true},
|
pin: {type: String, required:true},
|
||||||
validated: {type: Boolean, required:true},
|
validated: {type: Boolean, required:true},
|
||||||
expired: {type: Boolean, required:true, default: false}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
module.exports = mongoose.model('User', userSchema);
|
module.exports = mongoose.model('User', userSchema);
|
||||||
|
|
|
@ -63,7 +63,9 @@ export class BusinessComponent implements OnInit {
|
||||||
country: '',
|
country: '',
|
||||||
email: '',
|
email: '',
|
||||||
website: '',
|
website: '',
|
||||||
zats: false
|
zats: false,
|
||||||
|
invoices: false,
|
||||||
|
expiration: new Date(Date.now()).toISOString()
|
||||||
}
|
}
|
||||||
public countriesUpdate: Observable<Country[]>;
|
public countriesUpdate: Observable<Country[]>;
|
||||||
public ownerUpdate: Observable<Owner>;
|
public ownerUpdate: Observable<Owner>;
|
||||||
|
@ -147,6 +149,7 @@ export class BusinessComponent implements OnInit {
|
||||||
|
|
||||||
save() {
|
save() {
|
||||||
this.owner = {
|
this.owner = {
|
||||||
|
_id: '',
|
||||||
address: '',
|
address: '',
|
||||||
currency: 'usd',
|
currency: 'usd',
|
||||||
tax: false,
|
tax: false,
|
||||||
|
@ -165,7 +168,9 @@ export class BusinessComponent implements OnInit {
|
||||||
country: this.bizForm.get('country')!.value,
|
country: this.bizForm.get('country')!.value,
|
||||||
email: this.bizForm.get('email')!.value,
|
email: this.bizForm.get('email')!.value,
|
||||||
website: this.bizForm.get('website')!.value,
|
website: this.bizForm.get('website')!.value,
|
||||||
zats: false
|
zats: false,
|
||||||
|
invoices: false,
|
||||||
|
expiration: new Date(Date.now()).toISOString()
|
||||||
};
|
};
|
||||||
this.userService.addOwner(this.owner);
|
this.userService.addOwner(this.owner);
|
||||||
this.stepper!.next();
|
this.stepper!.next();
|
||||||
|
|
|
@ -4,6 +4,7 @@ import {HttpClient, HttpParams, HttpHeaders} from '@angular/common/http';
|
||||||
import {UserService} from './user.service';
|
import {UserService} from './user.service';
|
||||||
import { Owner } from './owner.model';
|
import { Owner } from './owner.model';
|
||||||
|
|
||||||
|
var Buffer = require('buffer/').Buffer;
|
||||||
//import {User} from './user.model';
|
//import {User} from './user.model';
|
||||||
|
|
||||||
@Injectable({providedIn: 'root'})
|
@Injectable({providedIn: 'root'})
|
||||||
|
@ -42,11 +43,14 @@ export class FullnodeService{
|
||||||
paid: false,
|
paid: false,
|
||||||
website: '',
|
website: '',
|
||||||
country: '',
|
country: '',
|
||||||
zats: false
|
zats: false,
|
||||||
|
invoices: false,
|
||||||
|
expiration: new Date(Date.now()).toISOString()
|
||||||
};
|
};
|
||||||
|
|
||||||
constructor(private http: HttpClient, public userService: UserService){
|
constructor(private http: HttpClient, public userService: UserService){
|
||||||
this.reqHeaders = new HttpHeaders().set('Authorization', this.apiKey);
|
var auth = 'Basic ' + Buffer.from('user:superSecret').toString('base64');
|
||||||
|
this.reqHeaders = new HttpHeaders().set('Authorization', auth);
|
||||||
this.ownerUpdate = userService.ownerUpdate;
|
this.ownerUpdate = userService.ownerUpdate;
|
||||||
this.getAddr();
|
this.getAddr();
|
||||||
this.getHeight();
|
this.getHeight();
|
||||||
|
|
|
@ -37,7 +37,9 @@ export class HeaderComponent implements OnInit, OnDestroy {
|
||||||
paid: false,
|
paid: false,
|
||||||
website: '',
|
website: '',
|
||||||
country: '',
|
country: '',
|
||||||
zats: false
|
zats: false,
|
||||||
|
invoices: false,
|
||||||
|
expiration: new Date(Date.now()).toISOString()
|
||||||
};
|
};
|
||||||
private session: string | null = '';
|
private session: string | null = '';
|
||||||
public heightUpdate: Observable<number>;
|
public heightUpdate: Observable<number>;
|
||||||
|
|
|
@ -2,6 +2,6 @@ export interface Item {
|
||||||
_id?: any;
|
_id?: any;
|
||||||
name: string;
|
name: string;
|
||||||
description: string;
|
description: string;
|
||||||
user: string;
|
owner: string;
|
||||||
cost: number;
|
cost: number;
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,7 +23,7 @@ export class ItemCreateComponent implements OnInit {
|
||||||
){
|
){
|
||||||
if (data._id === '') {
|
if (data._id === '') {
|
||||||
this.form = fb.group({
|
this.form = fb.group({
|
||||||
id: [null],
|
id: [''],
|
||||||
name: [null, Validators.required],
|
name: [null, Validators.required],
|
||||||
description: [null, Validators.required],
|
description: [null, Validators.required],
|
||||||
cost: new FormControl('', {
|
cost: new FormControl('', {
|
||||||
|
@ -49,6 +49,7 @@ export class ItemCreateComponent implements OnInit {
|
||||||
}
|
}
|
||||||
|
|
||||||
save() {
|
save() {
|
||||||
|
console.log(this.form.value);
|
||||||
this.dialogRef.close(this.form.value);
|
this.dialogRef.close(this.form.value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -40,7 +40,9 @@ export class ItemListComponent implements OnInit{
|
||||||
paid: false,
|
paid: false,
|
||||||
website: '',
|
website: '',
|
||||||
country: '',
|
country: '',
|
||||||
zats: false
|
zats: false,
|
||||||
|
invoices: false,
|
||||||
|
expiration: new Date(Date.now()).toISOString()
|
||||||
};
|
};
|
||||||
public price: number = 1;
|
public price: number = 1;
|
||||||
public ownerUpdate: Observable<Owner>;
|
public ownerUpdate: Observable<Owner>;
|
||||||
|
@ -87,7 +89,7 @@ export class ItemListComponent implements OnInit{
|
||||||
|
|
||||||
dialogRef.afterClosed().subscribe((val) => {
|
dialogRef.afterClosed().subscribe((val) => {
|
||||||
if(val != null) {
|
if(val != null) {
|
||||||
var item:Item = {name: val.name, description: val.description, cost: val.cost, user: this.owner.address};
|
var item:Item = {_id: '', name: val.name, description: val.description, cost: val.cost, owner: this.owner.address};
|
||||||
this.itemService.addItem(item);
|
this.itemService.addItem(item);
|
||||||
}
|
}
|
||||||
this.itemService.getItems(this.owner.address);
|
this.itemService.getItems(this.owner.address);
|
||||||
|
@ -98,9 +100,9 @@ export class ItemListComponent implements OnInit{
|
||||||
}
|
}
|
||||||
|
|
||||||
edit(id: string) {
|
edit(id: string) {
|
||||||
//console.log('Edit:', id);
|
console.log('Edit:', id);
|
||||||
const item = this.items.find(element => element._id == id);
|
const item = this.items.find(element => element._id == id);
|
||||||
//console.log(item);
|
console.log(item);
|
||||||
const dialogConfig = new MatDialogConfig();
|
const dialogConfig = new MatDialogConfig();
|
||||||
|
|
||||||
dialogConfig.disableClose = true;
|
dialogConfig.disableClose = true;
|
||||||
|
@ -115,7 +117,7 @@ export class ItemListComponent implements OnInit{
|
||||||
name: val.name,
|
name: val.name,
|
||||||
description: val.description,
|
description: val.description,
|
||||||
cost: val.cost,
|
cost: val.cost,
|
||||||
user: this.owner.address
|
owner: this.owner.address
|
||||||
};
|
};
|
||||||
//console.log('Edit:', editItem);
|
//console.log('Edit:', editItem);
|
||||||
this.itemService.addItem(editItem).subscribe((response) => {
|
this.itemService.addItem(editItem).subscribe((response) => {
|
||||||
|
|
|
@ -3,5 +3,5 @@ export interface Item {
|
||||||
name: string;
|
name: string;
|
||||||
description: string;
|
description: string;
|
||||||
cost: number;
|
cost: number;
|
||||||
user: string;
|
owner: string;
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,8 @@ import { Injectable } from '@angular/core';
|
||||||
import { Subject, BehaviorSubject, Observable } from 'rxjs';
|
import { Subject, BehaviorSubject, Observable } from 'rxjs';
|
||||||
import { HttpClient, HttpParams, HttpHeaders } from '@angular/common/http';
|
import { HttpClient, HttpParams, HttpHeaders } from '@angular/common/http';
|
||||||
|
|
||||||
|
var Buffer = require('buffer/').Buffer;
|
||||||
|
|
||||||
@Injectable({providedIn: 'root'})
|
@Injectable({providedIn: 'root'})
|
||||||
|
|
||||||
export class ItemService{
|
export class ItemService{
|
||||||
|
@ -15,13 +17,14 @@ export class ItemService{
|
||||||
private reqHeaders: HttpHeaders;
|
private reqHeaders: HttpHeaders;
|
||||||
|
|
||||||
constructor(private http: HttpClient){
|
constructor(private http: HttpClient){
|
||||||
this.reqHeaders = new HttpHeaders().set('Authorization', this.apiKey);
|
var auth = 'Basic ' + Buffer.from('user:superSecret').toString('base64');
|
||||||
|
this.reqHeaders = new HttpHeaders().set('Authorization', auth);
|
||||||
}
|
}
|
||||||
|
|
||||||
getItems(addr: string){
|
getItems(addr: string){
|
||||||
this.address = addr;
|
this.address = addr;
|
||||||
const params = new HttpParams().append('address', addr);
|
const params = new HttpParams().append('address', addr);
|
||||||
let obs = this.http.get<{message: string, items: any}>(this.beUrl+'api/getitems', { headers:this.reqHeaders, params: params, observe: 'response'});
|
let obs = this.http.get<{message: string, items: any}>(this.beUrl+'api/items', { headers:this.reqHeaders, params: params, observe: 'response'});
|
||||||
|
|
||||||
obs.subscribe((ItemDataResponse) => {
|
obs.subscribe((ItemDataResponse) => {
|
||||||
if (ItemDataResponse.status == 200 ) {
|
if (ItemDataResponse.status == 200 ) {
|
||||||
|
@ -39,7 +42,7 @@ export class ItemService{
|
||||||
|
|
||||||
addItem(item: Item) {
|
addItem(item: Item) {
|
||||||
//const params = new HttpParams().append('item', JSON.stringify(item));
|
//const params = new HttpParams().append('item', JSON.stringify(item));
|
||||||
let obs = this.http.post<{message: string}>(this.beUrl+'api/item', { item: item }, { headers: this.reqHeaders });
|
let obs = this.http.post<{message: string}>(this.beUrl+'api/item', { payload: item }, { headers: this.reqHeaders });
|
||||||
|
|
||||||
obs.subscribe((ItemResponse) => {
|
obs.subscribe((ItemResponse) => {
|
||||||
console.log('Item added');
|
console.log('Item added');
|
||||||
|
|
|
@ -35,7 +35,6 @@ export class LoginComponent implements OnInit, AfterViewInit {
|
||||||
address: '',
|
address: '',
|
||||||
session: '',
|
session: '',
|
||||||
blocktime: 0,
|
blocktime: 0,
|
||||||
expired: false,
|
|
||||||
pin: '',
|
pin: '',
|
||||||
validated: false
|
validated: false
|
||||||
};
|
};
|
||||||
|
@ -58,7 +57,9 @@ export class LoginComponent implements OnInit, AfterViewInit {
|
||||||
paid: false,
|
paid: false,
|
||||||
website: '',
|
website: '',
|
||||||
country: '',
|
country: '',
|
||||||
zats: false
|
zats: false,
|
||||||
|
invoices: false,
|
||||||
|
expiration: new Date(Date.now()).toISOString()
|
||||||
};
|
};
|
||||||
private FullnodeSub: Subscription = new Subscription();
|
private FullnodeSub: Subscription = new Subscription();
|
||||||
private UserSub: Subscription = new Subscription();
|
private UserSub: Subscription = new Subscription();
|
||||||
|
@ -152,12 +153,7 @@ export class LoginComponent implements OnInit, AfterViewInit {
|
||||||
}
|
}
|
||||||
|
|
||||||
loginCheck(){
|
loginCheck(){
|
||||||
var today = new Date().getTime() / 1000;
|
|
||||||
this.userService.findUser();
|
this.userService.findUser();
|
||||||
this.userService.findPending();
|
|
||||||
this.txsUpdate.subscribe((txs) => {
|
|
||||||
this.txs = txs;
|
|
||||||
});
|
|
||||||
this.userUpdate.subscribe((user) => {
|
this.userUpdate.subscribe((user) => {
|
||||||
if (user.blocktime > 0) {
|
if (user.blocktime > 0) {
|
||||||
if(this.myStepper!.selectedIndex === 1){
|
if(this.myStepper!.selectedIndex === 1){
|
||||||
|
@ -173,12 +169,6 @@ export class LoginComponent implements OnInit, AfterViewInit {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
if (this.txs.length > 0) {
|
|
||||||
this.barMode = 'determinate';
|
|
||||||
this.barValue = (this.txs[0].confirmations / 2) * 100;
|
|
||||||
this.confirmedMemo = true;
|
|
||||||
this.barMessage = 'Login memo found, awaiting confirmations';
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
login(stepper: MatStepper) {
|
login(stepper: MatStepper) {
|
||||||
|
|
|
@ -8,6 +8,8 @@ import { User } from '../user.model';
|
||||||
import { Owner } from '../owner.model';
|
import { Owner } from '../owner.model';
|
||||||
import { LineItem} from '../items/lineitem.model';
|
import { LineItem} from '../items/lineitem.model';
|
||||||
|
|
||||||
|
var Buffer = require('buffer/').Buffer;
|
||||||
|
|
||||||
@Injectable({providedIn: 'root'})
|
@Injectable({providedIn: 'root'})
|
||||||
|
|
||||||
export class OrderService {
|
export class OrderService {
|
||||||
|
@ -18,7 +20,6 @@ export class OrderService {
|
||||||
address: '',
|
address: '',
|
||||||
session: '',
|
session: '',
|
||||||
blocktime: 0,
|
blocktime: 0,
|
||||||
expired: false,
|
|
||||||
pin: '',
|
pin: '',
|
||||||
validated: false
|
validated: false
|
||||||
},
|
},
|
||||||
|
@ -42,7 +43,9 @@ export class OrderService {
|
||||||
paid: false,
|
paid: false,
|
||||||
website: '',
|
website: '',
|
||||||
country: '',
|
country: '',
|
||||||
zats: false
|
zats: false,
|
||||||
|
invoices: false,
|
||||||
|
expiration: new Date(Date.now()).toISOString()
|
||||||
},
|
},
|
||||||
order: {
|
order: {
|
||||||
address: '',
|
address: '',
|
||||||
|
@ -78,7 +81,8 @@ export class OrderService {
|
||||||
public fullnodeService: FullnodeService,
|
public fullnodeService: FullnodeService,
|
||||||
public userService: UserService
|
public userService: UserService
|
||||||
) {
|
) {
|
||||||
this.reqHeaders = new HttpHeaders().set('Authorization', this.apiKey);
|
var auth = 'Basic ' + Buffer.from('user:superSecret').toString('base64');
|
||||||
|
this.reqHeaders = new HttpHeaders().set('Authorization', auth);
|
||||||
this.userUpdate = userService.userUpdate;
|
this.userUpdate = userService.userUpdate;
|
||||||
this.ownerUpdate = userService.ownerUpdate;
|
this.ownerUpdate = userService.ownerUpdate;
|
||||||
this.userUpdate.subscribe((user) => {
|
this.userUpdate.subscribe((user) => {
|
||||||
|
@ -132,7 +136,8 @@ export class OrderService {
|
||||||
|
|
||||||
addToOrder(lineItem: LineItem) {
|
addToOrder(lineItem: LineItem) {
|
||||||
if(this.dataStore.order._id != null) {
|
if(this.dataStore.order._id != null) {
|
||||||
let obs = this.http.post<{message: string}>(this.beUrl+'api/lineitem', { order_id: this.dataStore.order._id, line: lineItem }, { headers: this.reqHeaders });
|
this.dataStore.order.lines.push(lineItem);
|
||||||
|
let obs = this.http.post(this.beUrl+'api/order', { payload: this.dataStore.order }, { headers: this.reqHeaders });
|
||||||
obs.subscribe((orderData) => {
|
obs.subscribe((orderData) => {
|
||||||
this.getOrder();
|
this.getOrder();
|
||||||
});
|
});
|
||||||
|
@ -143,21 +148,21 @@ export class OrderService {
|
||||||
|
|
||||||
createOrder(lineItem: LineItem) {
|
createOrder(lineItem: LineItem) {
|
||||||
var order:Order = {
|
var order:Order = {
|
||||||
|
_id: '',
|
||||||
address: this.dataStore.user.address,
|
address: this.dataStore.user.address,
|
||||||
session: this.dataStore.user.session,
|
session: this.dataStore.user.session,
|
||||||
currency: this.dataStore.owner.currency,
|
currency: this.dataStore.owner.currency,
|
||||||
|
timestamp: new Date(Date.now()).toISOString(),
|
||||||
closed: false,
|
closed: false,
|
||||||
totalZec: 0,
|
totalZec: 0,
|
||||||
price: 0,
|
price: 0,
|
||||||
total: 0,
|
total: 0,
|
||||||
lines: []
|
lines: [lineItem]
|
||||||
};
|
};
|
||||||
let obs = this.http.post<{message: string, order: Order}>(this.beUrl+'api/order', {order: order}, { headers: this.reqHeaders });
|
let obs = this.http.post<{message: string, order: Order}>(this.beUrl+'api/order', {payload: order}, { headers: this.reqHeaders });
|
||||||
obs.subscribe((orderData) => {
|
obs.subscribe((orderData) => {
|
||||||
console.log('Create order', orderData);
|
console.log('Created order');
|
||||||
this.dataStore.order = orderData.order;
|
this.getOrder()
|
||||||
this._orderUpdated.next(Object.assign({}, this.dataStore).order);
|
|
||||||
this.addToOrder(lineItem);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return obs;
|
return obs;
|
||||||
|
@ -197,7 +202,7 @@ export class OrderService {
|
||||||
this.dataStore.order.price = price;
|
this.dataStore.order.price = price;
|
||||||
});
|
});
|
||||||
this.dataStore.order.closed = true;
|
this.dataStore.order.closed = true;
|
||||||
let obs = this.http.post<{message: string, order: Order}>(this.beUrl+'api/order', {order: this.dataStore.order}, { headers: this.reqHeaders });
|
let obs = this.http.post(this.beUrl+'api/order', {payload: this.dataStore.order}, { headers: this.reqHeaders });
|
||||||
obs.subscribe((orderData) => {
|
obs.subscribe((orderData) => {
|
||||||
console.log('Closed order', orderData);
|
console.log('Closed order', orderData);
|
||||||
this.dataStore.order = {
|
this.dataStore.order = {
|
||||||
|
|
|
@ -19,4 +19,6 @@ export interface Owner {
|
||||||
website: string;
|
website: string;
|
||||||
country: string;
|
country: string;
|
||||||
zats: boolean;
|
zats: boolean;
|
||||||
|
invoices: boolean;
|
||||||
|
expiration: string;
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,8 @@ import { Order } from './order/order.model';
|
||||||
import { Owner } from './owner.model';
|
import { Owner } from './owner.model';
|
||||||
import { UserService } from './user.service';
|
import { UserService } from './user.service';
|
||||||
|
|
||||||
|
var Buffer = require('buffer/').Buffer;
|
||||||
|
|
||||||
@Injectable({
|
@Injectable({
|
||||||
providedIn: 'root'
|
providedIn: 'root'
|
||||||
})
|
})
|
||||||
|
@ -31,7 +33,9 @@ export class ReceiptService {
|
||||||
paid: false,
|
paid: false,
|
||||||
website: '',
|
website: '',
|
||||||
country: '',
|
country: '',
|
||||||
zats: false
|
zats: false,
|
||||||
|
invoices: false,
|
||||||
|
expiration: new Date(Date.now()).toISOString()
|
||||||
},
|
},
|
||||||
order: {
|
order: {
|
||||||
address: '',
|
address: '',
|
||||||
|
@ -63,13 +67,14 @@ export class ReceiptService {
|
||||||
private http: HttpClient,
|
private http: HttpClient,
|
||||||
public userService: UserService
|
public userService: UserService
|
||||||
) {
|
) {
|
||||||
this.reqHeaders = new HttpHeaders().set('Authorization', this.apiKey);
|
var auth = 'Basic ' + Buffer.from('user:superSecret').toString('base64');
|
||||||
|
this.reqHeaders = new HttpHeaders().set('Authorization', auth);
|
||||||
this.ownerUpdate = userService.ownerUpdate;
|
this.ownerUpdate = userService.ownerUpdate;
|
||||||
}
|
}
|
||||||
|
|
||||||
getOrderById(id:string) {
|
getOrderById(id:string) {
|
||||||
const params = new HttpParams().append('id', id);
|
//const params = new HttpParams().append('id', id);
|
||||||
let obs = this.http.get<{message: string, order: any}>(this.beUrl+'api/receipt', { headers:this.reqHeaders, params:params, observe: 'response'});
|
let obs = this.http.get<{message: string, order: any}>(this.beUrl+'api/order/'+id, { headers:this.reqHeaders, observe: 'response'});
|
||||||
|
|
||||||
obs.subscribe((OrderDataResponse) => {
|
obs.subscribe((OrderDataResponse) => {
|
||||||
if (OrderDataResponse.status == 200) {
|
if (OrderDataResponse.status == 200) {
|
||||||
|
|
|
@ -3,7 +3,6 @@ export interface User {
|
||||||
address: string;
|
address: string;
|
||||||
session: string;
|
session: string;
|
||||||
blocktime: number;
|
blocktime: number;
|
||||||
expired: boolean;
|
|
||||||
pin: string;
|
pin: string;
|
||||||
validated: boolean;
|
validated: boolean;
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,8 @@ import {Owner} from './owner.model';
|
||||||
import { Country } from './country.model';
|
import { Country } from './country.model';
|
||||||
import {Tx} from './tx.model';
|
import {Tx} from './tx.model';
|
||||||
|
|
||||||
|
var Buffer = require('buffer/').Buffer;
|
||||||
|
|
||||||
@Injectable({providedIn: 'root'})
|
@Injectable({providedIn: 'root'})
|
||||||
|
|
||||||
export class UserService{
|
export class UserService{
|
||||||
|
@ -15,7 +17,6 @@ export class UserService{
|
||||||
address: '',
|
address: '',
|
||||||
session: '',
|
session: '',
|
||||||
blocktime: 0,
|
blocktime: 0,
|
||||||
expired: false,
|
|
||||||
pin: '',
|
pin: '',
|
||||||
validated: false
|
validated: false
|
||||||
},
|
},
|
||||||
|
@ -38,7 +39,9 @@ export class UserService{
|
||||||
paid: false,
|
paid: false,
|
||||||
website: '',
|
website: '',
|
||||||
country: '',
|
country: '',
|
||||||
zats: false
|
zats: false,
|
||||||
|
invoices: false,
|
||||||
|
expiration: new Date(Date.now()).toISOString()
|
||||||
},
|
},
|
||||||
txs : [],
|
txs : [],
|
||||||
countries: []
|
countries: []
|
||||||
|
@ -64,12 +67,12 @@ export class UserService{
|
||||||
private apiKey = 'Le2adeic8Thah4Aeng4daem6i';
|
private apiKey = 'Le2adeic8Thah4Aeng4daem6i';
|
||||||
|
|
||||||
constructor(private http: HttpClient){
|
constructor(private http: HttpClient){
|
||||||
this.reqHeaders = new HttpHeaders().set('Authorization', this.apiKey);
|
var auth = 'Basic ' + Buffer.from('user:superSecret').toString('base64');
|
||||||
|
this.reqHeaders = new HttpHeaders().set('Authorization', auth);
|
||||||
//console.log('US:', this.reqHeaders);
|
//console.log('US:', this.reqHeaders);
|
||||||
this.session = localStorage.getItem('s4z_token');
|
this.session = localStorage.getItem('s4z_token');
|
||||||
if (this.session != null) {
|
if (this.session != null) {
|
||||||
this.findUser();
|
this.findUser();
|
||||||
this.findPending();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -88,12 +91,12 @@ export class UserService{
|
||||||
this.session = localStorage.getItem('s4z_token');
|
this.session = localStorage.getItem('s4z_token');
|
||||||
if (this.session != null) {
|
if (this.session != null) {
|
||||||
const params = new HttpParams().append('session', this.session!);
|
const params = new HttpParams().append('session', this.session!);
|
||||||
let obs = this.http.get<{message: string, user: any}>(this.beUrl+'api/getuser', { headers: this.reqHeaders, params: params, observe: 'response'});
|
let obs = this.http.get<{message: string, user: any}>(this.beUrl+'api/user', { headers: this.reqHeaders, params: params, observe: 'response'});
|
||||||
|
|
||||||
obs.subscribe((UserDataResponse) => {
|
obs.subscribe((UserDataResponse) => {
|
||||||
console.log(UserDataResponse.status);
|
console.log(UserDataResponse.status);
|
||||||
if (UserDataResponse.status == 200){
|
if (UserDataResponse.status == 200){
|
||||||
this.dataStore.user = UserDataResponse.body!.user[0];
|
this.dataStore.user = UserDataResponse.body!.user;
|
||||||
console.log(`US: Found user, returning it`);
|
console.log(`US: Found user, returning it`);
|
||||||
this._uZaddrUpdated.next(Object.assign({},this.dataStore).user.address);
|
this._uZaddrUpdated.next(Object.assign({},this.dataStore).user.address);
|
||||||
this._userUpdated.next(Object.assign({}, this.dataStore).user);
|
this._userUpdated.next(Object.assign({}, this.dataStore).user);
|
||||||
|
@ -103,7 +106,6 @@ export class UserService{
|
||||||
address: '',
|
address: '',
|
||||||
session: '',
|
session: '',
|
||||||
blocktime: 0,
|
blocktime: 0,
|
||||||
expired: false,
|
|
||||||
pin: '',
|
pin: '',
|
||||||
validated: false
|
validated: false
|
||||||
};
|
};
|
||||||
|
@ -120,32 +122,6 @@ export class UserService{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
findPending() {
|
|
||||||
this.session = localStorage.getItem('s4z_token');
|
|
||||||
if (this.session != null) {
|
|
||||||
const params = new HttpParams().append('session', this.session!);
|
|
||||||
let obs = this.http.get<{message: string, txs: any}>(this.beUrl+'api/pending', { headers: this.reqHeaders, params: params, observe: 'response'});
|
|
||||||
|
|
||||||
obs.subscribe((TxDataResponse) => {
|
|
||||||
//console.log('US Tx', TxDataResponse);
|
|
||||||
if (TxDataResponse.status == 200){
|
|
||||||
this.dataStore.txs = TxDataResponse.body!.txs;
|
|
||||||
console.log(`US: Pending logins found`);
|
|
||||||
this._txsUpdated.next(Object.assign({},this.dataStore).txs);
|
|
||||||
} else {
|
|
||||||
console.log('US: Did not find pending txs');
|
|
||||||
this.dataStore.txs = [];
|
|
||||||
this._txsUpdated.next(Object.assign({},this.dataStore).txs);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
return obs;
|
|
||||||
} else {
|
|
||||||
console.log('No session loaded');
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
validateUser(){
|
validateUser(){
|
||||||
var validatedUser: User = this.dataStore.user;
|
var validatedUser: User = this.dataStore.user;
|
||||||
validatedUser.validated = true;
|
validatedUser.validated = true;
|
||||||
|
@ -157,10 +133,9 @@ export class UserService{
|
||||||
|
|
||||||
addOwner(owner: Owner) {
|
addOwner(owner: Owner) {
|
||||||
owner.address = this.dataStore.user.address;
|
owner.address = this.dataStore.user.address;
|
||||||
let obs = this.http.post<{message: string}>(this.beUrl+'api/addowner', {owner: owner}, {headers: this.reqHeaders});
|
let obs = this.http.post(this.beUrl+'api/owner', {payload: owner}, {headers: this.reqHeaders});
|
||||||
|
|
||||||
obs.subscribe((responseData) => {
|
obs.subscribe((responseData) => {
|
||||||
console.log(responseData.message);
|
|
||||||
this.getOwner(this.dataStore.user.address);
|
this.getOwner(this.dataStore.user.address);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -180,12 +155,12 @@ export class UserService{
|
||||||
getOwner(address: string) {
|
getOwner(address: string) {
|
||||||
console.log('getOwner', address);
|
console.log('getOwner', address);
|
||||||
const ownParams = new HttpParams().append('address', address);
|
const ownParams = new HttpParams().append('address', address);
|
||||||
let obs = this.http.get<{message:string, owner: any}>(this.beUrl+'api/getowner', { headers: this.reqHeaders, params: ownParams, observe: 'response'});
|
let obs = this.http.get<{message:string, owner: any}>(this.beUrl+'api/owner', { headers: this.reqHeaders, params: ownParams, observe: 'response'});
|
||||||
|
|
||||||
obs.subscribe((OwnerDataResponse) => {
|
obs.subscribe((OwnerDataResponse) => {
|
||||||
console.log('api/getowner', OwnerDataResponse.status);
|
console.log('api/getowner', OwnerDataResponse.status);
|
||||||
if (OwnerDataResponse.status == 200) {
|
if (OwnerDataResponse.status == 200) {
|
||||||
this.dataStore.owner = OwnerDataResponse.body!.owner[0];
|
this.dataStore.owner = OwnerDataResponse.body!.owner;
|
||||||
//console.log('getOwner object', this.dataStore.owner);
|
//console.log('getOwner object', this.dataStore.owner);
|
||||||
this._ownerUpdated.next(Object.assign({},this.dataStore).owner);
|
this._ownerUpdated.next(Object.assign({},this.dataStore).owner);
|
||||||
this._paidUpdated.next(Object.assign({}, this.dataStore).owner.paid);
|
this._paidUpdated.next(Object.assign({}, this.dataStore).owner.paid);
|
||||||
|
|
|
@ -24,7 +24,6 @@ export class ViewerComponent implements OnInit {
|
||||||
address: '',
|
address: '',
|
||||||
session: '',
|
session: '',
|
||||||
blocktime: 0,
|
blocktime: 0,
|
||||||
expired: false,
|
|
||||||
pin: '',
|
pin: '',
|
||||||
validated: false
|
validated: false
|
||||||
};
|
};
|
||||||
|
@ -48,7 +47,9 @@ export class ViewerComponent implements OnInit {
|
||||||
paid: false,
|
paid: false,
|
||||||
website: '',
|
website: '',
|
||||||
country: '',
|
country: '',
|
||||||
zats: false
|
zats: false,
|
||||||
|
invoices: false,
|
||||||
|
expiration: new Date(Date.now()).toISOString()
|
||||||
};
|
};
|
||||||
public addrUpdate: Observable<string>;
|
public addrUpdate: Observable<string>;
|
||||||
public ownerUpdate: Observable<Owner>;
|
public ownerUpdate: Observable<Owner>;
|
||||||
|
@ -123,7 +124,7 @@ export class ViewerComponent implements OnInit {
|
||||||
this.userUpdate.subscribe((user) => {
|
this.userUpdate.subscribe((user) => {
|
||||||
this.user = user;
|
this.user = user;
|
||||||
//console.log('Viewer loginCheck', this.user);
|
//console.log('Viewer loginCheck', this.user);
|
||||||
if (!this.owner.paid || !this.user.validated || this.user.expired) {
|
if (!this.owner.paid || !this.user.validated) {
|
||||||
console.log('Log in expired!');
|
console.log('Log in expired!');
|
||||||
this.router.navigate(['/login']);
|
this.router.navigate(['/login']);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue