徐明 %!s(int64=6) %!d(string=hai) anos
pai
achega
0ca39fee62

+ 6 - 1
CasinosManager/src/app/content/content.component.css

@@ -21,9 +21,14 @@ line-height: inherit;
     box-shadow: inset -1px 0 0 rgba(0, 0, 0, .1);
 }
 
-.sidebar .nav-item
+.nav-top{
+    list-style: none;
+}
+
+.nav-top .nav-item
 {
     padding-left: 25px;
+    list-style: none;
 }
 
 .main{

+ 2 - 2
CasinosManager/src/app/content/content.component.html

@@ -2,10 +2,10 @@
     <a class="navbar-brand col-sm-3 col-md-2 mr-0" href="#">CasinosManager</a>
     <ul class="nav-top px-3">
         <li class="nav-item text-nowrap">
-            <a class="nav-link" href="#">loginName</a>
+            <a class="nav-link" href="#">{{userinfo.userName}}</a>
         </li>
         <li class="nav-item text-nowrap">
-            <a class="nav-link" href="#">Sign out</a>
+            <button type="button" class="btn btn-success" style="box-shadow: 0px" (click)="logout()">注销</button>
         </li>
     </ul>
 </nav>

+ 19 - 1
CasinosManager/src/app/content/content.component.ts

@@ -1,4 +1,7 @@
 import { Component, OnInit } from '@angular/core';
+import { Router } from '@angular/router';
+import { AppSessionService } from '../shared/auth/app-session.service'
+import { TokenAuthService, UserInfo } from '../shared/service-proxy/token-auth.service'
 
 @Component({
   selector: 'app-content',
@@ -7,9 +10,24 @@ import { Component, OnInit } from '@angular/core';
 })
 export class ContentComponent implements OnInit {
 
-  constructor() { }
+  userinfo:UserInfo;
+
+  constructor(
+    private _sessionService: AppSessionService,
+    private _tokenAuthService: TokenAuthService,
+    private _router: Router
+    ) { }
 
   ngOnInit() {
+    this.userinfo = this._sessionService.user;
+  }
+
+  logout(){
+    this._tokenAuthService.logout()
+    .subscribe((result)=>{
+      this._router.navigate(['account'])
+      document.cookie = "auth_token=" + escape('') + ";expires=-1";
+    })
   }
 
 }

+ 19 - 3
CasinosManager/src/app/shared/service-proxy/token-auth.service.ts

@@ -16,7 +16,7 @@ export class TokenAuthService{
   }
 
   authenticate(authenticateModel:AuthenticateModel): Observable<AuthenticateResult> {
-    let url = this.baseUrl + "/connect/token";
+    let url = "http://localhost:54225/api/identity";
 
     return this.http.post<AuthenticateResult>(url, authenticateModel).pipe(
       tap(item => console.log("authenticate user")),
@@ -35,12 +35,28 @@ export class TokenAuthService{
     })
     };
 
-    return this.http.get<UserInfo>(url).pipe(
+    return this.http.get<UserInfo>(url,options_).pipe(
       tap(item => console.log("authenticate user")),
       catchError(this.handleError<UserInfo>("authenticate user"))
     );
   }
 
+  logout(): Observable<boolean> {
+    let url = "http://localhost:54225/api/identity";
+    let options_ = {
+      headers : new HttpHeaders({
+        "Content-Type": "application/json",
+        "Accept": "application/json",
+        "Authorization": "Bearer " + this.getCookie("auth_token")
+    })
+    };
+
+    return this.http.delete<boolean>(url, options_).pipe(
+      tap(item => console.log("authenticate logout")),
+      catchError(this.handleError<boolean>("authenticate logout"))
+    );
+  }
+
   private getCookie(name) {
     var arr, reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)"); //正则匹配
     if (arr = document.cookie.match(reg)) {
@@ -81,7 +97,7 @@ export class AuthenticateModel {
 
 export class AuthenticateResult{
   access_token: string;
-  expires_in: string;
+  expires_in: number;
   token_type: string;
 }