Guest User

Untitled

a guest
Feb 23rd, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.81 KB | None | 0 0
  1. import {Component} from '@angular/core';
  2. import { Response } from '@angular/http';
  3. import {RecipeDataService} from '../shared/RecipeData.service';
  4. import {SignupUserService} from '../auth/signupUser.service';
  5.  
  6.  
  7. @Component({
  8. selector: 'app-header',
  9. templateUrl: './header.component.html',
  10. styleUrls: ['./header.component.css']
  11. })
  12. export class HeaderComponent {
  13. constructor(private RecipeDataService: RecipeDataService,
  14. private authService: SignupUserService) { }
  15. OnSave()
  16. {
  17. this.RecipeDataService.OnSaveRecipe()
  18. .subscribe(
  19. (response: Response) =>
  20. {
  21. console.log(response);
  22. }
  23. );
  24. }
  25. OnGet()
  26. {
  27. this.RecipeDataService.OnGettingRecipe();
  28. }
  29.  
  30.  
  31.  
  32.  
  33. }
  34.  
  35. И содержимое сервиса, на который ссылаюсь:
  36. import {Injectable} from '@angular/core';
  37. import * as firebase from 'firebase';
  38.  
  39.  
  40. @Injectable()
  41.  
  42. export class SignupUserService {
  43. token = '';
  44. signUpUser(email: string, password: string) {
  45. firebase.auth().createUserWithEmailAndPassword(email, password)
  46. .catch(
  47. error => console.log(error)
  48. );
  49. }
  50. signInUser(email: string, password: string)
  51. {
  52. firebase.auth().signInWithEmailAndPassword(email, password)
  53. .then(
  54. response => {
  55. firebase.auth().currentUser.getIdToken()
  56. .then(
  57. (token: string) => this.token = token
  58. );
  59. }
  60. )
  61. .catch (
  62. error => {console.log(error); }
  63. );
  64. }
  65. getToken() {
  66. firebase.auth().currentUser.getIdToken()
  67. .then(
  68. (token: string) => this.token = token
  69. );
  70. return this.token;
  71. }
  72. isAuthenticated(): boolean
  73. {
  74. return this.token != null;
  75. }
  76. }
  77.  
  78. constructor(private RecipeDataService: RecipeDataService,
  79. public authService: SignupUserService) { }
Add Comment
Please, Sign In to add comment