Esempio n. 1
0
        public async Task <IActionResult> ConfirmAccount(AccountConfirmationModel model)
        {
            try
            {
                await this.accountConfirmationService.ConfirmEmail(model);

                return(Ok());
            }
            catch (FeatureServiceException ex)
            {
                return(BadRequest(ex.Message));
            }
        }
        public async Task ConfirmEmail(AccountConfirmationModel model)
        {
            var user        = this.userRepository.GetUserByEmail(model.Email);
            var isValidUser = user == null ? false : await this.userManager.CheckPasswordAsync(user, model.Password);

            if (!isValidUser)
            {
                throw new FeatureServiceException("Invalid email or password.");
            }

            var result = await userManager.ConfirmEmailAsync(user, model.Token);

            if (!result.Succeeded)
            {
                throw new FeatureServiceException("Cannot confirm this email.");
            }

            // update user
            user.FirstName = model.FirstName;
            user.LastName  = model.LastName;
            this.SaveChanges();
        }