Browse Source

SPA: identity component

pull/49/merge
Carlos Cañizares Estévez 8 years ago
parent
commit
bced5f0a33
5 changed files with 24 additions and 28 deletions
  1. +1
    -1
      src/Web/WebSPA/eShopOnContainers.WebSPA/Client/modules/app.component.html
  2. +2
    -1
      src/Web/WebSPA/eShopOnContainers.WebSPA/Client/modules/shared/components/identity/identity.html
  3. +14
    -9
      src/Web/WebSPA/eShopOnContainers.WebSPA/Client/modules/shared/components/identity/identity.ts
  4. +5
    -15
      src/Web/WebSPA/eShopOnContainers.WebSPA/Client/modules/shared/services/security.service.ts
  5. +2
    -2
      src/Web/WebSPA/eShopOnContainers.WebSPA/project.json

+ 1
- 1
src/Web/WebSPA/eShopOnContainers.WebSPA/Client/modules/app.component.html View File

@ -7,8 +7,8 @@
</a>
</div>
<div class="col-sm-2">
<esh-identity></esh-identity>
<esh-basket-status *ngIf="Authenticated"></esh-basket-status>
<esh-identity *ngIf="!Authenticated"></esh-identity>
</div>
</div>
</div>


+ 2
- 1
src/Web/WebSPA/eShopOnContainers.WebSPA/Client/modules/shared/components/identity/identity.html View File

@ -1 +1,2 @@
<button (click)="login()">Login</button>
<button *ngIf="!authenticated" (click)="login()">Login</button>
<div *ngIf="authenticated">userName: {{userName}}</div>

+ 14
- 9
src/Web/WebSPA/eShopOnContainers.WebSPA/Client/modules/shared/components/identity/identity.ts View File

@ -1,4 +1,5 @@
import { Component, OnInit, OnChanges, Output, Input, EventEmitter } from '@angular/core';
import { Subscription } from 'rxjs/Subscription';
import { IIdentity } from '../../models/identity.model';
import { SecurityService } from '../../services/security.service';
@ -9,22 +10,26 @@ import { SecurityService } from '../../services/security.service';
styleUrls: ['./identity.scss']
})
export class Identity implements OnInit {
constructor(private service: SecurityService) {
}
private authenticated: boolean = false;
private subscription: Subscription;
private userName: string = "";
@Output()
changed: EventEmitter<number> = new EventEmitter<number>();
constructor(private service: SecurityService) {
@Input()
model: IIdentity;
}
ngOnInit() {
console.log("ngOnInit _securityService.AuthorizedCallback");
this.subscription = this.service.authenticationChallenge$.subscribe(res =>
{
//console.log(res);
//console.log(this.service.UserData);
//console.log(this.service);
this.authenticated = res;
this.userName = this.service.UserData.email;
});
if (window.location.hash) {
this.service.AuthorizedCallback();
console.log('isAutorized?');
console.log(this.service.IsAuthorized);
}
}


+ 5
- 15
src/Web/WebSPA/eShopOnContainers.WebSPA/Client/modules/shared/services/security.service.ts View File

@ -16,22 +16,17 @@ export class SecurityService {
authenticationChallenge$ = this.authenticationSource.asObservable();
constructor(private _http: Http, private _router: Router) {
//this.actionUrl = _configuration.Server + 'api/DataEventRecords/';
this.headers = new Headers();
this.headers.append('Content-Type', 'application/json');
this.headers.append('Accept', 'application/json');
this.storage = sessionStorage; //localStorage;
if (this.retrieve("IsAuthorized") !== "") {
//this.HasAdminRole = this.retrieve("HasAdminRole");
this.IsAuthorized = this.retrieve("IsAuthorized");
}
}
public IsAuthorized: boolean;
//public HasAdminRole: boolean;
public GetToken(): any {
return this.retrieve("authorizationData");
@ -42,8 +37,6 @@ export class SecurityService {
this.store("authorizationDataIdToken", "");
this.IsAuthorized = false;
//this.HasAdminRole = false;
this.store("HasAdminRole", false);
this.store("IsAuthorized", false);
}
@ -57,11 +50,13 @@ export class SecurityService {
this.store("authorizationDataIdToken", id_token);
this.IsAuthorized = true;
this.store("IsAuthorized", true);
//emit observable
this.authenticationSource.next(true);
this.getUserData()
.subscribe(data => this.UserData = data,
.subscribe(data => {
this.UserData = data;
//emit observable
this.authenticationSource.next(true);
},
error => this.HandleError(error),
() => {
console.log(this.UserData);
@ -71,8 +66,6 @@ export class SecurityService {
public Authorize() {
this.ResetAuthorizationData();
console.log("BEGIN Authorize, no auth data");
var authorizationUrl = 'http://localhost:5105/connect/authorize';
var client_id = 'js';
var redirect_uri = 'http://localhost:5104/';
@ -83,7 +76,6 @@ export class SecurityService {
this.store("authStateControl", state);
this.store("authNonce", nonce);
console.log("AuthorizedController created. adding myautostate: " + this.retrieve("authStateControl"));
var url =
authorizationUrl + "?" +
@ -98,7 +90,6 @@ export class SecurityService {
}
public AuthorizedCallback() {
console.log("BEGIN AuthorizedCallback, no auth data");
this.ResetAuthorizationData();
var hash = window.location.hash.substr(1);
@ -110,7 +101,6 @@ export class SecurityService {
}, {});
console.log(result);
console.log("AuthorizedCallback created, begin token validation");
var token = "";
var id_token = "";


+ 2
- 2
src/Web/WebSPA/eShopOnContainers.WebSPA/project.json View File

@ -39,8 +39,8 @@
},
"tools": {
"Microsoft.DotNet.Watcher.Tools": {
"version": "1.0.0-*",
"imports": "portable-net451+win8"
"version": "1.0.0-preview2-final",
"imports": "portable-net451+win8+dnxcore50"
},
"Microsoft.AspNetCore.Razor.Tools": {
"version": "1.0.0-preview2-final",


Loading…
Cancel
Save