Fix: Save account error was because in constructor type did not end in underscore

Fix: Employee save as checking for in None instead of is None

Feature: Checking the existing token for validity in constructor of auth service, this should prevent last login showing
Feature: Moved the middleware secret key into the env file

Chore: Replaced my own GUID() with postgres UUID() type
This commit is contained in:
2020-06-30 11:32:09 +05:30
parent 6ccb3634be
commit ad8a2d2cc3
19 changed files with 132 additions and 171 deletions

View File

@ -16,12 +16,28 @@ export class AuthService {
public currentUser: Observable<User>;
constructor(private http: HttpClient) {
this.currentUserSubject = new BehaviorSubject<User>(JSON.parse(localStorage.getItem(JWT_USER)));
const existingToken: User = JSON.parse(localStorage.getItem(JWT_USER));
if (existingToken === null || Date.now() > existingToken.exp * 1000) {
localStorage.removeItem(JWT_USER);
this.currentUserSubject = new BehaviorSubject<User>(null);
} else {
this.currentUserSubject = new BehaviorSubject<User>(existingToken);
}
this.currentUser = this.currentUserSubject.asObservable();
}
public get user(): User {
return this.currentUserSubject.value;
const val = this.currentUserSubject.value;
if (val == null) {
return val;
}
const expired = Date.now() > val.exp * 1000;
if (expired) {
this.logout();
return null;
} else {
return this.currentUserSubject.value;
}
}
login(username: string, password: string, otp: string) {

View File

@ -60,7 +60,7 @@ export class LoginComponent implements OnInit, AfterViewInit {
this.router.navigate([this.returnUrl]);
},
(error) => {
if (error.status === 401 && 'Client is not registered' == error.error.detail) {
if (error.status === 401 && 'Client is not registered' === error.error.detail) {
this.showOtp = true;
this.clientId = this.cs.getCookie('client_id');
}

View File

@ -18,7 +18,7 @@ export class JwtInterceptor implements HttpInterceptor {
// console.log("intercepting:\nisRefreshing: ", this.isRefreshing, "\n user: ", this.authService.user,"\n needsRefreshing: ", this.authService.needsRefreshing());
if (!this.isRefreshing && this.authService.user && this.authService.needsRefreshing()) {
this.isRefreshing = true;
this.authService.refreshToken().subscribe( x=> this.isRefreshing = false);
this.authService.refreshToken().subscribe( x => this.isRefreshing = false);
}
const currentUser = this.authService.user;
if (currentUser?.access_token) {

View File

@ -1,13 +1,13 @@
import {AfterViewInit, Component, ElementRef, OnInit, ViewChild} from '@angular/core';
import { AfterViewInit, Component, ElementRef, OnInit, ViewChild } from '@angular/core';
import { MatPaginator } from '@angular/material/paginator';
import { MatSort } from '@angular/material/sort';
import {ProductListDataSource} from './product-list-datasource';
import {Product} from '../../core/product';
import {ActivatedRoute} from '@angular/router';
import {debounceTime, distinctUntilChanged, startWith} from 'rxjs/operators';
import {FormBuilder, FormGroup} from '@angular/forms';
import {Observable} from 'rxjs';
import {ToCsvService} from "../../shared/to-csv.service";
import { ProductListDataSource } from './product-list-datasource';
import { Product } from '../../core/product';
import { ActivatedRoute } from '@angular/router';
import { debounceTime, distinctUntilChanged, startWith } from 'rxjs/operators';
import { FormBuilder, FormGroup } from '@angular/forms';
import { Observable } from 'rxjs';
import { ToCsvService } from '../../shared/to-csv.service';
@Component({
selector: 'app-product-list',
@ -15,6 +15,25 @@ import {ToCsvService} from "../../shared/to-csv.service";
styleUrls: ['./product-list.component.css']
})
export class ProductListComponent implements OnInit, AfterViewInit {
constructor(private route: ActivatedRoute, private fb: FormBuilder, private toCsv: ToCsvService) {
this.showExtended = false;
this.createForm();
this.filter = this.listenToFilterChange();
}
get showExtended(): boolean {
return this._showExtended;
}
set showExtended(value: boolean) {
this._showExtended = value;
if (value) {
this.displayedColumns = ['name', 'costPrice', 'productYield', 'productGroup', 'info'];
} else {
this.displayedColumns = ['name', 'costPrice', 'productGroup', 'info'];
}
}
@ViewChild('filterElement', { static: true }) filterElement: ElementRef;
@ViewChild(MatPaginator, { static: true }) paginator: MatPaginator;
@ViewChild(MatSort, { static: true }) sort: MatSort;
@ -25,11 +44,7 @@ export class ProductListComponent implements OnInit, AfterViewInit {
/** Columns displayed in the table. Columns IDs can be added, removed, or reordered. */
displayedColumns: string[];
constructor(private route: ActivatedRoute, private fb: FormBuilder, private toCsv: ToCsvService) {
this.showExtended = false;
this.createForm();
this.filter = this.listenToFilterChange();
}
private _showExtended: boolean;
createForm() {
this.form = this.fb.group({
@ -60,21 +75,6 @@ export class ProductListComponent implements OnInit, AfterViewInit {
}, 0);
}
private _showExtended: boolean;
get showExtended(): boolean {
return this._showExtended;
}
set showExtended(value: boolean) {
this._showExtended = value;
if (value) {
this.displayedColumns = ['name', 'costPrice', 'productYield', 'productGroup', 'info'];
} else {
this.displayedColumns = ['name', 'costPrice', 'productGroup', 'info'];
}
}
exportCsv() {
const headers = {
Code: 'code',

View File

@ -1,9 +1,9 @@
import {Injectable} from '@angular/core';
import {HttpClient, HttpHeaders, HttpParams} from '@angular/common/http';
import {ErrorLoggerService} from '../core/error-logger.service';
import {catchError} from 'rxjs/operators';
import {Observable} from 'rxjs/internal/Observable';
import {Role} from './role';
import { Injectable } from '@angular/core';
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { ErrorLoggerService } from '../core/error-logger.service';
import { catchError } from 'rxjs/operators';
import { Observable } from 'rxjs/internal/Observable';
import { Role } from './role';
const httpOptions = {
headers: new HttpHeaders({'Content-Type': 'application/json'})

View File

@ -1,9 +1,9 @@
import {Injectable} from '@angular/core';
import {HttpClient, HttpHeaders, HttpParams} from '@angular/common/http';
import {ErrorLoggerService} from '../core/error-logger.service';
import {catchError} from 'rxjs/operators';
import {Observable} from 'rxjs/internal/Observable';
import {User} from '../core/user';
import { Injectable } from '@angular/core';
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { ErrorLoggerService } from '../core/error-logger.service';
import { catchError } from 'rxjs/operators';
import { Observable } from 'rxjs/internal/Observable';
import { User } from '../core/user';
const httpOptions = {
headers: new HttpHeaders({'Content-Type': 'application/json'})