diff --git a/backend/models/user.js b/backend/models/user.js index 11a983b..f4145bc 100644 --- a/backend/models/user.js +++ b/backend/models/user.js @@ -6,7 +6,6 @@ const userSchema = mongoose.Schema({ blocktime: {type: Number, required:true}, pin: {type: String, required:true}, validated: {type: Boolean, required:true}, - expired: {type: Boolean, required:true, default: false} }); module.exports = mongoose.model('User', userSchema); diff --git a/src/app/business/business.component.ts b/src/app/business/business.component.ts index bb345ff..b5ce34a 100644 --- a/src/app/business/business.component.ts +++ b/src/app/business/business.component.ts @@ -63,7 +63,9 @@ export class BusinessComponent implements OnInit { country: '', email: '', website: '', - zats: false + zats: false, + invoices: false, + expiration: new Date(Date.now()).toISOString() } public countriesUpdate: Observable; public ownerUpdate: Observable; @@ -147,6 +149,7 @@ export class BusinessComponent implements OnInit { save() { this.owner = { + _id: '', address: '', currency: 'usd', tax: false, @@ -165,7 +168,9 @@ export class BusinessComponent implements OnInit { country: this.bizForm.get('country')!.value, email: this.bizForm.get('email')!.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.stepper!.next(); diff --git a/src/app/fullnode.service.ts b/src/app/fullnode.service.ts index d652816..6ad96ad 100644 --- a/src/app/fullnode.service.ts +++ b/src/app/fullnode.service.ts @@ -4,6 +4,7 @@ import {HttpClient, HttpParams, HttpHeaders} from '@angular/common/http'; import {UserService} from './user.service'; import { Owner } from './owner.model'; +var Buffer = require('buffer/').Buffer; //import {User} from './user.model'; @Injectable({providedIn: 'root'}) @@ -42,11 +43,14 @@ export class FullnodeService{ paid: false, website: '', country: '', - zats: false + zats: false, + invoices: false, + expiration: new Date(Date.now()).toISOString() }; 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.getAddr(); this.getHeight(); diff --git a/src/app/header/header.component.ts b/src/app/header/header.component.ts index 298b4ff..37ee99b 100644 --- a/src/app/header/header.component.ts +++ b/src/app/header/header.component.ts @@ -37,7 +37,9 @@ export class HeaderComponent implements OnInit, OnDestroy { paid: false, website: '', country: '', - zats: false + zats: false, + invoices: false, + expiration: new Date(Date.now()).toISOString() }; private session: string | null = ''; public heightUpdate: Observable; diff --git a/src/app/item.model.ts b/src/app/item.model.ts index e94757f..6c4c331 100644 --- a/src/app/item.model.ts +++ b/src/app/item.model.ts @@ -2,6 +2,6 @@ export interface Item { _id?: any; name: string; description: string; - user: string; + owner: string; cost: number; } diff --git a/src/app/items/item-create/item-create.component.ts b/src/app/items/item-create/item-create.component.ts index ed5790a..c5bdbaf 100644 --- a/src/app/items/item-create/item-create.component.ts +++ b/src/app/items/item-create/item-create.component.ts @@ -23,7 +23,7 @@ export class ItemCreateComponent implements OnInit { ){ if (data._id === '') { this.form = fb.group({ - id: [null], + id: [''], name: [null, Validators.required], description: [null, Validators.required], cost: new FormControl('', { @@ -49,6 +49,7 @@ export class ItemCreateComponent implements OnInit { } save() { + console.log(this.form.value); this.dialogRef.close(this.form.value); } diff --git a/src/app/items/item-list/item-list.component.ts b/src/app/items/item-list/item-list.component.ts index 80eec30..c08ac73 100644 --- a/src/app/items/item-list/item-list.component.ts +++ b/src/app/items/item-list/item-list.component.ts @@ -40,7 +40,9 @@ export class ItemListComponent implements OnInit{ paid: false, website: '', country: '', - zats: false + zats: false, + invoices: false, + expiration: new Date(Date.now()).toISOString() }; public price: number = 1; public ownerUpdate: Observable; @@ -87,7 +89,7 @@ export class ItemListComponent implements OnInit{ dialogRef.afterClosed().subscribe((val) => { 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.getItems(this.owner.address); @@ -98,9 +100,9 @@ export class ItemListComponent implements OnInit{ } edit(id: string) { - //console.log('Edit:', id); + console.log('Edit:', id); const item = this.items.find(element => element._id == id); - //console.log(item); + console.log(item); const dialogConfig = new MatDialogConfig(); dialogConfig.disableClose = true; @@ -115,7 +117,7 @@ export class ItemListComponent implements OnInit{ name: val.name, description: val.description, cost: val.cost, - user: this.owner.address + owner: this.owner.address }; //console.log('Edit:', editItem); this.itemService.addItem(editItem).subscribe((response) => { diff --git a/src/app/items/item.model.ts b/src/app/items/item.model.ts index 3e239f5..982ee08 100644 --- a/src/app/items/item.model.ts +++ b/src/app/items/item.model.ts @@ -3,5 +3,5 @@ export interface Item { name: string; description: string; cost: number; - user: string; + owner: string; } diff --git a/src/app/items/items.service.ts b/src/app/items/items.service.ts index 1cb6cb2..c93c509 100644 --- a/src/app/items/items.service.ts +++ b/src/app/items/items.service.ts @@ -3,6 +3,8 @@ import { Injectable } from '@angular/core'; import { Subject, BehaviorSubject, Observable } from 'rxjs'; import { HttpClient, HttpParams, HttpHeaders } from '@angular/common/http'; +var Buffer = require('buffer/').Buffer; + @Injectable({providedIn: 'root'}) export class ItemService{ @@ -15,13 +17,14 @@ export class ItemService{ private reqHeaders: HttpHeaders; 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){ this.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) => { if (ItemDataResponse.status == 200 ) { @@ -39,7 +42,7 @@ export class ItemService{ addItem(item: 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) => { console.log('Item added'); diff --git a/src/app/login/login.component.ts b/src/app/login/login.component.ts index 315379f..02c60e0 100644 --- a/src/app/login/login.component.ts +++ b/src/app/login/login.component.ts @@ -35,7 +35,6 @@ export class LoginComponent implements OnInit, AfterViewInit { address: '', session: '', blocktime: 0, - expired: false, pin: '', validated: false }; @@ -58,7 +57,9 @@ export class LoginComponent implements OnInit, AfterViewInit { paid: false, website: '', country: '', - zats: false + zats: false, + invoices: false, + expiration: new Date(Date.now()).toISOString() }; private FullnodeSub: Subscription = new Subscription(); private UserSub: Subscription = new Subscription(); @@ -152,12 +153,7 @@ export class LoginComponent implements OnInit, AfterViewInit { } loginCheck(){ - var today = new Date().getTime() / 1000; this.userService.findUser(); - this.userService.findPending(); - this.txsUpdate.subscribe((txs) => { - this.txs = txs; - }); this.userUpdate.subscribe((user) => { if (user.blocktime > 0) { 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) { diff --git a/src/app/order/order.service.ts b/src/app/order/order.service.ts index 6e64ac4..a9b2817 100644 --- a/src/app/order/order.service.ts +++ b/src/app/order/order.service.ts @@ -8,6 +8,8 @@ import { User } from '../user.model'; import { Owner } from '../owner.model'; import { LineItem} from '../items/lineitem.model'; +var Buffer = require('buffer/').Buffer; + @Injectable({providedIn: 'root'}) export class OrderService { @@ -18,7 +20,6 @@ export class OrderService { address: '', session: '', blocktime: 0, - expired: false, pin: '', validated: false }, @@ -42,7 +43,9 @@ export class OrderService { paid: false, website: '', country: '', - zats: false + zats: false, + invoices: false, + expiration: new Date(Date.now()).toISOString() }, order: { address: '', @@ -78,7 +81,8 @@ export class OrderService { public fullnodeService: FullnodeService, 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.ownerUpdate = userService.ownerUpdate; this.userUpdate.subscribe((user) => { @@ -132,7 +136,8 @@ export class OrderService { addToOrder(lineItem: LineItem) { 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) => { this.getOrder(); }); @@ -143,21 +148,21 @@ export class OrderService { createOrder(lineItem: LineItem) { var order:Order = { + _id: '', address: this.dataStore.user.address, session: this.dataStore.user.session, currency: this.dataStore.owner.currency, + timestamp: new Date(Date.now()).toISOString(), closed: false, totalZec: 0, price: 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) => { - console.log('Create order', orderData); - this.dataStore.order = orderData.order; - this._orderUpdated.next(Object.assign({}, this.dataStore).order); - this.addToOrder(lineItem); + console.log('Created order'); + this.getOrder() }); return obs; @@ -197,7 +202,7 @@ export class OrderService { this.dataStore.order.price = price; }); 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) => { console.log('Closed order', orderData); this.dataStore.order = { diff --git a/src/app/owner.model.ts b/src/app/owner.model.ts index b80dc95..e371de6 100644 --- a/src/app/owner.model.ts +++ b/src/app/owner.model.ts @@ -19,4 +19,6 @@ export interface Owner { website: string; country: string; zats: boolean; + invoices: boolean; + expiration: string; } diff --git a/src/app/receipt.service.ts b/src/app/receipt.service.ts index 7999d03..d0b55fc 100644 --- a/src/app/receipt.service.ts +++ b/src/app/receipt.service.ts @@ -5,6 +5,8 @@ import { Order } from './order/order.model'; import { Owner } from './owner.model'; import { UserService } from './user.service'; +var Buffer = require('buffer/').Buffer; + @Injectable({ providedIn: 'root' }) @@ -31,7 +33,9 @@ export class ReceiptService { paid: false, website: '', country: '', - zats: false + zats: false, + invoices: false, + expiration: new Date(Date.now()).toISOString() }, order: { address: '', @@ -63,13 +67,14 @@ export class ReceiptService { 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; } getOrderById(id:string) { - 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'}); + //const params = new HttpParams().append('id', id); + let obs = this.http.get<{message: string, order: any}>(this.beUrl+'api/order/'+id, { headers:this.reqHeaders, observe: 'response'}); obs.subscribe((OrderDataResponse) => { if (OrderDataResponse.status == 200) { diff --git a/src/app/user.model.ts b/src/app/user.model.ts index d555e82..82194a9 100644 --- a/src/app/user.model.ts +++ b/src/app/user.model.ts @@ -3,7 +3,6 @@ export interface User { address: string; session: string; blocktime: number; - expired: boolean; pin: string; validated: boolean; } diff --git a/src/app/user.service.ts b/src/app/user.service.ts index 82edb75..3b567dc 100644 --- a/src/app/user.service.ts +++ b/src/app/user.service.ts @@ -6,6 +6,8 @@ import {Owner} from './owner.model'; import { Country } from './country.model'; import {Tx} from './tx.model'; +var Buffer = require('buffer/').Buffer; + @Injectable({providedIn: 'root'}) export class UserService{ @@ -15,7 +17,6 @@ export class UserService{ address: '', session: '', blocktime: 0, - expired: false, pin: '', validated: false }, @@ -38,7 +39,9 @@ export class UserService{ paid: false, website: '', country: '', - zats: false + zats: false, + invoices: false, + expiration: new Date(Date.now()).toISOString() }, txs : [], countries: [] @@ -64,12 +67,12 @@ export class UserService{ private apiKey = 'Le2adeic8Thah4Aeng4daem6i'; 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); this.session = localStorage.getItem('s4z_token'); if (this.session != null) { this.findUser(); - this.findPending(); } } @@ -88,12 +91,12 @@ export class UserService{ 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, 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) => { console.log(UserDataResponse.status); if (UserDataResponse.status == 200){ - this.dataStore.user = UserDataResponse.body!.user[0]; + this.dataStore.user = UserDataResponse.body!.user; console.log(`US: Found user, returning it`); this._uZaddrUpdated.next(Object.assign({},this.dataStore).user.address); this._userUpdated.next(Object.assign({}, this.dataStore).user); @@ -103,7 +106,6 @@ export class UserService{ address: '', session: '', blocktime: 0, - expired: false, pin: '', 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(){ var validatedUser: User = this.dataStore.user; validatedUser.validated = true; @@ -157,10 +133,9 @@ export class UserService{ addOwner(owner: Owner) { 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) => { - console.log(responseData.message); this.getOwner(this.dataStore.user.address); }); @@ -180,12 +155,12 @@ export class UserService{ getOwner(address: string) { console.log('getOwner', 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) => { console.log('api/getowner', OwnerDataResponse.status); if (OwnerDataResponse.status == 200) { - this.dataStore.owner = OwnerDataResponse.body!.owner[0]; + this.dataStore.owner = OwnerDataResponse.body!.owner; //console.log('getOwner object', this.dataStore.owner); this._ownerUpdated.next(Object.assign({},this.dataStore).owner); this._paidUpdated.next(Object.assign({}, this.dataStore).owner.paid); diff --git a/src/app/viewer/viewer.component.ts b/src/app/viewer/viewer.component.ts index 39f2286..0c1f481 100644 --- a/src/app/viewer/viewer.component.ts +++ b/src/app/viewer/viewer.component.ts @@ -24,7 +24,6 @@ export class ViewerComponent implements OnInit { address: '', session: '', blocktime: 0, - expired: false, pin: '', validated: false }; @@ -48,7 +47,9 @@ export class ViewerComponent implements OnInit { paid: false, website: '', country: '', - zats: false + zats: false, + invoices: false, + expiration: new Date(Date.now()).toISOString() }; public addrUpdate: Observable; public ownerUpdate: Observable; @@ -123,7 +124,7 @@ export class ViewerComponent implements OnInit { this.userUpdate.subscribe((user) => { this.user = 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!'); this.router.navigate(['/login']); }