Exemple #1
0
        static void Check(IdentityAuthOptionsConfig optionsConfig)
        {
            if (string.IsNullOrWhiteSpace(optionsConfig.JsonString))
            {
                throw new UserFriendlyException($"{nameof(IdentityAuthOptionsConfig.JsonString)}不可以为空.");
            }

            IdentityAuthOptions authop;

            try
            {
                authop = JsonConvert.DeserializeObject <IdentityAuthOptions>(optionsConfig.JsonString);
            }
            catch (Exception ex)
            {
                throw new UserFriendlyException($"Json反序列化出错: {ex.Message}");
            }

            if (string.IsNullOrWhiteSpace(authop.ApiName))
            {
                throw new UserFriendlyException($"配置错误: [{nameof(IdentityAuthOptions.ApiName)}]不可以为空");
            }

            if (string.IsNullOrWhiteSpace(authop.Authority))
            {
                throw new UserFriendlyException($"配置错误: [{nameof(IdentityAuthOptions.Authority)}]不可以为空");
            }

            if (string.IsNullOrWhiteSpace(authop.AuthScheme))
            {
                throw new UserFriendlyException($"配置错误: [{nameof(IdentityAuthOptions.AuthScheme)}]不可以为空");
            }
        }
Exemple #2
0
 public void SaveOrUpdate(IdentityAuthOptionsConfig authOptions)
 {
     if (Exists(authOptions.Id.ToString()))
     {
         authOptions.ModifiedTime = DateTime.Now;
         Update(authOptions);
     }
     else
     {
         authOptions.CreateTime = DateTime.Now;
         Create(authOptions);
     }
 }
Exemple #3
0
        void Update(IdentityAuthOptionsConfig authOptions)
        {
            Check(authOptions);
            string sql = $"update {_tableName} set " +
                         $"jsonString = '{authOptions.JsonString}', " +
                         $"description = '{authOptions.Description}', " +
                         $"modifiedTime = '{authOptions.ModifiedTime}'" +
                         $"where id = '{authOptions.Id}'";

            _logger.Debug($"{nameof(Update)} sql:{sql}");
            using (IDbConnection cone = _connectionProvider.Create())
            {
                cone.Open();
                cone.Execute(sql);
            }
        }
Exemple #4
0
        void Create(IdentityAuthOptionsConfig authOptions)
        {
            Check(authOptions);
            authOptions.Id = Guid.NewGuid();
            string sql = $"insert into {_tableName} " +
                         $"(id, jsonString, description, createTime) " +
                         $"values (" +
                         $"'{authOptions.Id}', " +
                         $"'{authOptions.JsonString}', " +
                         $"'{authOptions.Description}', " +
                         $"'{authOptions.CreateTime}')";

            _logger.Debug($"{nameof(Create)} sql:{sql}");
            using (IDbConnection cone = _connectionProvider.Create())
            {
                cone.Open();
                cone.Execute(sql);
            }
        }