Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import {Injectable} from '@angular/core';
- import {OauthService} from './oauth.service';
- import {Observable} from 'rxjs/Observable';
- import {isUndefined} from 'util';
- import {CookieService} from 'ngx-cookie-service';
- import {ApiService} from './api.service';
- import {BehaviorSubject} from 'rxjs/BehaviorSubject';
- @Injectable()
- export class AuthService {
- public userId: number;
- public user$: BehaviorSubject<UserData> = new BehaviorSubject(null);
- public logged$: BehaviorSubject<boolean> = new BehaviorSubject<boolean>(false);
- private _CONSUMER_KEY: string;
- public constructor(
- private _oauth: OauthService,
- private _cookie: CookieService,
- private _api: ApiService
- ) {}
- public logIn(userData: UserData): Observable<any> {
- return this._oauth.post('url',
- {username: userData.email, password: userData.password});
- }
- public saveUser(userData: UserData): void {
- this.logged$.next(true);
- this._cookie.set('stuurm', userData);
- this.user$.next(userData);
- }
- public logOut(): void {
- this.logged$.next(false);
- this.user$.next(null);
- }
- public registerUser(newUser: NewUser): Observable<any> {
- const URL: string = 'some/url';
- const requestString: string =
- `name=${newUser.name}&vorname=${newUser.vorname}&email=${newUser.email}&password=${newUser.password}&password_conf=${newUser['password_conf']}&consumer_key=${this._CONSUMER_KEY}`;
- return this._api.post(
- URL,
- encodeURI(requestString),
- {'Content-Type': 'application/x-www-form-urlencoded'});
- }
- }
Add Comment
Please, Sign In to add comment