Esempio n. 1
0
        public ChangeEmailResponse ChangeEmail(string sessionId, string authenticationId, string emailId)
        {
            var response = new ChangeEmailResponse { IsSuccess = true };
            using (new ApplicationContextScope(new ApplicationContext()))
            {
                ApplicationContext.SetSessionId(sessionId);
                try
                {
                    IAccountProvider accountProvider = AccountProviderFactory.GetAccountProvider();
                    IAuthenticationProvider authenticationProvider =
                        AuthenticationProviderFactory.GetAuthenticationProvider();
                    IEmailProvider verificationProvider = EmailProviderFactory.GetEmailProvider();

                    Core.Model.Account account =
                        accountProvider.GetAccount(authenticationProvider.GetAccountId(authenticationId));
                    if (account != null)
                    {
                        if (accountProvider.ChangeEmail(account.AccountId, emailId))
                        {
                            account.Email = emailId;
                            account.IsEmailActivated = false;
                            verificationProvider.ResendEmailVerification(account);
                            response.IsSuccess = true;
                        }
                        else
                        {
                            response.ErrorMessage =
                                "EmailId could not be changed. Please retry with valid information.";
                            response.IsSuccess = false;
                        }
                    }
                    else
                    {
                        response.ErrorMessage = "Invalid Account or EmailId. Please retry with valid information.";
                        response.IsSuccess = false;
                    }
                }
                catch (Exception exception)
                {
                    response.ErrorMessage = "Something is not quite right here. Please try again later.";
                    response.IsSuccess = false;
                    Logger.LogException(exception, Source, "ResendMobileCode", Severity.Critical);
                }
            }
            return response;
        }
        public async void UpdateEmail()
        {
            if (string.IsNullOrWhiteSpace(Email))
            {
                SetError("You must provide an email address!");
                return;
            }

            IsUpdatingEmail = true;

            try
            {
                ChangeEmailResponse response = await Account.PostAuthenticatedAsync <ChangeEmailRequest, ChangeEmailResponse>(
                    Website.URL + "changeemailmodern",
                    new ChangeEmailRequest()
                {
                    NewEmail = Email
                });

                if (response.Error != null)
                {
                    SetError(response.Error);
                }

                else
                {
                    GoBack();
                }
            }

            catch
            {
                SetError(PowerPlannerResources.GetString("Settings_ChangeEmailPage_Errors_FailedUpdateOnline"));
            }

            finally
            {
                IsUpdatingEmail = false;
            }
        }