This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @Injectable() | |
| export class UserService { | |
| constructor(private http: AuthHttp) { | |
| FB.init({ | |
| appId : ‘YOUR-APP-ID-HERE’, | |
| status : false, // the SDK will attempt to get info about the current user immediately after init | |
| cookie : false, // enable cookies to allow the server to access | |
| // the session | |
| xfbml : false, // With xfbml set to true, the SDK will parse your page's DOM to find and initialize any social plugins that have been added using XFBML |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!doctype html> | |
| <html> | |
| <head> | |
| <meta charset="utf-8" > | |
| <title>AngularBootstrapDemo</title> | |
| <base href=”/”> | |
| <meta name=”viewport” content="width=device-width, initial-scale=1"> | |
| <link rel=”icon” type="image/x-icon” href=”favicon.ico"> | |
| <script src="//connect.facebook.net/en_US/sdk.js"></script> | |
| </head> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @Injectable() | |
| export class AuthGuard implements CanActivate { | |
| constructor(private userService: UserService, private router: Router) {} | |
| canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) { | |
| return this.checkLogin(); | |
| } | |
| checkLogin(): Promise<boolean> { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @Injectable() | |
| export class AnonymousGuard implements CanActivate { | |
| constructor(private userService: UserService, private router: Router) {} | |
| canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) { | |
| return this.checkLogin(); | |
| } | |
| checkLogin(): Promise<boolean> { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @Component({ | |
| selector: 'app-login', | |
| templateUrl: './login.component.html', | |
| styleUrls: ['./login.component.sass'] | |
| }) | |
| export class LoginComponent implements OnInit { | |
| constructor(private userService: UserService, private router: Router) { } | |
| ngOnInit() { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <div class="navbar navbar-default navbar-fixed-top"> | |
| </div> | |
| <div class="page-header"></div> | |
| <div class="container"> | |
| <div class="row"> | |
| <div class="col-lg-8 col-md-7 col-sm-6"> | |
| <div class="panel panel-default"> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @Component({ | |
| selector: 'app-dashboard', | |
| templateUrl: './dashboard.component.html', | |
| styleUrls: ['./dashboard.component.sass'] | |
| }) | |
| export class DashboardComponent implements OnInit { | |
| public currentUser : any = {}; | |
| constructor(private userService: UserService, private router: Router) { } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <div class="navbar navbar-default navbar-fixed-top"> | |
| <ul class="nav navbar-nav navbar-right"> | |
| <li role="menuitem"><a class="dropdown-item" (click)="logout()">Logout</a></li> | |
| </ul> | |
| </div> | |
| <div class="page-header"></div> | |
| <div class="container"> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const appRoutes: Routes = [ | |
| { | |
| path: 'welcome', | |
| component: LoginComponent, | |
| canActivate: [AnonymousGuard] | |
| }, | |
| { | |
| path: 'dashboard', | |
| component: DashboardComponent, | |
| canActivate: [AuthGuard] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| export function getAuthHttp(http: Http) { | |
| return new AuthHttp(new AuthConfig({ | |
| headerName: 'x-auth-token', | |
| noTokenScheme: true, | |
| noJwtError: true, | |
| globalHeaders: [{'Accept': 'application/json'}], | |
| tokenGetter: (() => localStorage.getItem('id_token')), | |
| }), http); | |
| } |
OlderNewer