Guest User

Untitled

a guest
May 23rd, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.72 KB | None | 0 0
  1. export class AuthenticatetokenComponent implements OnInit {
  2.  
  3. constructor(private authService: AuthService,private spinner: NgxSpinnerService) {}
  4.  
  5. public showSpinner() {
  6. this.spinner.show();
  7. }
  8.  
  9. public stopSpinner() {
  10. this.spinner.hide();
  11. }
  12.  
  13. private postToken() {
  14. this.authService.postToken(this.token);
  15. }
  16. }
  17.  
  18. @Injectable()
  19. export class AuthService {
  20.  
  21. private BASE_URL: string = "http://localhost:8080";
  22.  
  23. constructor(private authenticateToken: AuthenticatetokenComponent, private _router: Router, private _dataservice: DataService) { }
  24.  
  25. postToken(token: string) : void {
  26. this.authenticateToken.showSpinner();
  27.  
  28. if(this.authenticateToken.token == '') {
  29. this.authenticateToken.stopSpinner();
  30. this.authenticateToken.openModal("Tokenveld is leeg! Voer aub een token in!");
  31. }
  32.  
  33. this.authenticateToken.httpClient.post('/authentication', {
  34. token: token
  35. }
  36. ).subscribe(
  37. (data: any) => {
  38. if (token === '') {
  39. this.authenticateToken.stopSpinner();
  40. console.log('Khiem hier error in duwen');
  41. throw new Error('This token is not valid');
  42. } else {
  43. this.authenticateToken.elementRef.nativeElement.ownerDocument.body.style.backgroundColor = 'white';
  44. this._dataservice.electionFromService = data;
  45. this._dataservice.tokenFromService = token;
  46. this.authenticateToken.stopSpinner();
  47. this._router.navigateByUrl('/voting-page');
  48. }
  49. }
  50. );
  51. }
  52. getRestCall() : void {
  53. this.authenticateToken.httpClient.get('http://localhost:8080/test')
  54. .subscribe(
  55. (data: any[]) => {
  56. this.authenticateToken.data = data;
  57. console.log(data);
  58. }
  59. );
  60. }
  61.  
  62. }
Add Comment
Please, Sign In to add comment