예제 #1
0
        /// <summary>
        /// Decode encrypted user data
        /// </summary>
        /// <param name="email"></param>
        /// <param name="placeProviderId"></param>
        /// <returns></returns>
        public virtual async Task <User> GetUser(string email, string placeProviderId)
        {
            logger.LogInformation($"User loaded from database: {email}");
            var encoded = await redisCacheClient.Db0.HashGetAsync <string>($"{configuration["db-prefix"]}{REDIS_KEY_USERS_OBJECTS}", email);

            if (string.IsNullOrEmpty(encoded))
            {
                return(null);
            }
            using var aes = new Aes(configuration["key"], configuration["iv"]);
            var  decoded = aes.DecryptFromBase64String(encoded);
            User ret     = Newtonsoft.Json.JsonConvert.DeserializeObject <User>(decoded);

            // enhance user object for place provider groups
            if (!string.IsNullOrEmpty(placeProviderId))
            {
                var groups = await placeProviderRepository.GetUserGroups(email, placeProviderId);

                if (ret.Roles == null)
                {
                    ret.Roles = new List <string>();
                }
                foreach (var group in groups)
                {
                    if (!ret.Roles.Contains(group))
                    {
                        ret.Roles.Add(group);
                    }
                }
            }
            return(ret);
        }
예제 #2
0
        /// <summary>
        /// Gets user
        /// </summary>
        /// <param name="email"></param>
        /// <param name="placeProviderId"></param>
        /// <returns></returns>
        public override async Task <User> GetUser(string email, string placeProviderId)
        {
            if (!data.ContainsKey(email))
            {
                return(null);
            }
            var ret = data[email];

            if (!string.IsNullOrEmpty(placeProviderId))
            {
                var groups = await placeProviderRepository.GetUserGroups(email, placeProviderId);

                if (ret.Roles == null)
                {
                    ret.Roles = new List <string>();
                }

                foreach (var group in groups)
                {
                    if (!ret.Roles.Contains(group))
                    {
                        ret.Roles.Add(group);
                    }
                }
            }
            return(ret);
        }