public async Task <ActionResponse> SendPasswordResetMessageAsync(SendPasswordResetMessageInputModel model)
        {
            if (!string.IsNullOrEmpty(model.ApplicationId))
            {
                var app = await _clientStore.FindEnabledClientByIdAsync(model.ApplicationId);

                if (app == null)
                {
                    return(BadRequest("Invalid application id"));
                }
            }

            var user = await _userStore.GetUserByEmailAsync(model.Username); //todo: support non-email addresses

            if (user == null)
            {
                // if valid email or phone number, send a message inviting them to register
                if (model.Username.Contains("@"))
                {
                    var result = await _messageService.SendAccountNotFoundMessageAsync(model.Username);

                    if (!result.MessageSent)
                    {
                        return(ServerError(result.ErrorMessageForEndUser));
                    }
                }
                return(Ok("Check your email for password reset instructions."));
            }
            var nextUrl             = SendToSetPasswordFirst(!string.IsNullOrEmpty(model.NextUrl) ? model.NextUrl : _urlHelper.Action("Apps", "Home"));
            var oneTimeCodeResponse = await _oneTimeCodeService.GetOneTimeCodeAsync(model.Username, TimeSpan.FromMinutes(5), nextUrl);

            if (oneTimeCodeResponse.Result == GetOneTimeCodeResult.Success)
            {
                var result = await _messageService.SendPasswordResetMessageAsync(model.ApplicationId, model.Username, oneTimeCodeResponse.ShortCode, oneTimeCodeResponse.LongCode);

                if (result.MessageSent)
                {
                    return(Ok("Check your email for password reset instructions."));
                }
                else
                {
                    return(ServerError(result.ErrorMessageForEndUser));
                }
            }
            return(ServerError("Hmm. Something went wrong. Please try again."));
        }