<commit_before>import {Injectable, Inject} from '@angular/core';
import {Http, Headers} from '@angular/http';

@Injectable()
export class AuthService {
    
    isLoggedin: boolean;
    AuthToken;
    
    constructor(public http: Http) {
        this.http = http;
        this.isLoggedin = false;
        this.AuthToken = null;
    }
    
    storeUserCredentials(token) {
        window.localStorage.setItem('globalmedia', token);
        this.useCredentials(token);
        
    }
    
    useCredentials(token) {
        this.isLoggedin = true;
        this.AuthToken = token;
    }
    
    loadUserCredentials() {
        var token = window.localStorage.getItem('globalmedia');
        this.useCredentials(token);
    }
    
    destroyUserCredentials() {
        this.isLoggedin = false;
        this.AuthToken = null;
        window.localStorage.clear();
    }
    
    authenticate(user) {
        var creds = "username=" + user.name + "&password=" + <PASSWORD>;
        
        var headers = new Headers();
        headers.append('Content-Type', 'application/x-www-form-urlencoded');
        
        return new Promise(resolve => {
            this.http.post('http://localhost/bgp/api/login.json', creds, {headers: headers}).subscribe(data => {
                if(data.json().response == 'success'){
                    this.storeUserCredentials(data.json().token);
                    resolve(true);
                }
                else
                    resolve(false);
            });
        });
    }
   
    
    checkLogin() {
        return new Promise(resolve => {
            var headers = new Headers();
            this.loadUserCredentials();
            headers.append('Authorization', 'Bearer: ' +this.AuthToken);
            this.http.get('http://localhost/bgp/api/checklogin.json', {headers: headers}).subscribe(data => {
                if(data.json().response == 'success'){
                    resolve(true);                    
                }else{
                    resolve(false);
                }
            });
        })
    }
    
    logout() {
        this.destroyUserCredentials();
    }
}<commit_msg>User verileri de localstorage'da tutuluyor artık<commit_after>import {Injectable, Inject} from '@angular/core';
import {Http, Headers} from '@angular/http';

@Injectable()
export class AuthService {
    
    isLoggedin: boolean;
    AuthToken;
    
    constructor(public http: Http) {
        this.http = http;
        this.isLoggedin = false;
        this.AuthToken = null;
    }
    
    storeUserCredentials(token) {
        window.localStorage.setItem('globalmedia', token);
        this.useCredentials(token);
        
    }
    
    storeUserInformation(id, name, email){
        window.localStorage.setItem('user_id',id);
        window.localStorage.setItem('user_name',name);
        window.localStorage.setItem('user_email',email);        
    }
    
    useCredentials(token) {
        this.isLoggedin = true;
        this.AuthToken = token;
    }
    
    loadUserCredentials() {
        var token = window.localStorage.getItem('globalmedia');
        this.useCredentials(token);
    }
    
    destroyUserCredentials() {
        this.isLoggedin = false;
        this.AuthToken = null;
        window.localStorage.clear();
    }
    
    authenticate(user) {
        var creds = "username=" + user.name + "&password=" + <PASSWORD>;
        
        var headers = new Headers();
        headers.append('Content-Type', 'application/x-www-form-urlencoded');
        
        return new Promise(resolve => {
            this.http.post('http://localhost/bgp/api/login.json', creds, {headers: headers}).subscribe(data => {
                if(data.json().response == 'success'){
                    this.storeUserCredentials(data.json().token);
                    this.storeUserInformation(data.json().user_id, data.json().name, user.name);
                    resolve(true);
                }
                else
                    resolve(false);
            });
        });
    }
   
    
    checkLogin() {
        return new Promise(resolve => {
            var headers = new Headers();
            this.loadUserCredentials();
            headers.append('Authorization', 'Bearer: ' +this.AuthToken);
            this.http.get('http://localhost/bgp/api/checklogin.json', {headers: headers}).subscribe(data => {
                if(data.json().response == 'success'){
                    resolve(true);                    
                }else{
                    resolve(false);
                }
            });
        })
    }
    
    logout() {
        this.destroyUserCredentials();
    }
}
{'fraction_non_alphanumeric': 0.12872774082814847, 'fraction_numerical': 0.0, 'mean_word_length': 1.7407407407407407, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '2987819', 'n_tokens_mistral': 1287, 'n_tokens_neox': 1281, 'n_words': 202}