示例#1
0
        protected override async Task <bool> PostHtmlAsync(IOwinEnvironment context, IClient client, ContentType bodyContentType, CancellationToken cancellationToken)
        {
            var application = await client.GetApplicationAsync(_configuration.Application.Href, cancellationToken);

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

                var model    = PostBodyParser.ToModel <ForgotPasswordPostModel>(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)
                {
                    var queryString      = QueryStringParser.Parse(context.Request.QueryString, _logger);
                    var viewModelBuilder = new ForgotPasswordFormViewModelBuilder(client, _configuration, queryString);
                    var viewModel        = viewModelBuilder.Build();
                    viewModel.Errors.Add("An error occurred. Please try again.");

                    await RenderViewAsync(context, _configuration.Web.ForgotPassword.View, viewModel, cancellationToken);

                    return(true);
                }

                await application.SendPasswordResetEmailAsync(model.Email, cancellationToken);
            }
            catch (Exception ex)
            {
                _logger.Error(ex, source: "ForgotRoute.PostHtml");
            }

            return(await HttpResponse.Redirect(context, _configuration.Web.ForgotPassword.NextUri));
        }
示例#2
0
        protected override async Task <bool> GetHtmlAsync(IOwinEnvironment context, IClient client, CancellationToken cancellationToken)
        {
            var queryString = QueryStringParser.Parse(context.Request.QueryString, _logger);

            var viewModelBuilder = new ForgotPasswordFormViewModelBuilder(client, _configuration, queryString);
            var forgotViewModel  = viewModelBuilder.Build();

            await RenderViewAsync(context, _configuration.Web.ForgotPassword.View, forgotViewModel, cancellationToken);

            return(true);
        }