Beispiel #1
0
        public async Task <ActionResult> ChangePassword(ChangeFullNameModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            var result = await UserManager.ChangePasswordAsync(User.Identity.GetUserId(), model.OldPassword, model.NewPassword);

            if (result.Succeeded)
            {
                var user = await UserManager.FindByIdAsync(User.Identity.GetUserId());

                if (user != null)
                {
                    await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false);
                }
                return(RedirectToAction("Index", new { Message = ManageMessageId.ChangePasswordSuccess }));
            }
            AddErrors(result);
            return(View(model));
        }
        public async Task <IActionResult> UpdateFullName([FromBody] ChangeFullNameModel updateFullNameModel)
        {
            try
            {
                var userId = User.FindFirstValue(JwtRegisteredClaimNames.Sub);
                await _userService.UpdateFullName(userId, updateFullNameModel.FirstName, updateFullNameModel.LastName, updateFullNameModel.SurName);

                return(Ok());
            }
            catch (NotFoundException ex1)
            {
                return(NotFound(ex1.ToString()));
            }
            catch (Exception ex)
            {
                if (ex.Data?.Count > 0)
                {
                    return(BadRequest(ex.Data));
                }
                return(BadRequest());
            }
        }