back button issues fixed and missing app module fixed
This commit is contained in:
parent
f1eb384b9a
commit
3b244597ac
@ -167,9 +167,12 @@ export class AwsService {
|
||||
* Logout function
|
||||
*/
|
||||
logout(){
|
||||
|
||||
return Observable.create(observe=>{
|
||||
this.shared.getCurrentUser().signOut();
|
||||
|
||||
observe.next();
|
||||
|
||||
observe.complete();
|
||||
});
|
||||
}
|
||||
|
||||
@ -11,6 +11,7 @@ import {
|
||||
CognitoUserSession
|
||||
} from "amazon-cognito-identity-js";
|
||||
import { environment } from '../../environments/environment';
|
||||
import { BehaviorSubject } from 'rxjs';
|
||||
const sineedge_poolData = {
|
||||
UserPoolId: "ap-south-1_y7dt3iEaX", //ap-south-1_qQ85yQZJO UserName :SPARQ_SINEEDGE_DEV
|
||||
ClientId: "291qt4smn5pql6o8cc2hi201lj" // ClientName: SINEEDGE_DEV_WEB
|
||||
@ -49,6 +50,7 @@ export interface Callback {
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class CognitoService implements CanActivateChild {
|
||||
public loggedIn :boolean = false;
|
||||
// public static _REGION = environment.region;
|
||||
|
||||
// public static _IDENTITY_POOL_ID = environment.identityPoolId;
|
||||
@ -59,6 +61,14 @@ export class CognitoService implements CanActivateChild {
|
||||
// UserPoolId: CognitoService._USER_POOL_ID,
|
||||
// ClientId: CognitoService._CLIENT_ID
|
||||
// };
|
||||
get isLoggedIn() {
|
||||
if(sineedgedevUserpool.getCurrentUser() !=null){
|
||||
this.loggedIn = true;
|
||||
}else{
|
||||
this.loggedIn = false;
|
||||
}
|
||||
return this.loggedIn; // {2}
|
||||
}
|
||||
canActivateChild(){
|
||||
if(this.getToken()){
|
||||
//alert('session valid')
|
||||
@ -82,6 +92,7 @@ isloggin:boolean = false;
|
||||
// }
|
||||
|
||||
getCurrentUser() {
|
||||
|
||||
return sineedgedevUserpool.getCurrentUser();
|
||||
}
|
||||
constructor(public route:Router) { }
|
||||
|
||||
@ -1,54 +1,46 @@
|
||||
// import { Injectable } from '@angular/core';
|
||||
// import { Router, CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot, CanActivateChild } from '@angular/router';
|
||||
// import { Observable , of } from 'rxjs';
|
||||
import { Injectable } from '@angular/core';
|
||||
import { Router, CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot, CanActivateChild } from '@angular/router';
|
||||
import { Observable , of } from 'rxjs';
|
||||
import { CognitoService } from '../AwsService/cognito.service';
|
||||
@Injectable()
|
||||
export class AuthGuard implements CanActivate, CanActivateChild {
|
||||
|
||||
// @Injectable()
|
||||
// export class AuthGuard implements CanActivate, CanActivateChild {
|
||||
constructor(private router: Router,public shared:CognitoService) { }
|
||||
|
||||
// constructor(private router: Router) { }
|
||||
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
|
||||
if (this.shared.getToken()) {
|
||||
alert("if");
|
||||
// this.router.navigate(['']);
|
||||
return true
|
||||
} else {
|
||||
alert("else");
|
||||
this.router.navigate(['/login']);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
|
||||
// if (localStorage.getItem('token') != null) {
|
||||
// // this.router.navigate(['']);
|
||||
// return true
|
||||
// } else {
|
||||
// this.router.navigate(['/login']);
|
||||
// return false;
|
||||
// }
|
||||
// }
|
||||
canActivateChild(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): boolean {
|
||||
|
||||
if (this.shared.getToken()) {
|
||||
// alert("if");
|
||||
|
||||
return true;
|
||||
} else {
|
||||
// alert("else");
|
||||
this.router.navigate(['/login']);
|
||||
return false;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// canActivateChild(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): boolean {
|
||||
// if (this.loginService.loggedIn()) {
|
||||
// let roles = route.data["role"] as Array<string>;
|
||||
// console.log("dataRole: " +roles);
|
||||
// if(roles.length > -1){
|
||||
// var match = this.loginService.roleMatch(roles);
|
||||
// if(match){
|
||||
// // this.router.navigate(['./dashboard']);
|
||||
// return this.loginService.loggedIn()
|
||||
// }
|
||||
// else {
|
||||
// this.router.navigate(['./404']);
|
||||
// return this.loginService.loggedIn();
|
||||
// }
|
||||
// } else {
|
||||
// this.router.navigate(['/login']);
|
||||
// return this.loginService.loggedIn();
|
||||
// }
|
||||
// } else {
|
||||
// this.router.navigate(['/login']);
|
||||
// return this.loginService.loggedIn();
|
||||
// }
|
||||
// }
|
||||
// public getToken(): string {
|
||||
// return localStorage.getItem('token');
|
||||
// }
|
||||
|
||||
// public getToken(): string {
|
||||
// return localStorage.getItem('token');
|
||||
// }
|
||||
|
||||
// public logOut() {
|
||||
// localStorage.clear();
|
||||
// if(localStorage.getItem('token') === null){
|
||||
// this.router.navigate(['/login']);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// public logOut() {
|
||||
// localStorage.clear();
|
||||
// if(localStorage.getItem('token') === null){
|
||||
// this.router.navigate(['/login']);
|
||||
// }
|
||||
// }
|
||||
}
|
||||
@ -30,7 +30,7 @@ import {MatCheckboxModule} from '@angular/material/checkbox';
|
||||
import {MatProgressBarModule} from '@angular/material/progress-bar';
|
||||
import {MatSelectModule} from '@angular/material/select';
|
||||
import {MatCardModule} from '@angular/material/card';
|
||||
import { ChangePasswordDialog } from './settings/users/'
|
||||
import {ChangePasswordDialog} from './settings/users/user-profile/user-profile.component';
|
||||
|
||||
import { AppRoutes } from './app.routing';
|
||||
import { AppComponent } from './app.component';
|
||||
@ -40,6 +40,7 @@ import { SharedModule } from './shared/shared.module';
|
||||
import { AwsService } from './AwsService/aws.service';
|
||||
import { TokenInterceptor } from './_guard/token.interceptor';
|
||||
import { NewPasswordDialog, ForgotPass } from './session/login/login.component';
|
||||
import { AuthGuard } from './_guard/auth.guard';
|
||||
export function HttpLoaderFactory(http: HttpClient) {
|
||||
return new TranslateHttpLoader(http);
|
||||
}
|
||||
@ -57,7 +58,7 @@ const DEFAULT_PERFECT_SCROLLBAR_CONFIG: PerfectScrollbarConfigInterface = {
|
||||
AppComponent,
|
||||
AdminLayoutComponent,
|
||||
AuthLayoutComponent,
|
||||
NewPasswordDialog,ForgotPass,ChangePasswordDialog
|
||||
NewPasswordDialog,ForgotPass,ChangePasswordDialog,
|
||||
],
|
||||
imports: [
|
||||
BrowserModule,
|
||||
@ -93,7 +94,7 @@ const DEFAULT_PERFECT_SCROLLBAR_CONFIG: PerfectScrollbarConfigInterface = {
|
||||
provide: LocationStrategy,
|
||||
useClass: HashLocationStrategy,
|
||||
},
|
||||
AwsService,
|
||||
AwsService,AuthGuard,
|
||||
TranslateService,
|
||||
// {
|
||||
// provide: PERFECT_SCROLLBAR_CONFIG,
|
||||
|
||||
@ -3,6 +3,7 @@ import { Routes } from '@angular/router';
|
||||
import { AdminLayoutComponent } from './layouts/admin/admin-layout.component';
|
||||
import { AuthLayoutComponent } from './layouts/auth/auth-layout.component';
|
||||
import { CognitoService} from './AwsService/cognito.service';
|
||||
import { AuthGuard } from './_guard/auth.guard';
|
||||
export const AppRoutes: Routes = [{
|
||||
path: '',
|
||||
redirectTo: 'home',
|
||||
@ -10,7 +11,7 @@ export const AppRoutes: Routes = [{
|
||||
}, {
|
||||
path: '',
|
||||
component: AdminLayoutComponent,
|
||||
canActivateChild:[CognitoService],
|
||||
canActivateChild:[AuthGuard],
|
||||
children: [{
|
||||
path: 'home',
|
||||
loadChildren: './dashboard/dashboard.module#DashboardModule'
|
||||
|
||||
@ -20,7 +20,7 @@ import { CognitoService } from '../../AwsService/cognito.service';
|
||||
styleUrls: ['./login-component.scss'],
|
||||
encapsulation: ViewEncapsulation.None,
|
||||
})
|
||||
export class LoginComponent {
|
||||
export class LoginComponent implements OnInit{
|
||||
changepass: FormGroup;
|
||||
email: string;
|
||||
password: string;
|
||||
@ -43,6 +43,10 @@ export class LoginComponent {
|
||||
private router: Router, public aws: AwsService, public dialog: MatDialog,
|
||||
public shared:CognitoService,) {
|
||||
|
||||
}
|
||||
ngOnInit(){
|
||||
this.loggedInCheck();
|
||||
|
||||
}
|
||||
/**
|
||||
* @param email
|
||||
@ -103,9 +107,17 @@ export class LoginComponent {
|
||||
console.log(res);
|
||||
|
||||
})
|
||||
|
||||
|
||||
|
||||
}
|
||||
loggedInCheck(){
|
||||
//alert(this.shared.isLoggedIn);
|
||||
if(this.shared.isLoggedIn){
|
||||
// alert("if");
|
||||
this.router.navigate(['/home']);
|
||||
return false;
|
||||
}else{
|
||||
//alert("else");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user