Пример #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);
            }
        }
Пример #2
0
        protected override async Task <bool> PostHtmlAsync(IOwinEnvironment context, IClient client, ContentType bodyContentType, CancellationToken cancellationToken)
        {
            var htmlErrorHandler = new Func <string, CancellationToken, Task <bool> >(async(error, ct) =>
            {
                var viewModelBuilder     = new VerifyEmailFormViewModelBuilder(client, _configuration);
                var verifyEmailViewModel = viewModelBuilder.Build();
                verifyEmailViewModel.Errors.Add(error);

                await RenderViewAsync(context, _configuration.Web.VerifyEmail.View, verifyEmailViewModel, cancellationToken);
                return(true);
            });

            var body = await context.Request.GetBodyAsStringAsync(cancellationToken);

            var model = PostBodyParser.ToModel <VerifyEmailPostModel>(body, bodyContentType, _logger);

            var formData         = FormContentParser.Parse(body, _logger);
            var stateToken       = formData.GetString(StringConstants.StateTokenName);
            var parsedStateToken = new StateTokenParser(client, _configuration.Client.ApiKey, stateToken, _logger);

            if (!parsedStateToken.Valid)
            {
                await htmlErrorHandler("An error occurred. Please try again.", cancellationToken);

                return(true);
            }

            var htmlSuccessHandler = new Func <CancellationToken, Task <bool> >(
                ct => HttpResponse.Redirect(context, $"{_configuration.Web.Login.Uri}?status=unverified"));

            return(await ResendVerification(
                       model.Email,
                       client,
                       context,
                       htmlErrorHandler,
                       htmlSuccessHandler,
                       cancellationToken));
        }