示例#1
0
        public object Post(UserCreatedDiscourseWebHook request)
        {
            var rawString = request.RequestStream.ToUtf8String();

            Log.Info("User registered hook fired. \r\n\r\n" + rawString);
            string apiKey = Helpers.GetApiKeyFromRequest(rawString);

            if (AppSettings.Get("DiscourseApiKey", "") != apiKey)
            {
                Log.Warn("Invalid api key used - {0}.".Fmt(apiKey));
            }
            var discourseUser = Helpers.GetUserFromRequest(rawString);

            Log.Info("User email: {0}".Fmt(discourseUser.Email));
            var existingCustomerSubscription = ServiceStackAccountClient.GetUserSubscription(discourseUser.Email);

            if (existingCustomerSubscription != null &&
                existingCustomerSubscription.Expiry != null &&
                existingCustomerSubscription.Expiry > DateTime.Now)
            {
                Log.Info("User {0} with email {1} did have a valid subscription. Approving.".Fmt(discourseUser.Id, discourseUser.Email));
                ThreadPool.QueueUserWorkItem(BackgroundApprove, discourseUser);
            }
            else
            {
                Log.Info("User {0} with email {1} did not have a valid subscription".Fmt(discourseUser.Id, discourseUser.Email));
            }
            return(null);
        }
        public void TestWebHookWithAccount()
        {
            var service = appHost.Container.Resolve <WebHookServices>();

            var req = new UserCreatedDiscourseWebHook {
                RequestStream = new MemoryStream(validEmailInput.ToUtf8Bytes())
            };

            service.Post(req);
            Thread.Sleep(3200);
            var discourseClient = appHost.Resolve <IDiscourseClient>() as MockDiscourseClient;

            Assert.That(discourseClient != null);
            Assert.That(discourseClient.ApproveCalledCount > 0);
        }