Esempio n. 1
0
        public async Task <IActionResult> RequestChangeEmailForTheCurrentUser([FromBody] RequestChangeEmailCommand request)
        {
            if (request != null)
            {
                var currentUser = await this.currentUserProvider.GetCurrentUserAsync();

                request.UserId = currentUser.Id;
                request.ConfigureCallbackOptions("confirm-change-email", true);
            }
            else
            {
                return(this.BadRequest());
            }

            return(this.Ok(await this.Mediator.Send(request)));
        }
Esempio n. 2
0
        public async Task <IActionResult> ChangeEmailRequest(AdminChangeEmailViewModel model)
        {
            try
            {
                var currentUser = await this.CurrentUserProvider.GetCurrentUserAsync();

                var request = new RequestChangeEmailCommand()
                {
                    UserId   = currentUser.Id,
                    NewEmail = model.NewEmail,
                };

                request.ConfigureCallbackOptions("admin/manage/change-email", false);
                var requestResult = await this.Mediator.Send(request);

                if (requestResult.Succeeded)
                {
                    this.ShowSuccessNotification("Email request has been sent successfully. Check your email for confirmation.");
                    return(this.View());
                }
                else
                {
                    this.ShowErrorNotification("Email request has not been sent successfully.");
                    return(this.View(model));
                }
            }
            catch (ValidationException ex)
            {
                this.ModelState.ApplyValidationException(ex, true);
            }
            catch (Exception)
            {
                this.ModelState.AddModelError(string.Empty, "Change email request operation has failed.");
            }

            return(this.View(model));
        }