Beispiel #1
0
        public async Task <IActionResult> UpdateAccount([FromBody] UserAccountDto userAccountDto)
        {
            async Task UpdateAccount()
            {
                var user = await _userManager.GetUserAsync(HttpContext.User);

                await _accountHelper.ValidateCurrentPasswordIsCorrect(user, userAccountDto.CurrentPassword);

                if (!string.IsNullOrEmpty(userAccountDto.NewPassword))
                {
                    await _accountHelper.ChangePassword(user, userAccountDto.CurrentPassword,
                                                        userAccountDto.NewPassword);
                }

                bool EmailHasChanged()
                {
                    return(!string.IsNullOrEmpty(userAccountDto.Email) && !string.Equals(user.Email, userAccountDto.Email, StringComparison.CurrentCultureIgnoreCase));
                }

                if (EmailHasChanged())
                {
                    await _accountHelper.ChangeEmail(user, userAccountDto.Email);
                }
            }

            return(await Execute(UpdateAccount));
        }