Advertisement
Guest User

Untitled

a guest
Feb 6th, 2017
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.74 KB | None | 0 0
  1. import { Injectable } from "@angular/core";
  2. import { AngularFire, AuthProviders, AuthMethods, FirebaseListObservable, FirebaseObjectObservable } from 'angularfire2';
  3. import { UserModel } from '../users/models/user.model';
  4.  
  5. @Injectable()
  6. export class AuthenticationService {
  7.  
  8. public displayName: string;
  9. public userKey: string;
  10. public user: UserModel;
  11.  
  12. constructor(public af: AngularFire) {
  13. this.af.auth.subscribe(
  14. (auth) => {
  15. if (auth != null) {
  16. this.user = this.af.database.object('users/' + auth.uid);
  17. this.userKey = auth.uid;
  18. }
  19. });
  20. }
  21.  
  22. logout() {
  23. return this.af.auth.logout();
  24. }
  25.  
  26. loginWithEmail(email, password) {
  27. return this.af.auth.login({
  28. email: email,
  29. password: password,
  30. },
  31. {
  32. provider: AuthProviders.Password,
  33. method: AuthMethods.Password,
  34. });
  35. }
  36. }
  37.  
  38. import { Injectable } from '@angular/core';
  39. import { Router } from '@angular/router';
  40. import { AngularFire, FirebaseListObservable, FirebaseObjectObservable } from 'angularfire2';
  41.  
  42. import { AuthenticationService } from '../authentication/authentication.service';
  43.  
  44. import { CustomerModel } from './models/customer.model';
  45.  
  46. @Injectable()
  47. export class CustomersService {
  48.  
  49. customersRef: string = '/customers/';
  50. customer: any;
  51. usersCustomerId: string;
  52.  
  53. constructor(
  54. private af: AngularFire,
  55. private authService: AuthenticationService,
  56. private router: Router) { }
  57.  
  58. getAllCustomers(): FirebaseListObservable<CustomerModel[]> {
  59.  
  60. this.usersCustomerId = this.authService.userKey;
  61. console.log(this.usersCustomerId);
  62.  
  63. return this.af.database.list(this.customersRef, {
  64. query: {
  65. orderByChild: 'uid',
  66. equalTo: this.usersCustomerId
  67. }
  68. });
  69. }
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement