Guest User

Untitled

a guest
Dec 19th, 2018
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.35 KB | None | 0 0
  1. const getLoginUrl = this.url1 + '/api/' + 'Users?' + 'UserName=' + post['UserName'] + '&' + 'Password=' + post['Password'];
  2. return this.http
  3. .get(getLoginUrl, {})
  4. .map(
  5. res => {
  6. if (res.status == 200) {
  7. localStorage.setItem('currentUser', JSON.stringify(res.json().data));
  8. localStorage.setItem('roleId', res.json().RoleId);
  9. }
  10. return res.json();
  11. },
  12. err => {
  13. return err;
  14. }
  15. )
  16. }
  17. getToken(post) {
  18. var data = "username=" + post['UserName'] + "&password=" + post['Password'] + "&grant_type=password";
  19. var reqHeader = new HttpHeaders({ 'Content-Type': 'application/x-www-form-urlencoded',"No-Auth":'True' });
  20. return this.httpClient.post(this.urlToken, data, { headers : reqHeader});
  21. }
  22.  
  23. this.authenticationservice.login(post).subscribe(
  24. res => {
  25. this.spin = true;
  26.  
  27. if (res.Succes == true) {
  28. this.authenticationservice.login1(post).subscribe(
  29. res => {
  30.  
  31. if (res.UID != null && res.UID != undefined) {
  32. localStorage.setItem('isLoggedIn', "true");
  33. localStorage.setItem('currentUser', this.f.UserName.value);
  34. localStorage.setItem('userId', res.UID);
  35. localStorage.setItem('isAdmin', res.IsAdministrateur);
  36. //getToken();
  37. this.authenticationservice.getToken(post).subscribe((data: any) => {
  38. //this.baseService.setToken(data.access_token);
  39. localStorage.setItem('token', data.access_token);
  40. // this.helpers.setToken(data.access_token);
  41. this.goto = true;
  42. if (this.goto) {
  43. this.router.navigate([this.returnUrl1]);
  44. }
  45. },
  46. (err: HttpHeaderResponse) => {
  47. console.log("error request");
  48. this.spin = false;
  49. });
  50. }
  51. else {
  52. //this.loginError = true
  53. //this.loginAlert = res.message;
  54. this.error1 = 'Username or password is incorrect';
  55. this.loading1 = false;
  56. this.spin = false;
  57. }
  58. },
  59. error1 => {
  60. this.error1 = 'Votre Email ou Mot de passe incorrecte';
  61. this.loading1 = false;
  62. this.spin = false;
  63.  
  64. }
  65. );
  66. }
  67. else {
  68. //this.loginError = true
  69. //this.loginAlert = res.message;
  70. this.error = 'Votre code est incorrecte';
  71. this.loading = false;
  72. this.spin = false;
  73.  
  74.  
  75. //return Observable.throw(new Error('Username or password incorrect'));
  76.  
  77. // this.router.navigate([this.returnUrl2]);
  78. }
  79.  
  80. },
  81. err => {
  82. return err;
  83. });
  84.  
  85. ////
  86. if (this.error) {
  87. $('#lgnfrm').append('<div class="alert alert-danger">' + this.error + '</div>');
  88. }
  89. if (this.error1) {
  90. $('#lgnfrm').append('<div class="alert alert-danger" >' + this.error1 + '</div>');
  91. }
  92. }
  93.  
  94. {
  95. "/api": {
  96. "target": "http://172.xx.xx.xx:8080/PortailXEFI.WebServices/",
  97. "secure": false,
  98. "pathRewrite": { "^/api": "" },
  99. "logLevel": "debug",
  100. "changeOrigini": true
  101. }
  102. }
Add Comment
Please, Sign In to add comment