public HttpResponseMessage DeleteUSer(string username)
        {
            DnnUser dnnUser = new DnnUser(username);

            Dictionary <string, string> listParam = uow.SystemParamRepo.GetByGroupKey("AD");
            var       pass    = GlobalCommon.DecryptString(listParam[ADManager.AD_ADMIN_PASS] ?? "");
            ADManager manager = new ADManager(listParam[ADManager.AD_DOMAIN], listParam[ADManager.AD_ADMIN_USER], pass);

            if (manager.IsAuthenticated())
            {
                string message = manager.Delete(username);
                if (string.IsNullOrEmpty(message))
                {
                    bool result = dnnUser.DeleteUser(username);
                    if (result)
                    {
                        return(Request.CreateResponse(HttpStatusCode.OK, new { success = true }));
                    }
                    else
                    {
                        return(Request.CreateResponse(HttpStatusCode.BadRequest, new { message = "Error delete user DNN" }));
                    }
                }

                return(Request.CreateResponse(HttpStatusCode.BadRequest, new { message = message }));
            }

            return(Request.CreateResponse(HttpStatusCode.BadRequest, new { success = false }));
        }
Example #2
0
        [AllowAnonymous]   // will check security internally, so assume no requirements
        public Dictionary <string, object> CreateOrUpdate([FromUri] string contentType, [FromBody] Dictionary <string, object> newContentItem, [FromUri] int?id = null, [FromUri] string appPath = null)
        {
            Log.Add($"create or update type:{contentType}, id:{id}, path:{appPath}");
            // if app-path specified, use that app, otherwise use from context
            var appIdentity = AppFinder.GetAppIdFromPathOrContext(appPath, SxcInstance);

            // Check that this ID is actually of this content-type,
            // this throws an error if it's not the correct type
            var itm = id == null
                ? null
                : new EntityApi(appIdentity.AppId, Log).GetOrThrow(contentType, id.Value);

            var ok = itm == null
                ? new MultiPermissionsTypes(SxcInstance, appIdentity.AppId, contentType, Log)
                     .EnsureAll(Grants.Create.AsSet(), out var exp)
                : new MultiPermissionsItems(SxcInstance, appIdentity.AppId, itm, Log)
                     .EnsureAll(Grants.Update.AsSet(), out exp);

            if (!ok)
            {
                throw exp;
            }

            //2018-09-15 2dm moved/disabled
            //var context = GetContext(SxcInstance, Log);
            //PerformSecurityCheck(appIdentity, contentType, perm, appPath == null ? context.Dnn.Module : null, itm);

            // Convert to case-insensitive dictionary just to be safe!
            newContentItem = new Dictionary <string, object>(newContentItem, StringComparer.OrdinalIgnoreCase);

            // Now create the cleaned up import-dictionary so we can create a new entity
            var cleanedNewItem = new AppContentEntityBuilder(Log)
                                 .CreateEntityDictionary(contentType, newContentItem, appIdentity.AppId);

            var userName = new DnnUser().IdentityToken;

            // try to create
            var publish = Factory.Resolve <IEnvironmentFactory>().PagePublisher(Log);
            // 2018-09-22 new
            // todo: something looks wrong here, I think create/update would fail if it doesn't have a moduleid
            var currentApp = new App(new DnnTenant(PortalSettings), appIdentity.ZoneId, appIdentity.AppId,
                                     ConfigurationProvider.Build(false, publish.IsEnabled(ActiveModule.ModuleID),
                                                                 SxcInstance.Data.ConfigurationProvider), true, Log);

            // 2018-09-22 old
            //currentApp.InitData(false,
            //    publish.IsEnabled(ActiveModule.ModuleID),
            //    SxcInstance.Data.ConfigurationProvider);
            if (id == null)
            {
                currentApp.Data.Create(contentType, cleanedNewItem, userName);
                // Todo: try to return the newly created object
                return(null);
            }

            currentApp.Data.Update(id.Value, cleanedNewItem, userName);
            return(InitEavAndSerializer(appIdentity.AppId).Prepare(currentApp.Data.List.One(id.Value)));
        }
        public HttpResponseMessage DeleteRole(int portalId, string username, string rolename)
        {
            DnnUser dnnUser = new DnnUser(username);
            bool    result  = dnnUser.DeleteRole(portalId, username, rolename);

            if (result)
            {
                return(Request.CreateResponse(HttpStatusCode.OK, new { success = true }));
            }

            return(Request.CreateResponse(HttpStatusCode.BadRequest, new { success = false }));
        }
Example #4
0
        private void MergeAffiliate(Affiliate aff, DnnUser user)
        {
            if (user == null)
            {
                return;
            }

            aff.Username          = user.Username;
            aff.Address.FirstName = user.FirstName;
            aff.Address.LastName  = user.LastName;

            aff.Address.Company    = user.ProfileCompany;
            aff.Address.Line1      = user.ProfileStreet;
            aff.Address.City       = user.ProfileCity;
            aff.Address.PostalCode = user.ProfilePostalCode;
            aff.Address.Phone      = user.ProfileTelephone;
        }
Example #5
0
        public Dictionary <string, object> CreateOrUpdate([FromUri] string contentType, [FromBody] Dictionary <string, object> newContentItem, [FromUri] int?id = null, [FromUri] string appPath = null)
        {
            Log.Add($"create or update type:{contentType}, id:{id}, path:{appPath}");
            // if app-path specified, use that app, otherwise use from context
            var appId = GetAppIdFromPathOrContext_AndInitEavAndSerializer(appPath);

            // Check that this ID is actually of this content-type,
            // this throws an error if it's not the correct type
            var itm = id == null
                ? null
                : _entitiesController.GetEntityOrThrowError(contentType, id.Value);

            var perm = id == null
                ? Grants.Create
                : Grants.Update;

            PerformSecurityCheck(appId, contentType, perm, appPath == null ? Dnn.Module : null, App, itm);

            // Convert to case-insensitive dictionary just to be safe!
            newContentItem = new Dictionary <string, object>(newContentItem, StringComparer.OrdinalIgnoreCase);

            // Now create the cleaned up import-dictionary so we can create a new entity
            var cleanedNewItem = CreateEntityDictionary(contentType, newContentItem, appId);

            var userName = new DnnUser().IdentityToken;

            // try to create
            var currentApp = new App(new DnnTenant(PortalSettings), appId);
            //currentApp.InitData(false, new ValueCollectionProvider());
            var publish = Factory.Resolve <IEnvironmentFactory>().PagePublisher(Log);

            currentApp.InitData(false,
                                publish.IsEnabled(ActiveModule.ModuleID),
                                Data.ConfigurationProvider);
            if (id == null)
            {
                currentApp.Data.Create(contentType, cleanedNewItem, userName);
                // Todo: try to return the newly created object
                return(null);
            }
            else
            {
                currentApp.Data.Update(id.Value, cleanedNewItem, userName);
                return(_entitiesController.Serializer.Prepare(currentApp.Data.List.One(id.Value)));
            }
        }