Advertisement
Guest User

Untitled

a guest
Nov 30th, 2016
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. @Injectable()
  2. export class AuthGuard implements CanActivate {
  3.  
  4. public router: Router;
  5. public serverThisLogin: ServerDataComponent;
  6.  
  7. constructor(router: Router) {
  8. this.router = router;
  9. }
  10.  
  11. public canActivate(): boolean {
  12. if (this.serverThisLogin.isLogin) {
  13. return true;
  14. }
  15. this.router.navigate(["/login"]);
  16. return false;
  17. }
  18. }
  19.  
  20. public isLogin (username: string, password: string): Observable<boolean> {
  21. return this.http.post( authURL + loginURL,
  22. JSON.stringify({ password, username }))
  23. .map((response: Response) => {
  24. if (response.status === 200) {
  25. return true;
  26. } else {
  27. return false;
  28. }
  29. });
  30. }
  31.  
  32. { canActivate: [AuthGuard], component: LaskComponent, path: "table_per" }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement