From 756889d2023c584a847b48b498279c702b1adaf0 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Fri, 7 May 2021 15:46:55 +0300 Subject: User now gets logged out only when they change their username --- ExamTemplate/Web/Controllers/UserController.cs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'ExamTemplate/Web/Controllers/UserController.cs') diff --git a/ExamTemplate/Web/Controllers/UserController.cs b/ExamTemplate/Web/Controllers/UserController.cs index c855c39..4d245f7 100644 --- a/ExamTemplate/Web/Controllers/UserController.cs +++ b/ExamTemplate/Web/Controllers/UserController.cs @@ -112,19 +112,20 @@ namespace ExamTemplate.Web.Controllers if (!this._userService.IsSignedIn(HttpContext.User)) return RedirectToAction("Login"); + UserServiceModel loggedInUser = await this._userService.GetUserByClaimsAsync(HttpContext.User); + EditUserServiceModel editUserServiceModel = this._autoMapper.Map(editUserViewModel); bool result = await this._userService.EditUserAsync(HttpContext.User, editUserServiceModel); if (result) { - await this._userService.LogoutAsync(); + if (loggedInUser.Username != editUserViewModel.Username) + await this._userService.LogoutAsync(); + return RedirectToAction("Profile", new { username = editUserViewModel.Username }); } else - { - UserServiceModel userServiceModel = await this._userService.GetUserByClaimsAsync(HttpContext.User); - return RedirectToAction("Profile", new { username = userServiceModel.Username }); - } + return RedirectToAction("Profile", new { username = loggedInUser.Username }); } } } -- cgit v1.2.3