Exemplo n.º 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="deviceId"></param>
        /// <returns></returns>
        public static AnonymousAccount CreateNew(long deviceId)
        {
            ArgumentAssertion.IsNotNull(deviceId, "deviceId");
            var accountKey = string.Concat(deviceId.ToString(), Guid.NewGuid().ToString("N"));

            var account = new AnonymousAccount();

            account.DeviceId = deviceId;
            var authToken = HashHelper.ComputeHash(string.Concat(accountKey, account.CreatedTime.ToString()), HashAlgorithmName.SHA1);

            account.Token = new AnonymousAccount.AccountToken()
            {
                AccessToken = authToken, ExpiresTime = DateTime.Now.AddYears(1)
            };
            var saved = account.Save();

            return(saved ? account : null);
        }
Exemplo n.º 2
0
        private static void ChangeAccessTokenCache(string accessToken, AnonymousAccount account)
        {
            var cache = CacheManager.GetCache(ModuleEnvironment.TokenCacheName);

            if (null == account)
            {
                cache.Remove(accessToken);
            }
            else
            {
                cache.Set(accessToken, account);
            }

            if (false == string.IsNullOrEmpty(ModuleEnvironment.ThirdLinkedCacheName))
            {
                var thirdLinkedCache = CacheManager.GetCache(ModuleEnvironment.ThirdLinkedCacheName);
                thirdLinkedCache.Remove(accessToken);
            }

            M2SA.AppGenome.Logging.LogManager.GetLogger().Info("=========>[Token] Change cache {0} => [{1}]", accessToken, null == account ? "null" : account.ToText());
        }