diff --git a/src/LanBackup.WebApp/ClientApp/app/components/profile/profile.component.ts b/src/LanBackup.WebApp/ClientApp/app/components/profile/profile.component.ts index 00a149a..7b0108c 100644 --- a/src/LanBackup.WebApp/ClientApp/app/components/profile/profile.component.ts +++ b/src/LanBackup.WebApp/ClientApp/app/components/profile/profile.component.ts @@ -61,7 +61,11 @@ export class ProfileComponent implements OnInit { } else { //notify something not OK - this.showToast({ title: "Password change error", body: data.errors, type: ToastType.error }); + if (!data.isLoggedIn) { + localStorage.removeItem("user"); + this._router.navigate(['/']);//to default or last url + } + this.showToast({ title: "Password change error", body: data.errors.map(err => err.description), type: ToastType.error }); } }, err => { this.log.error(err); diff --git a/src/LanBackup.WebApp/ClientApp/app/services/authentication.service.ts b/src/LanBackup.WebApp/ClientApp/app/services/authentication.service.ts index 3a6b511..6e19b84 100644 --- a/src/LanBackup.WebApp/ClientApp/app/services/authentication.service.ts +++ b/src/LanBackup.WebApp/ClientApp/app/services/authentication.service.ts @@ -14,6 +14,7 @@ export class User { email: string; password: string; newpassword: string; + isLoggedIn: boolean; isAdmin: boolean; succeeded: boolean; isLockedOut: boolean; diff --git a/src/LanBackup.WebApp/ClientApp/boot-client.ts b/src/LanBackup.WebApp/ClientApp/boot-client.ts index b34b923..5481660 100644 --- a/src/LanBackup.WebApp/ClientApp/boot-client.ts +++ b/src/LanBackup.WebApp/ClientApp/boot-client.ts @@ -5,7 +5,6 @@ import { AppModule } from './app/app.module'; import * as $ from 'jquery'; import 'bootstrap'; -//import { AppInsightsModule, AppInsightsService } from 'ng2-appinsights'; // Enable either Hot Module Reloading or production mode if (module['hot']) { @@ -23,8 +22,3 @@ if (document.readyState === 'complete') { } else { document.addEventListener('DOMContentLoaded', bootApplication); } - -//var appIns: AppInsightsService = new AppInsightsService(''); -//appIns.Init({ -// instrumentationKey: '9f667285-ff2c-4626-a8da-1db518593323' //TODO - MOVE INTO A CONFIG FILE THAT SHOULD NOT BE COMMITED -//}); \ No newline at end of file diff --git a/src/LanBackup.WebApp/Controllers/API/UsersController.cs b/src/LanBackup.WebApp/Controllers/API/UsersController.cs index c9807b7..e15dcfc 100644 --- a/src/LanBackup.WebApp/Controllers/API/UsersController.cs +++ b/src/LanBackup.WebApp/Controllers/API/UsersController.cs @@ -9,7 +9,6 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using LanBackup.WebApp.Models.Telemetry; -using System.Net; namespace LanBackup.WebApp.Controllers { @@ -146,6 +145,7 @@ namespace LanBackup.WebApp.Controllers if (user != null) { dtouser.Succeeded = false; + dtouser.IsLoggedIn = true; var result = await _userManager.ChangePasswordAsync(user, dtouser.Password, dtouser.NewPassword); if (result.Succeeded) { @@ -162,7 +162,14 @@ namespace LanBackup.WebApp.Controllers return BadRequest(msg); } } - return StatusCode((int)HttpStatusCode.Unauthorized, "User not logged in");// Unauthorized(); + else + { + this.telemetry.TrackEvent("ChangePasswordNotLoggedIn"); + dtouser.Succeeded = false; + dtouser.IsLoggedIn = false; + dtouser.Errors = new IdentityError[] { new IdentityError() { Description = "User not logged in" } }; + return Ok(dtouser); + } } catch (Exception ex) { diff --git a/src/LanBackup.WebApp/Models/DTO/User.cs b/src/LanBackup.WebApp/Models/DTO/User.cs index bae1d61..4eb42ac 100644 --- a/src/LanBackup.WebApp/Models/DTO/User.cs +++ b/src/LanBackup.WebApp/Models/DTO/User.cs @@ -10,6 +10,7 @@ namespace LanBackup.WebApp.Models public string Email { get; set; } public string Password { get; set; } public string NewPassword { get; set; } + public bool IsLoggedIn { get; set; } public bool IsAdmin { get; set; } public bool Succeeded { get; set; } public bool IsLockedOut { get; set; }