Пример #1
0
        protected override async Task OnInitializedAsync()
        {
            try
            {
                ApplicationUserService = ScopedServices.GetRequiredService <IApplicationUserService>();

                var userId = NavigationManager.GetQueryValue("userId");
                var code   = NavigationManager.GetQueryValue("code");
                var email  = NavigationManager.GetQueryValue("email");

                if (userId == null || email == null || code == null)
                {
                    SetWrongParameters("Wrong code", "This code is not valid.");
                    SetInitialized();
                    return;
                }

                var user = await UserManager.FindByIdAsync(userId);

                if (user == null)
                {
                    SetWrongParameters("User not found", "Unable to load user.");
                    SetInitialized();
                    return;
                }

                code = Encoding.UTF8.GetString(WebEncoders.Base64UrlDecode(code));
                try
                {
                    await ApplicationUserService.ConfirmEmailChangeAsync(new UserConfirmEmailChangeModel()
                    {
                        UserId = userId, Email = email, Code = code
                    });

                    await IdentityApiClient.LogoutAsync();
                }
                catch (Exception ex)
                {
                    SetWrongParameters("Error changing email", ex.Message);
                    SetInitialized();
                    return;
                }

                Success = true;
                SetInitialized();
            }
            catch (Exception ex)
            {
                Logger.LogError(ex.Message);
                SetLoadFailed(ex.Message);
            }
        }