예제 #1
0
        public async Task <ChangeEmailResponse> Handle(ChangeEmailRequest request, CancellationToken cancellationToken)
        {
            if (await authValidationService.EmailExists(request.NewEmail))
            {
                throw new DuplicateException("Email address already exists", ErrorCodes.EmailExists);
            }

            var emailChanged = await accountManager.ChangeEmail(request.NewEmail, request.Token);

            return(emailChanged ? new ChangeEmailResponse()
                : throw new ProfileUpdateException("Error occurred during changing email address"));
        }
예제 #2
0
        public async Task <ChangeEmailResponse> Handle(ChangeEmailRequest request, CancellationToken cancellationToken)
        {
            var(token, email, newEmail) = (cryptoService.Decrypt(request.Token),
                                           cryptoService.Decrypt(request.Email), cryptoService.Decrypt(request.NewEmail));

            if (await authValidationService.EmailExists(newEmail))
            {
                throw new DuplicateException("Account with this email already exists");
            }

            return(await accountManager.ChangeEmail(newEmail, email, token)
                ? new ChangeEmailResponse()
                : throw new ChangeEmailException("Error occured during changing email"));
        }
예제 #3
0
        public async Task <IActionResult> ConfirmChangeEmail(int id, [FromQuery] ChangeEmailParams changeEmailParams)
        {
            var user = await accountManager.GetUser(id);

            if (user.SecurityData != changeEmailParams.NewEmail)
            {
                return(BadRequest("Niepoprawny link zmiany adresu email"));
            }

            if (user.Id != changeEmailParams.UserId)
            {
                return(BadRequest("Niepoprawny link zmiany adresu email"));
            }

            if (await accountManager.ChangeEmail(user, changeEmailParams.NewEmail, changeEmailParams.Token))
            {
                return(Ok());
            }

            throw new AccountException("Wystąpił błąd podczas zmiany adresu email");
        }