<commit_before>import { Injectable, Inject } from '@angular/core';
import { Http, Response, Headers } from '@angular/http';
import { Observable } from 'rxjs/Rx';
import { LocalStorageService, SessionStorageService } from 'ng2-webstorage';

@Injectable()
export class AuthServerProvider {
    constructor(
        private http: Http,
        private $localStorage: LocalStorageService,
        private $sessionStorage: SessionStorageService
    ){}

    getToken () {
        return this.$localStorage.retrieve('authenticationToken') || this.$sessionStorage.retrieve('authenticationToken');
    }

    login (credentials): Observable<any> {
<%_ if(authenticationType === 'uaa') { _%>
        let data = {
            username: credentials.username,
            password: <PASSWORD>,
            grant_type: "password"
        };
        let headers = new Headers ({
            'Content-Type': 'application/x-www-form-urlencoded',
            "Authorization" : "Basic d2ViX2FwcDo="
        });

        return this.http.post('<%= uaaBaseName.toLowerCase() %>/oauth/token', data, {
            headers: headers
            //TODO this needs to be handled
            /*transformRequest: function(obj) {
                var str = [];
                for (var p in obj) {
                    str.push(encodeURIComponent(p) + '=' + encodeURIComponent(obj[p]));
                }
                return str.join('&');
            }*/
        }).map((resp) => {
            let accessToken = resp.json().data["access_token"];
            if (accessToken) {
                this.storeAuthenticationToken(accessToken, credentials.rememberMe);
            }
        });
<% } else { %>
        var data = {
            username: credentials.username,
            password: <PASSWORD>,
            rememberMe: credentials.rememberMe
        };
        return this.http.post('api/authenticate', data).map(authenticateSuccess.bind(this));

        function authenticateSuccess (resp) {
            var bearerToken = resp.headers.get('Authorization');
            if (bearerToken && bearerToken.slice(0, 7) === 'Bearer ') {
                var jwt = bearerToken.slice(7, bearerToken.length);
                this.storeAuthenticationToken(jwt, credentials.rememberMe);
                return jwt;
            }
        }
<%_ } _%>
    }
<commit_msg>changes the token call for uaa auth<commit_after>import { Injectable, Inject } from '@angular/core';
import { Http, Response, Headers, URLSearchParams } from '@angular/http';
import { Observable } from 'rxjs/Rx';
import { LocalStorageService, SessionStorageService } from 'ng2-webstorage';

@Injectable()
export class AuthServerProvider {
    constructor(
        private http: Http,
        private $localStorage: LocalStorageService,
        private $sessionStorage: SessionStorageService
    ){}

    getToken () {
        return this.$localStorage.retrieve('authenticationToken') || this.$sessionStorage.retrieve('authenticationToken');
    }

    login (credentials): Observable<any> {
<%_ if(authenticationType === 'uaa') { _%>
        let data = new URLSearchParams();
        data.append('grant_type', 'password');
        data.append('username', credentials.username);
        data.append('password', <PASSWORD>);

        let headers = new Headers ({
            'Content-Type': 'application/x-www-form-urlencoded',
            "Authorization" : "Basic d2ViX2FwcDo="
        });

        return this.http.post('<%= uaaBaseName.toLowerCase() %>/oauth/token', data, {
            headers: headers
        }).map((resp) => {
            let accessToken = resp.json().data["access_token"];
            if (accessToken) {
                this.storeAuthenticationToken(accessToken, credentials.rememberMe);
            }
        });
<% } else { %>
        var data = {
            username: credentials.username,
            password: <PASSWORD>,
            rememberMe: credentials.rememberMe
        };
        return this.http.post('api/authenticate', data).map(authenticateSuccess.bind(this));

        function authenticateSuccess (resp) {
            var bearerToken = resp.headers.get('Authorization');
            if (bearerToken && bearerToken.slice(0, 7) === 'Bearer ') {
                var jwt = bearerToken.slice(7, bearerToken.length);
                this.storeAuthenticationToken(jwt, credentials.rememberMe);
                return jwt;
            }
        }
<%_ } _%>
    }

{'fraction_non_alphanumeric': 0.12863913337846988, 'fraction_numerical': 0.002708192281651997, 'mean_word_length': 2.302533532041729, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 19, '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': '379737', 'n_tokens_mistral': 1208, 'n_tokens_neox': 1172, 'n_words': 240}