Exemplo n.º 1
0
        protected override async Task <bool> GetHtmlAsync(IOwinEnvironment context, IClient client, CancellationToken cancellationToken)
        {
            var queryString = QueryStringParser.Parse(context.Request.QueryString, _logger);
            var spToken     = queryString.GetString("sptoken");

            if (string.IsNullOrEmpty(spToken))
            {
                var viewModelBuilder = new VerifyEmailFormViewModelBuilder(client, _configuration);
                var verifyViewModel  = viewModelBuilder.Build();

                await RenderViewAsync(context, _configuration.Web.VerifyEmail.View, verifyViewModel, cancellationToken);

                return(true);
            }

            try
            {
                var account = await client.VerifyAccountEmailAsync(spToken, cancellationToken);

                var postVerifyEmailContext = new PostVerifyEmailContext(context, account);
                await _handlers.PostVerifyEmailHandler(postVerifyEmailContext, cancellationToken);

                return(await HttpResponse.Redirect(context, $"{_configuration.Web.VerifyEmail.NextUri}"));
            }
            catch (ResourceException)
            {
                var viewModelBuilder = new VerifyEmailFormViewModelBuilder(client, _configuration);
                var verifyViewModel  = viewModelBuilder.Build();
                verifyViewModel.InvalidSpToken = true;

                await RenderViewAsync(context, _configuration.Web.VerifyEmail.View, verifyViewModel, cancellationToken);

                return(true);
            }
        }
Exemplo n.º 2
0
        protected override async Task <bool> GetJsonAsync(IOwinEnvironment context, IClient client, CancellationToken cancellationToken)
        {
            var queryString = QueryStringParser.Parse(context.Request.QueryString, _logger);
            var spToken     = queryString.GetString("sptoken");

            if (string.IsNullOrEmpty(spToken))
            {
                return(await Error.Create(context, new BadRequest("sptoken parameter not provided."), cancellationToken));
            }

            var account = await client.VerifyAccountEmailAsync(spToken, cancellationToken);

            // Errors are caught in AbstractRouteMiddleware

            var postVerifyEmailContext = new PostVerifyEmailContext(context, account);
            await _handlers.PostVerifyEmailHandler(postVerifyEmailContext, cancellationToken);

            return(await JsonResponse.Ok(context));
        }