const getLoginUrl = this.url1 + '/api/' + 'Users?' + 'UserName=' + post['UserName'] + '&' + 'Password=' + post['Password']; return this.http .get(getLoginUrl, {}) .map( res => { if (res.status == 200) { localStorage.setItem('currentUser', JSON.stringify(res.json().data)); localStorage.setItem('roleId', res.json().RoleId); } return res.json(); }, err => { return err; } ) } getToken(post) { var data = "username=" + post['UserName'] + "&password=" + post['Password'] + "&grant_type=password"; var reqHeader = new HttpHeaders({ 'Content-Type': 'application/x-www-form-urlencoded',"No-Auth":'True' }); return this.httpClient.post(this.urlToken, data, { headers : reqHeader}); } this.authenticationservice.login(post).subscribe( res => { this.spin = true; if (res.Succes == true) { this.authenticationservice.login1(post).subscribe( res => { if (res.UID != null && res.UID != undefined) { localStorage.setItem('isLoggedIn', "true"); localStorage.setItem('currentUser', this.f.UserName.value); localStorage.setItem('userId', res.UID); localStorage.setItem('isAdmin', res.IsAdministrateur); //getToken(); this.authenticationservice.getToken(post).subscribe((data: any) => { //this.baseService.setToken(data.access_token); localStorage.setItem('token', data.access_token); // this.helpers.setToken(data.access_token); this.goto = true; if (this.goto) { this.router.navigate([this.returnUrl1]); } }, (err: HttpHeaderResponse) => { console.log("error request"); this.spin = false; }); } else { //this.loginError = true //this.loginAlert = res.message; this.error1 = 'Username or password is incorrect'; this.loading1 = false; this.spin = false; } }, error1 => { this.error1 = 'Votre Email ou Mot de passe incorrecte'; this.loading1 = false; this.spin = false; } ); } else { //this.loginError = true //this.loginAlert = res.message; this.error = 'Votre code est incorrecte'; this.loading = false; this.spin = false; //return Observable.throw(new Error('Username or password incorrect')); // this.router.navigate([this.returnUrl2]); } }, err => { return err; }); //// if (this.error) { $('#lgnfrm').append('
' + this.error + '
'); } if (this.error1) { $('#lgnfrm').append('
' + this.error1 + '
'); } } { "/api": { "target": "http://172.xx.xx.xx:8080/PortailXEFI.WebServices/", "secure": false, "pathRewrite": { "^/api": "" }, "logLevel": "debug", "changeOrigini": true } }