Enable logout
This commit is contained in:
parent
ba631ebf24
commit
372c7eacf5
16 changed files with 193 additions and 31 deletions
|
@ -271,7 +271,7 @@ app.get('/api/countries', (req, res, next) => {
|
||||||
|
|
||||||
app.get('/api/users', (req, res, next) => {
|
app.get('/api/users', (req, res, next) => {
|
||||||
console.log('Get: /api/users');
|
console.log('Get: /api/users');
|
||||||
usermodel.find({'address': req.query.address, 'session': req.query.session}).
|
usermodel.find({'address': req.query.address, 'session': req.query.session, 'expired': { $ne: true}}).
|
||||||
then((documents) => {
|
then((documents) => {
|
||||||
if (documents != null) {
|
if (documents != null) {
|
||||||
res.status(200).json({
|
res.status(200).json({
|
||||||
|
@ -309,8 +309,7 @@ app.get('/api/pending', (req, res, next) => {
|
||||||
|
|
||||||
app.get('/api/getuser', (req, res, next) => {
|
app.get('/api/getuser', (req, res, next) => {
|
||||||
console.log('Get: /api/getuser/', req.query.session);
|
console.log('Get: /api/getuser/', req.query.session);
|
||||||
var today = new Date().getTime() / 1000;
|
usermodel.find({'session': req.query.session, 'expired': { $ne: true }}).
|
||||||
usermodel.find({'session': req.query.session, 'expiration': { $gt: today }}).
|
|
||||||
then((documents) => {
|
then((documents) => {
|
||||||
if(documents.length > 0){
|
if(documents.length > 0){
|
||||||
//console.log(documents);
|
//console.log(documents);
|
||||||
|
@ -478,6 +477,19 @@ app.delete('/api/item/:id', (req, res, next) => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
app.delete('/api/user/:id', (req, res, next) => {
|
||||||
|
console.log("Delete user", req.params.id);
|
||||||
|
usermodel.findByIdAndUpdate(req.params.id, {expired: true}, function(err, docs) {
|
||||||
|
if (err) {
|
||||||
|
console.log(err);
|
||||||
|
} else {
|
||||||
|
res.status(200).json({
|
||||||
|
message: 'User session deleted'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
app.get('/api/price', (req, res, next) => {
|
app.get('/api/price', (req, res, next) => {
|
||||||
console.log('Get /api/price');
|
console.log('Get /api/price');
|
||||||
const price = pricemodel.findOne({currency: req.query.currency}).then((document) => {
|
const price = pricemodel.findOne({currency: req.query.currency}).then((document) => {
|
||||||
|
|
|
@ -5,7 +5,8 @@ const userSchema = mongoose.Schema({
|
||||||
session: {type: String, required:true},
|
session: {type: String, required:true},
|
||||||
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);
|
||||||
|
|
|
@ -12,7 +12,7 @@ const routes: Routes = [
|
||||||
//{ path: 'create', component: PostCreateComponent, canActivate: [AuthGuardService]},
|
//{ path: 'create', component: PostCreateComponent, canActivate: [AuthGuardService]},
|
||||||
{ path: 'shop', component: ViewerComponent, canActivate: [AuthGuardService]},
|
{ path: 'shop', component: ViewerComponent, canActivate: [AuthGuardService]},
|
||||||
{ path: 'orders', component: ListOrdersComponent, canActivate: [AuthGuardService]},
|
{ path: 'orders', component: ListOrdersComponent, canActivate: [AuthGuardService]},
|
||||||
{ path: 'biz', component: BusinessComponent},
|
{ path: 'biz', component: BusinessComponent, canActivate: [AuthGuardService]},
|
||||||
{ path: 'login', component: LoginComponent, resolve: { response: NodeResolverService}}
|
{ path: 'login', component: LoginComponent, resolve: { response: NodeResolverService}}
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
|
@ -36,6 +36,7 @@ import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
|
||||||
import { BusinessComponent } from './business/business.component';
|
import { BusinessComponent } from './business/business.component';
|
||||||
import { SearchOptionsPipe } from './searchoptions.pipe';
|
import { SearchOptionsPipe } from './searchoptions.pipe';
|
||||||
import { TermsComponent } from './terms/terms.component';
|
import { TermsComponent } from './terms/terms.component';
|
||||||
|
import { LogoutComponent } from './logout/logout.component';
|
||||||
|
|
||||||
@NgModule({
|
@NgModule({
|
||||||
declarations: [
|
declarations: [
|
||||||
|
@ -55,7 +56,8 @@ import { TermsComponent } from './terms/terms.component';
|
||||||
ListOrdersComponent,
|
ListOrdersComponent,
|
||||||
BusinessComponent,
|
BusinessComponent,
|
||||||
SearchOptionsPipe,
|
SearchOptionsPipe,
|
||||||
TermsComponent
|
TermsComponent,
|
||||||
|
LogoutComponent
|
||||||
],
|
],
|
||||||
imports: [
|
imports: [
|
||||||
BrowserModule,
|
BrowserModule,
|
||||||
|
|
|
@ -26,6 +26,8 @@ export class AuthGuardService implements CanActivate {
|
||||||
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): boolean {
|
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): boolean {
|
||||||
const token = localStorage.getItem('s4z_token');
|
const token = localStorage.getItem('s4z_token');
|
||||||
|
|
||||||
|
var path = route.url[0].path;
|
||||||
|
|
||||||
if(token != null){
|
if(token != null){
|
||||||
this.userService.uZaddrUpdate.
|
this.userService.uZaddrUpdate.
|
||||||
subscribe((addr) => {
|
subscribe((addr) => {
|
||||||
|
@ -36,12 +38,21 @@ export class AuthGuardService implements CanActivate {
|
||||||
console.log("No record for that token");
|
console.log("No record for that token");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
if (path === 'biz') {
|
||||||
|
if (this.addr.length > 0) {
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
this.router.navigate(['/login']);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
if (this.addr != null && this.paid) {
|
if (this.addr != null && this.paid) {
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
this.router.navigate(['/login']);
|
this.router.navigate(['/login']);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
console.log("Not logged in");
|
console.log("Not logged in");
|
||||||
this.router.navigate(['/login']);
|
this.router.navigate(['/login']);
|
||||||
|
|
|
@ -24,6 +24,7 @@ import { TermsComponent } from '../terms/terms.component';
|
||||||
export class BusinessComponent implements OnInit {
|
export class BusinessComponent implements OnInit {
|
||||||
|
|
||||||
@ViewChild('stepper', { static: false}) stepper: MatStepper|undefined;
|
@ViewChild('stepper', { static: false}) stepper: MatStepper|undefined;
|
||||||
|
intervalHolder: any;
|
||||||
nodeAddress: string = '';
|
nodeAddress: string = '';
|
||||||
tickets = [
|
tickets = [
|
||||||
{
|
{
|
||||||
|
@ -114,6 +115,9 @@ export class BusinessComponent implements OnInit {
|
||||||
}
|
}
|
||||||
|
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
|
this.intervalHolder = setInterval(() => {
|
||||||
|
this.loginCheck();
|
||||||
|
}, 1000 * 60);
|
||||||
}
|
}
|
||||||
|
|
||||||
ngAfterViewInit(): void {
|
ngAfterViewInit(): void {
|
||||||
|
@ -148,8 +152,8 @@ export class BusinessComponent implements OnInit {
|
||||||
taxValue: 0,
|
taxValue: 0,
|
||||||
vat: false,
|
vat: false,
|
||||||
vatValue: 0,
|
vatValue: 0,
|
||||||
first: '',
|
first: this.bizForm.get('first')!.value,
|
||||||
last: '',
|
last: this.bizForm.get('last')!.value,
|
||||||
phone: '',
|
phone: '',
|
||||||
paid: false,
|
paid: false,
|
||||||
name: this.bizForm.get('name')!.value,
|
name: this.bizForm.get('name')!.value,
|
||||||
|
@ -186,4 +190,12 @@ export class BusinessComponent implements OnInit {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
loginCheck(){
|
||||||
|
this.ownerUpdate.subscribe((owner) => {
|
||||||
|
if(owner.paid) {
|
||||||
|
this.router.navigate(['/shop']);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,4 +8,7 @@
|
||||||
<p class="mini text">Last block:</p>
|
<p class="mini text">Last block:</p>
|
||||||
<p class="mini text">{{heightUpdate | async}}</p>
|
<p class="mini text">{{heightUpdate | async}}</p>
|
||||||
</span>
|
</span>
|
||||||
|
<span>
|
||||||
|
<button mat-raised-button (click)="logout()"><mat-icon class="logbutton">logout</mat-icon></button>
|
||||||
|
</span>
|
||||||
</mat-toolbar>
|
</mat-toolbar>
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
import {Component, OnInit, OnDestroy} from '@angular/core';
|
import {Component, OnInit, OnDestroy} from '@angular/core';
|
||||||
import { MatDialog, MatDialogConfig} from '@angular/material/dialog';
|
import { MatDialog, MatDialogConfig} from '@angular/material/dialog';
|
||||||
import {FullnodeService} from '../fullnode.service';
|
import {FullnodeService} from '../fullnode.service';
|
||||||
|
import { Router } from '@angular/router';
|
||||||
import { UserService } from '../user.service';
|
import { UserService } from '../user.service';
|
||||||
|
import { LogoutComponent } from '../logout/logout.component';
|
||||||
import {Subscription, Observable} from 'rxjs';
|
import {Subscription, Observable} from 'rxjs';
|
||||||
|
|
||||||
import {Owner} from '../owner.model';
|
import {Owner} from '../owner.model';
|
||||||
|
@ -44,7 +46,8 @@ export class HeaderComponent implements OnInit, OnDestroy {
|
||||||
constructor(
|
constructor(
|
||||||
public fullnodeService: FullnodeService,
|
public fullnodeService: FullnodeService,
|
||||||
public userService: UserService,
|
public userService: UserService,
|
||||||
private dialog: MatDialog
|
private dialog: MatDialog,
|
||||||
|
private router: Router
|
||||||
){
|
){
|
||||||
this.heightUpdate = fullnodeService.heightUpdate;
|
this.heightUpdate = fullnodeService.heightUpdate;
|
||||||
this.uZaddrUpdate = userService.uZaddrUpdate;
|
this.uZaddrUpdate = userService.uZaddrUpdate;
|
||||||
|
@ -64,4 +67,23 @@ export class HeaderComponent implements OnInit, OnDestroy {
|
||||||
getCurrency(){
|
getCurrency(){
|
||||||
return this.owner.currency.toUpperCase();
|
return this.owner.currency.toUpperCase();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
logout(){
|
||||||
|
const dialogConfig = new MatDialogConfig();
|
||||||
|
|
||||||
|
dialogConfig.disableClose = true;
|
||||||
|
dialogConfig.autoFocus = true;
|
||||||
|
|
||||||
|
const dialogRef = this.dialog.open(LogoutComponent, dialogConfig);
|
||||||
|
dialogRef.afterClosed().subscribe(val => {
|
||||||
|
if(val){
|
||||||
|
console.log('Logout!');
|
||||||
|
this.userService.deleteUser().subscribe(UserResponse => {
|
||||||
|
console.log('Rerouting');
|
||||||
|
this.userService.findUser();
|
||||||
|
this.router.navigate(['/login']);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,7 +35,7 @@ export class LoginComponent implements OnInit, AfterViewInit {
|
||||||
address: '',
|
address: '',
|
||||||
session: '',
|
session: '',
|
||||||
blocktime: 0,
|
blocktime: 0,
|
||||||
expiration: 0,
|
expired: false,
|
||||||
pin: '',
|
pin: '',
|
||||||
validated: false
|
validated: false
|
||||||
};
|
};
|
||||||
|
|
3
src/app/logout/logout.component.css
Normal file
3
src/app/logout/logout.component.css
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
* {
|
||||||
|
font-family: 'Spartan', sans-serif;
|
||||||
|
}
|
28
src/app/logout/logout.component.html
Normal file
28
src/app/logout/logout.component.html
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
<h3 mat-dialog-title>Logout?</h3>
|
||||||
|
|
||||||
|
<mat-dialog-content>
|
||||||
|
<div align="center">
|
||||||
|
<p>Are you sure you want to disconnect this device from ZGo?</p>
|
||||||
|
<p>You will have to re-link your device to ZGo via Zcash shielded memo if you want to access your shop again.</p>
|
||||||
|
</div>
|
||||||
|
</mat-dialog-content>
|
||||||
|
|
||||||
|
|
||||||
|
<mat-dialog-actions>
|
||||||
|
<table cellspacing="0" width="100%">
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
<button mat-raised-button color="primary" (click)="confirm()">
|
||||||
|
Yes
|
||||||
|
</button>
|
||||||
|
|
||||||
|
</td>
|
||||||
|
<td align="right">
|
||||||
|
<button mat-raised-button (click)="close()">
|
||||||
|
No
|
||||||
|
</button>
|
||||||
|
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
</mat-dialog-actions>
|
25
src/app/logout/logout.component.spec.ts
Normal file
25
src/app/logout/logout.component.spec.ts
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||||
|
|
||||||
|
import { LogoutComponent } from './logout.component';
|
||||||
|
|
||||||
|
describe('LogoutComponent', () => {
|
||||||
|
let component: LogoutComponent;
|
||||||
|
let fixture: ComponentFixture<LogoutComponent>;
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
await TestBed.configureTestingModule({
|
||||||
|
declarations: [ LogoutComponent ]
|
||||||
|
})
|
||||||
|
.compileComponents();
|
||||||
|
});
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
fixture = TestBed.createComponent(LogoutComponent);
|
||||||
|
component = fixture.componentInstance;
|
||||||
|
fixture.detectChanges();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should create', () => {
|
||||||
|
expect(component).toBeTruthy();
|
||||||
|
});
|
||||||
|
});
|
26
src/app/logout/logout.component.ts
Normal file
26
src/app/logout/logout.component.ts
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
import { Component, OnInit } from '@angular/core';
|
||||||
|
import { MatDialog, MatDialogRef, MAT_DIALOG_DATA} from '@angular/material/dialog';
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
selector: 'app-logout',
|
||||||
|
templateUrl: './logout.component.html',
|
||||||
|
styleUrls: ['./logout.component.css']
|
||||||
|
})
|
||||||
|
export class LogoutComponent implements OnInit {
|
||||||
|
|
||||||
|
constructor(
|
||||||
|
private dialogRef: MatDialogRef<LogoutComponent>
|
||||||
|
) { }
|
||||||
|
|
||||||
|
ngOnInit(): void {
|
||||||
|
}
|
||||||
|
|
||||||
|
confirm() {
|
||||||
|
this.dialogRef.close(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
close() {
|
||||||
|
this.dialogRef.close(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -3,7 +3,7 @@ export interface User {
|
||||||
address: string;
|
address: string;
|
||||||
session: string;
|
session: string;
|
||||||
blocktime: number;
|
blocktime: number;
|
||||||
expiration: number;
|
expired: boolean;
|
||||||
pin: string;
|
pin: string;
|
||||||
validated: boolean;
|
validated: boolean;
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,7 +15,7 @@ export class UserService{
|
||||||
address: '',
|
address: '',
|
||||||
session: '',
|
session: '',
|
||||||
blocktime: 0,
|
blocktime: 0,
|
||||||
expiration: 0,
|
expired: false,
|
||||||
pin: '',
|
pin: '',
|
||||||
validated: false
|
validated: false
|
||||||
},
|
},
|
||||||
|
@ -98,6 +98,16 @@ export class UserService{
|
||||||
this._userUpdated.next(Object.assign({}, this.dataStore).user);
|
this._userUpdated.next(Object.assign({}, this.dataStore).user);
|
||||||
this.getOwner(Object.assign({},this.dataStore.user).address);
|
this.getOwner(Object.assign({},this.dataStore.user).address);
|
||||||
} else {
|
} else {
|
||||||
|
this.dataStore.user = {
|
||||||
|
address: '',
|
||||||
|
session: '',
|
||||||
|
blocktime: 0,
|
||||||
|
expired: false,
|
||||||
|
pin: '',
|
||||||
|
validated: false
|
||||||
|
};
|
||||||
|
this._uZaddrUpdated.next(Object.assign({},this.dataStore).user.address);
|
||||||
|
this._userUpdated.next(Object.assign({}, this.dataStore).user);
|
||||||
console.log('US: Did not find user');
|
console.log('US: Did not find user');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -184,13 +194,14 @@ export class UserService{
|
||||||
return obs;
|
return obs;
|
||||||
}
|
}
|
||||||
|
|
||||||
hasOwner() {
|
deleteUser() {
|
||||||
return this.uZaddr === this.oZaddr;
|
let obs = this.http.delete<{message: string}>(this.beUrl+'api/user/'+this.dataStore.user._id, {headers: this.reqHeaders });
|
||||||
}
|
|
||||||
|
|
||||||
getNameUpdateListener() {
|
|
||||||
return this.uNameUpdated;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
obs.subscribe(UserResponse => {
|
||||||
|
console.log('User delete request sent.');
|
||||||
|
this.findUser();
|
||||||
|
});
|
||||||
|
|
||||||
|
return obs;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,7 +24,7 @@ export class ViewerComponent implements OnInit {
|
||||||
address: '',
|
address: '',
|
||||||
session: '',
|
session: '',
|
||||||
blocktime: 0,
|
blocktime: 0,
|
||||||
expiration: 0,
|
expired: false,
|
||||||
pin: '',
|
pin: '',
|
||||||
validated: false
|
validated: false
|
||||||
};
|
};
|
||||||
|
@ -115,11 +115,17 @@ export class ViewerComponent implements OnInit {
|
||||||
}
|
}
|
||||||
|
|
||||||
loginCheck(){
|
loginCheck(){
|
||||||
var today = new Date().getTime() / 1000;
|
this.userService.findUser();
|
||||||
//console.log('User check', this.user.validated);
|
this.ownerUpdate.subscribe((owner) => {
|
||||||
if (!this.owner.paid || !this.user.validated) {
|
this.owner = owner;
|
||||||
|
this.userUpdate.subscribe((user) => {
|
||||||
|
this.user = user;
|
||||||
|
console.log('Viewer loginCheck', this.user);
|
||||||
|
if (!this.owner.paid || !this.user.validated || this.user.expired) {
|
||||||
console.log('Log in expired!');
|
console.log('Log in expired!');
|
||||||
this.router.navigate(['/login']);
|
this.router.navigate(['/login']);
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue