Example #1
0
        private static void InitGlobalAttributesCache()
        {
            DateTime today = RockDateTime.Now;
            GlobalAttributesCache globalAttributes = GlobalAttributesCache.Get();

            globalAttributes.SetValue("GradeTransitionDate", string.Format("{0}/{1}", today.Month, today.Day), false);
        }
        private void SetOrganization(Organization organization)
        {
            GlobalAttributesCache globalCache = GlobalAttributesCache.Read();

            globalCache.SetValue("StoreOrganizationKey", organization.Key, true);
            pnlAuthenicate.Visible        = false;
            pnlSelectOrganization.Visible = false;
            pnlComplete.Visible           = true;

            lCompleteMessage.Text = string.Format("<div class='alert alert-success margin-t-md'><strong>Success!</strong> We were able to configure the store for use by {0}.</div>", organization.Name);
        }
        public void WithoutLegacyFallbackInvalidTokenShouldNotAllowLogin()
        {
            var rockContext        = new RockContext();
            var personTokenService = new PersonTokenService(rockContext);
            var token = "TokenProhibited";

            GlobalAttributesCache globalAttributes = GlobalAttributesCache.Get();

            globalAttributes.SetValue("core.PersonTokenUseLegacyFallback", "false", false);

            var personFromToken = personTokenService.GetByImpersonationToken(token);

            Assert.That.IsNull(personFromToken);
        }
        public void WithoutLegacyFallbackValidTokenShouldAllowLogin()
        {
            var rockContext        = new RockContext();
            var personService      = new PersonService(rockContext);
            var personTokenService = new PersonTokenService(rockContext);
            var personWithLowAccountProtectionProfile = personService.Get(PersonGuid.PersonWithLowAccountProtectionProfileGuid.AsGuid());

            GlobalAttributesCache globalAttributes = GlobalAttributesCache.Get();

            globalAttributes.SetValue("core.PersonTokenUseLegacyFallback", "false", false);

            var token = personWithLowAccountProtectionProfile.GetImpersonationToken();

            Assert.That.IsNotNull(token);

            var personFromToken = personTokenService.GetByImpersonationToken(token);

            Assert.That.Equal(PersonGuid.PersonWithLowAccountProtectionProfileGuid.AsGuid(), personFromToken.PersonAlias.Person.Guid);
        }
Example #5
0
        /// <summary>
        /// Gets the access token.
        /// </summary>
        /// <param name="recreate">if set to <c>true</c> [recreate].</param>
        /// <param name="errorMessage">The error message.</param>
        /// <returns></returns>
        public string GetAccessToken(bool recreate, out string errorMessage)
        {
            errorMessage = string.Empty;

            string accessToken = GlobalAttributesCache.Value("SignNowAccessToken");

            if (!recreate && !string.IsNullOrWhiteSpace(accessToken))
            {
                try
                {
                    JObject tokenVerification = SignNowSDK.OAuth2.Verify(accessToken);
                    var     errors            = ParseErrors(tokenVerification);
                    if (!errors.Any())
                    {
                        return(accessToken);
                    }
                }
                catch (Exception ex)
                {
                    ExceptionLogService.LogException(ex, null);
                }
            }

            // Get new Access Token
            SignNowSDK.Config.init(GetAttributeValue("APIClientId"), GetAttributeValue("APIClientSecret"), GetAttributeValue("UseAPISandbox").AsBoolean());
            JObject OAuthRes = SignNowSDK.OAuth2.RequestToken(GetAttributeValue("Username"), GetAttributeValue("Password"));

            errorMessage = ParseErrors(OAuthRes).AsDelimited("; ");
            if (string.IsNullOrWhiteSpace(errorMessage))
            {
                accessToken = OAuthRes.Value <string>("access_token");
                GlobalAttributesCache globalCache = GlobalAttributesCache.Get();
                globalCache.SetValue("SignNowAccessToken", accessToken, true);
            }

            return(accessToken);
        }
Example #6
0
        private static void SetGradeTransitionDateGlobalAttribute(int month, int day)
        {
            GlobalAttributesCache globalAttributes = GlobalAttributesCache.Get();

            globalAttributes.SetValue("GradeTransitionDate", string.Format("{0}/{1}", month, day), false);
        }