Guest User

Untitled

a guest
Feb 22nd, 2018
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.51 KB | None | 0 0
  1. import {Injectable} from '@angular/core';
  2. import {OauthService} from './oauth.service';
  3. import {Observable} from 'rxjs/Observable';
  4. import {isUndefined} from 'util';
  5. import {CookieService} from 'ngx-cookie-service';
  6. import {ApiService} from './api.service';
  7. import {BehaviorSubject} from 'rxjs/BehaviorSubject';
  8.  
  9. @Injectable()
  10. export class AuthService {
  11. public userId: number;
  12. public user$: BehaviorSubject<UserData> = new BehaviorSubject(null);
  13. public logged$: BehaviorSubject<boolean> = new BehaviorSubject<boolean>(false);
  14. private _CONSUMER_KEY: string;
  15.  
  16. public constructor(
  17. private _oauth: OauthService,
  18. private _cookie: CookieService,
  19. private _api: ApiService
  20. ) {}
  21.  
  22. public logIn(userData: UserData): Observable<any> {
  23. return this._oauth.post('url',
  24. {username: userData.email, password: userData.password});
  25. }
  26.  
  27. public saveUser(userData: UserData): void {
  28. this.logged$.next(true);
  29. this._cookie.set('stuurm', userData);
  30. this.user$.next(userData);
  31. }
  32.  
  33. public logOut(): void {
  34. this.logged$.next(false);
  35. this.user$.next(null);
  36. }
  37.  
  38. public registerUser(newUser: NewUser): Observable<any> {
  39. const URL: string = 'some/url';
  40. const requestString: string =
  41. `name=${newUser.name}&vorname=${newUser.vorname}&email=${newUser.email}&password=${newUser.password}&password_conf=${newUser['password_conf']}&consumer_key=${this._CONSUMER_KEY}`;
  42. return this._api.post(
  43. URL,
  44. encodeURI(requestString),
  45. {'Content-Type': 'application/x-www-form-urlencoded'});
  46. }
  47. }
Add Comment
Please, Sign In to add comment