Exemplo n.º 1
0
        public async Task <IActionResult> ConfirmEmail(ConfirmEmailInputModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View("Error", model));
            }

            var user = await FindUserAndSetTenantFilterAsync(model.UserId);

            if (user == null)
            {
                ModelState.AddModelError(nameof(model.UserId), "User wasn't found");
                return(View(model));
            }

            var identityResult = await _userManager.ConfirmEmailAsync(user, model.Code);

            if (!identityResult.Succeeded)
            {
                var error        = identityResult.Errors.FirstOrDefault();
                var errorMessage = error != null ? error.Code + ": " + error.Description : "Identity error";
                ModelState.AddModelError("", errorMessage);
                return(View("Error", model));
            }

            return(RedirectToAction("ConfirmEmailSuccess"));
        }
Exemplo n.º 2
0
        public async Task <IdentityResult> ConfirmEmail([FromBody] ConfirmEmailInputModel request)
        {
            var user = await _userManager.FindByEmailAsync(request.Email);

            user.EmailConfirmed = true;

            return(await _userManager.UpdateAsync(user));
        }
Exemplo n.º 3
0
        public async Task <ActionResult> ConfirmEmail(ConfirmEmailInputModel inputModel)
        {
            try
            {
                var confirmEmailIdentityResult = await this.userService.ConfirmEmail(
                    inputModel.EmailConfirmToken, this.GetUserId(this.User));

                if (confirmEmailIdentityResult.Succeeded)
                {
                    return(this.Ok());
                }

                return(this.BadRequest(confirmEmailIdentityResult.Errors));
            }
            catch (Exception ex)
            {
                this.loggerService.LogException(ex);
                return(this.BadRequest());
            }
        }