Esempio n. 1
0
        public async Task <bool> ConfirmToken(string confirmationUsername, string confirmationToken)
        {
            try
            {
                if (!Guid.TryParse(confirmationToken, out var guidToken))
                {
                    ConfirmAccountTokenError = "Invalid Token";
                    return(false);
                }

                var model = new ConfirmUserModel {
                    ConfirmationToken = guidToken
                };
                await apiGateway.Post(model, "users", "confirm", new string[] { confirmationUsername }).ConfigureAwait(false);

                return(true);
            }
            catch (Exception ex)
            {
                ConfirmAccountTokenError = ex.Message;
                return(false);
            }
        }
Esempio n. 2
0
        public async Task <UserModel> ConfirmUserAsync(int userId, ConfirmUserModel model)
        {
            var user = await _userRepository.GetByIdAsync(userId);

            if (user.Status != UserStatusEnum.WaitForConfirmation)
            {
                throw new InvalidOperationException("Invalid user status. Should be wait for confirmation");
            }

            user.ProjectId      = model.ProjectId;
            user.RouteIds       = model.RouteIds;
            user.EmailConfirmed = true;
            user.Enabled        = true;

            var role = await _roleRepository.GetByIdAsync(model.RoleId);

            CheckRoleData(user, role);

            var roleResult = await _userManager.AddToRoleAsync(user, role.NormalizedName);

            if (!roleResult.Succeeded)
            {
                ThrowIdentityError(roleResult.Errors);
            }

            await _userRepository.UpdateAsync(user);

            await _emailService.SendEmailAsync(
                user.Email,
                "Ваша учётная запись успешно подтверждёна",
                GetConfirmEmailBody());

            var result = await GetByIdFullAsync(userId);

            return(result);
        }
Esempio n. 3
0
        public async Task <ActionResult <UserModel> > GetAll(int id, [FromBody] ConfirmUserModel model)
        {
            var result = await _userService.ConfirmUserAsync(id, model);

            return(result);
        }
        public async Task <IActionResult> ConfirmToken([FromRoute] string twitchUsername, [FromBody] ConfirmUserModel model)
        {
            var result = await userService.Confirm(twitchUsername, model.ConfirmationToken).ConfigureAwait(false);

            if (result.State != ResultState.Success)
            {
                return(BadRequest(result.FailureReason));
            }

            return(Ok());
        }