Пример #1
0
        public ServerUser VadidateUser(string user, UserEmbedDetails userEmbeddetails)
        {
            var        email       = user;
            var        adminToken  = new DashboardModel().GetToken();
            ServerUser userDetails = IsUserExist(email, adminToken.AccessToken);

            if (email != null && userDetails == null)
            {
                string password = "******";
                string userName = "******";
                if (email.Contains('@'))
                {
                    var values = email.Split('@');
                    userName = values[0];
                    password = values[0] + "BI&786";
                }


                AddNewUser(email, userName, password, adminToken.AccessToken);
                userDetails = IsUserExist(email, adminToken.AccessToken);
                var userToken = new DashboardModel().GetToken(email);

                AddCategoryPermission(userDetails.UserId, adminToken.AccessToken);
                var categoryId = AddCategory(userName, userToken.AccessToken);
                AddDashboardPermission(userDetails.UserId, categoryId, adminToken.AccessToken);
                AddDatasourcePermission(userDetails.UserId, adminToken.AccessToken);
                var datasourceResponse = new DashboardModel().AddDatasource(userToken, userDetails.FirstName + "_Datasource", userEmbeddetails, userDetails.UserId);
            }


            return(userDetails);
        }
Пример #2
0
        public DesignerApiResponse AddDatasource(Token token, string name, UserEmbedDetails embedDetails, int userId)
        {
            using (var client = new HttpClient())
            {
                client.BaseAddress = new Uri(_globalAppSettings.EmbedDetails.RootUrl);
                client.DefaultRequestHeaders.Accept.Clear();

                var content = new FormUrlEncodedContent(new[]
                {
                    new KeyValuePair <string, string>("Name", name),
                    new KeyValuePair <string, string>("Type", embedDetails.DatasourceMode),
                    new KeyValuePair <string, string>("Connection", embedDetails.Credentials),
                    new KeyValuePair <string, string>("UserId", userId.ToString())
                });

                client.DefaultRequestHeaders.Add("Authorization", "bearer" + " " + token.AccessToken);
                var    result        = client.PostAsync(_globalAppSettings.EmbedDetails.RootUrl + "/api/" + _globalAppSettings.EmbedDetails.SiteIdentifier + "/v4.0/data-source/connection", content).Result;
                string resultContent = result.Content.ReadAsStringAsync().Result;
                return(JsonConvert.DeserializeObject <DesignerApiResponse>(resultContent));
            }
        }