Ejemplo n.º 1
0
        public async Task <IActionResult> ConfirmRegistrationEmail([FromBody] ConfirmRegistrationViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = await _userManager.FindByIdAsync(model.UserId);

                if (user == null)
                {
                    return(Ok());
                }

                var result = await _userManager.ConfirmEmailAsync(user, model.Code.Replace(" ", "+"));

                if (result.Succeeded)
                {
                    _logger.LogInformation("User signed into a new account.");
                    await _userManager.AddClaimAsync(user, new Claim(ClaimTypes.Role, "Member"));

                    _userContext.SetUserGuidCookies(user.UserGuid);
                    return(Ok(new { token = await _userContext.GenerateToken(user) }));
                }
            }

            return(BadRequest());
        }
        public IHttpActionResult ConfirmRegistration([FromBody] ConfirmRegistrationViewModel registrationModel)
        {
            if (!ModelState.IsValid)
            {
                return(ErrorResult(ModelState));
            }
            var model = _registrationService.ConfirmUser(registrationModel.ConfirmationCode, registrationModel.UserId);

            if (model.Confirmed)
            {
                return(SuccessResult(model));
            }
            return(ErrorResult(0, model.Status));
        }