<commit_before>import {HttpClient} from '@angular/common/http';
import {Injectable} from '@angular/core';
import {CookieService} from 'ngx-cookie-service';
import {Observable, ReplaySubject} from 'rxjs/Rx';
import {SocketService} from './sockets';

@Injectable()
export class AuthService {

    private session: string;
    private userInfo: any;

    private authEvents: ReplaySubject<{User: any, Session: string}>;

    constructor(
        private _http: HttpClient,
        private _cookies: CookieService,
        private _sockets: SocketService,
    ) {
        this.authEvents = new ReplaySubject<{User: any, Session: string}>(1);
    }

    private nuke() {
        this._cookies.deleteAll();
        this.session = undefined;
        this.userInfo = undefined;
        this._sockets.leave();
    }

    getSession() {
        return this.session;
    }

    getUser() {
        return this.userInfo;
    }

    hasAccess(): boolean {
        return !!this.userInfo;
    }

    observe(): Observable<{User: any, Session: string}> {
        return this.authEvents;
    }

    identify() {
        this._http.get<{Data: any}>(`/api/auth/`)
        .map(res => res.Data)
        .subscribe(
            data => {
                this.session = data.Session.Key;
                this.userInfo = data.User;
                this._sockets.join(data.Session.Key);
                this.authEvents.next({User: data.User, Session: data.Session.Key});
            },
            err => console.error(err)
        );
    }

    logIn(creds): Observable<any> {
        if (!creds || !creds.Username || !creds.Password) {
            return Observable.throw('Need login creds');
        }
        return this._http.post<{Data: any}>('/api/login', creds)
            .map(res => res.Data)
            .do(data => {
                this.session = data.Session;
                this.userInfo = data.User;
                this._sockets.join(data.Session);
                this.authEvents.next(data);
            });
    }

    signUp(creds): Observable<any> {
        if (!creds || !creds.Username || !creds.Email || !creds.Password) {
            return Observable.throw('Need signup creds');
        }
        return this._http.post<string>('/api/signup', creds, {responseType: 'text' as 'text'})
        .flatMap(_ => this.logIn(creds));
    }

    expireSocket() {
        this.userInfo = null;
        this.session = null;
        this.authEvents.next(null);
    }

    logOut(): Observable<any> {<commit_msg>remove ts warning by killing generic<commit_after>import {HttpClient} from '@angular/common/http';
import {Injectable} from '@angular/core';
import {CookieService} from 'ngx-cookie-service';
import {Observable, ReplaySubject} from 'rxjs/Rx';
import {SocketService} from './sockets';

@Injectable()
export class AuthService {

    private session: string;
    private userInfo: any;

    private authEvents: ReplaySubject<{User: any, Session: string}>;

    constructor(
        private _http: HttpClient,
        private _cookies: CookieService,
        private _sockets: SocketService,
    ) {
        this.authEvents = new ReplaySubject<{User: any, Session: string}>(1);
    }

    private nuke() {
        this._cookies.deleteAll();
        this.session = undefined;
        this.userInfo = undefined;
        this._sockets.leave();
    }

    getSession() {
        return this.session;
    }

    getUser() {
        return this.userInfo;
    }

    hasAccess(): boolean {
        return !!this.userInfo;
    }

    observe(): Observable<{User: any, Session: string}> {
        return this.authEvents;
    }

    identify() {
        this._http.get<{Data: any}>(`/api/auth/`)
        .map(res => res.Data)
        .subscribe(
            data => {
                this.session = data.Session.Key;
                this.userInfo = data.User;
                this._sockets.join(data.Session.Key);
                this.authEvents.next({User: data.User, Session: data.Session.Key});
            },
            err => console.error(err)
        );
    }

    logIn(creds): Observable<any> {
        if (!creds || !creds.Username || !creds.Password) {
            return Observable.throw('Need login creds');
        }
        return this._http.post<{Data: any}>('/api/login', creds)
            .map(res => res.Data)
            .do(data => {
                this.session = data.Session;
                this.userInfo = data.User;
                this._sockets.join(data.Session);
                this.authEvents.next(data);
            });
    }

    signUp(creds): Observable<any> {
        if (!creds || !creds.Username || !creds.Email || !creds.Password) {
            return Observable.throw('Need signup creds');
        }
        return this._http.post('/api/signup', creds, {responseType: 'text' as 'text'})
        .flatMap(_ => this.logIn(creds));
    }

    expireSocket() {
        this.userInfo = null;
        this.session = null;
        this.authEvents.next(null);
    }

    logOut(): Observable<any> {
{'fraction_non_alphanumeric': 0.13981278629755028, 'fraction_numerical': 0.00039832702648874725, 'mean_word_length': 2.0547445255474455, 'pattern_counts': {'":': 0, '<': 20, '<?xml version=': 0, '>': 32, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '787138', 'n_tokens_mistral': 1513, 'n_tokens_neox': 1476, 'n_words': 299}