public IHttpActionResult Submit([FromBody] UserMenuInfo menuInfo)
        {
            try
            {
                var request = new AuthenticatedRequest();
                if (!request.IsAdminLoggin ||
                    !request.AdminPermissionsImpl.HasSystemPermissions(ConfigManager.AppPermissions.SettingsConfigHomeMenu))
                {
                    return(Unauthorized());
                }

                if (menuInfo.Id == 0)
                {
                    DataProvider.UserMenuDao.Insert(menuInfo);

                    request.AddAdminLog("新增用户菜单", $"用户菜单:{menuInfo.Text}");
                }
                else if (menuInfo.Id > 0)
                {
                    DataProvider.UserMenuDao.Update(menuInfo);

                    request.AddAdminLog("修改用户菜单", $"用户菜单:{menuInfo.Text}");
                }

                return(Ok(new
                {
                    Value = UserMenuManager.GetAllUserMenuInfoList()
                }));
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex));
            }
        }
        public IHttpActionResult Submit([FromBody] AccessTokenInfo itemObj)
        {
            try
            {
                var request = new AuthenticatedRequest();
                if (!request.IsAdminLoggin ||
                    !request.AdminPermissionsImpl.HasSystemPermissions(ConfigManager.AppPermissions.SettingsAdminAccessTokens))
                {
                    return(Unauthorized());
                }

                if (itemObj.Id > 0)
                {
                    var tokenInfo = DataProvider.AccessTokenDao.GetAccessTokenInfo(itemObj.Id);

                    if (tokenInfo.Title != itemObj.Title && DataProvider.AccessTokenDao.IsTitleExists(itemObj.Title))
                    {
                        return(BadRequest("保存失败,已存在相同标题的API密钥!"));
                    }

                    tokenInfo.Title     = itemObj.Title;
                    tokenInfo.AdminName = itemObj.AdminName;
                    tokenInfo.Scopes    = itemObj.Scopes;

                    DataProvider.AccessTokenDao.Update(tokenInfo);

                    request.AddAdminLog("修改API密钥", $"Access Token:{tokenInfo.Title}");
                }
                else
                {
                    if (DataProvider.AccessTokenDao.IsTitleExists(itemObj.Title))
                    {
                        return(BadRequest("保存失败,已存在相同标题的API密钥!"));
                    }

                    var tokenInfo = new AccessTokenInfo
                    {
                        Title     = itemObj.Title,
                        AdminName = itemObj.AdminName,
                        Scopes    = itemObj.Scopes
                    };

                    DataProvider.AccessTokenDao.Insert(tokenInfo);

                    request.AddAdminLog("新增API密钥", $"Access Token:{tokenInfo.Title}");
                }

                return(Ok(new
                {
                    Value = DataProvider.AccessTokenDao.GetAccessTokenInfoList()
                }));
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex));
            }
        }
        public IHttpActionResult Submit()
        {
            try
            {
                var request = new AuthenticatedRequest();
                if (!request.IsAdminLoggin)
                {
                    return(Unauthorized());
                }

                var tableName         = request.GetPostString("tableName");
                var attributeName     = request.GetPostString("attributeName");
                var relatedIdentities = TranslateUtils.StringCollectionToIntList(request.GetPostString("relatedIdentities"));
                var isRapid           = request.GetPostBool("isRapid");
                var rapidValues       = TranslateUtils.StringCollectionToStringList(request.GetPostString("rapidValues"));
                var body = request.GetPostObject <TableStyleInfo>("styleInfo");

                var styleInfoDatabase =
                    TableStyleManager.GetTableStyleInfo(tableName, attributeName, relatedIdentities) ??
                    new TableStyleInfo();

                bool   isSuccess;
                string errorMessage;

                //数据库中没有此项及父项的表样式 or 数据库中没有此项的表样式,但是有父项的表样式
                if (styleInfoDatabase.Id == 0 && styleInfoDatabase.RelatedIdentity == 0 || styleInfoDatabase.RelatedIdentity != relatedIdentities[0])
                {
                    isSuccess = InsertTableStyleInfo(tableName, relatedIdentities, body, isRapid, rapidValues, out errorMessage);
                    request.AddAdminLog("添加表单显示样式", $"字段名:{body.AttributeName}");
                }
                //数据库中有此项的表样式
                else
                {
                    isSuccess = UpdateTableStyleInfo(styleInfoDatabase, body, isRapid, rapidValues, out errorMessage);
                    request.AddAdminLog("修改表单显示样式", $"字段名:{body.AttributeName}");
                }

                if (!isSuccess)
                {
                    return(BadRequest(errorMessage));
                }

                return(Ok(new{}));
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex));
            }
        }
示例#4
0
        public IHttpActionResult UnLock()
        {
            try
            {
                var request = new AuthenticatedRequest();
                if (!request.IsAdminLoggin ||
                    !request.AdminPermissionsImpl.HasSystemPermissions(ConfigManager.SettingsPermissions.Admin))
                {
                    return(Unauthorized());
                }

                var id = request.GetPostInt("id");

                var adminInfo = AdminManager.GetAdminInfoByUserId(id);

                DataProvider.AdministratorDao.UnLock(new List <string>
                {
                    adminInfo.UserName
                });

                request.AddAdminLog("解锁管理员", $"管理员:{adminInfo.UserName}");

                return(Ok(new
                {
                    Value = true
                }));
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex));
            }
        }
        public IHttpActionResult Delete()
        {
            try
            {
                var request = new AuthenticatedRequest();
                if (!request.IsAdminLoggin ||
                    !request.AdminPermissionsImpl.HasSystemPermissions(ConfigManager.AppPermissions.SettingsAdminRole))
                {
                    return(Unauthorized());
                }

                var id = request.GetPostInt("id");

                var roleInfo = DataProvider.RoleDao.GetRoleInfo(id);

                DataProvider.PermissionsInRolesDao.Delete(roleInfo.RoleName);
                DataProvider.SitePermissionsDao.Delete(roleInfo.RoleName);
                DataProvider.RoleDao.DeleteRole(roleInfo.Id);

                request.AddAdminLog("删除管理员角色", $"角色名称:{roleInfo.RoleName}");

                var roleInfoList = request.AdminPermissionsImpl.IsConsoleAdministrator
                    ? DataProvider.RoleDao.GetRoleInfoList()
                    : DataProvider.RoleDao.GetRoleInfoListByCreatorUserName(request.AdminName);

                return(Ok(new
                {
                    Value = roleInfoList
                }));
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex));
            }
        }
        public IHttpActionResult Reset()
        {
            try
            {
                var request = new AuthenticatedRequest();
                if (!request.IsAdminLoggin ||
                    !request.AdminPermissionsImpl.HasSystemPermissions(ConfigManager.AppPermissions.SettingsConfigHomeMenu))
                {
                    return(Unauthorized());
                }

                foreach (var userMenuInfo in UserMenuManager.GetAllUserMenuInfoList())
                {
                    DataProvider.UserMenuDao.Delete(userMenuInfo.Id);
                }

                request.AddAdminLog("重置用户菜单");

                return(Ok(new
                {
                    Value = UserMenuManager.GetAllUserMenuInfoList()
                }));
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex));
            }
        }
        public IHttpActionResult Submit()
        {
            try
            {
                var request = new AuthenticatedRequest();
                if (!request.IsAdminLoggin ||
                    !request.AdminPermissionsImpl.HasSystemPermissions(ConfigManager.PluginsPermissions.Add))
                {
                    return(Unauthorized());
                }

                var fileNames = request.GetPostObject <List <string> >("fileNames");

                foreach (var fileName in fileNames)
                {
                    var localFilePath = PathUtils.GetTemporaryFilesPath(fileName);

                    //var importObject = new ImportObject(siteId, request.AdminName);
                    //importObject.ImportContentsByZipFile(channelInfo, localFilePath, isOverride, isChecked, checkedLevel, request.AdminId, 0, SourceManager.Default);
                }

                request.AddAdminLog("安装离线插件", string.Empty);

                return(Ok(new
                {
                    Value = true
                }));
            }
            catch (Exception ex)
            {
                LogUtils.AddErrorLog(ex);
                return(InternalServerError(ex));
            }
        }
示例#8
0
        public IHttpActionResult Enable(string pluginId)
        {
            try
            {
                var request = new AuthenticatedRequest();
                if (!request.IsAdminLoggin ||
                    !request.AdminPermissionsImpl.HasSystemPermissions(ConfigManager.PluginsPermissions.Add))
                {
                    return(Unauthorized());
                }

                var pluginInfo = PluginManager.GetPluginInfo(pluginId);
                if (pluginInfo != null)
                {
                    pluginInfo.IsDisabled = !pluginInfo.IsDisabled;
                    DataProvider.PluginDao.UpdateIsDisabled(pluginId, pluginInfo.IsDisabled);
                    PluginManager.ClearCache();

                    request.AddAdminLog(!pluginInfo.IsDisabled ? "禁用插件" : "启用插件", $"插件:{pluginId}");
                }

                CacheUtils.ClearAll();
                CacheDbUtils.Clear();

                return(Ok());
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex));
            }
        }
        public IHttpActionResult Submit()
        {
            try
            {
                var request = new AuthenticatedRequest();
                if (!request.IsAdminLoggin ||
                    !request.AdminPermissionsImpl.HasSystemPermissions(ConfigManager.AppPermissions.SettingsConfigAdmin))
                {
                    return(Unauthorized());
                }

                ConfigManager.SystemConfigInfo.AdminTitle       = request.GetPostString("adminTitle");
                ConfigManager.SystemConfigInfo.AdminLogoUrl     = request.GetPostString("adminLogoUrl");
                ConfigManager.SystemConfigInfo.AdminWelcomeHtml = request.GetPostString("adminWelcomeHtml");

                DataProvider.ConfigDao.Update(ConfigManager.Instance);

                request.AddAdminLog("修改管理后台设置");

                return(Ok(new
                {
                    Value = ConfigManager.SystemConfigInfo
                }));
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex));
            }
        }
示例#10
0
        public IHttpActionResult SavePermissions(int adminId)
        {
            try
            {
                var request = new AuthenticatedRequest();
                if (!request.IsAdminLoggin ||
                    !request.AdminPermissionsImpl.HasSystemPermissions(ConfigManager.SettingsPermissions.Admin))
                {
                    return(Unauthorized());
                }

                if (!request.AdminPermissions.IsSuperAdmin())
                {
                    return(Unauthorized());
                }

                var adminLevel   = request.GetPostString("adminLevel");
                var checkedSites = request.GetPostObject <List <int> >("checkedSites");
                var checkedRoles = request.GetPostObject <List <string> >("checkedRoles");

                var adminInfo = AdminManager.GetAdminInfoByUserId(adminId);

                DataProvider.AdministratorsInRolesDao.RemoveUser(adminInfo.UserName);
                if (adminLevel == "SuperAdmin")
                {
                    DataProvider.AdministratorsInRolesDao.AddUserToRole(adminInfo.UserName, EPredefinedRoleUtils.GetValue(EPredefinedRole.ConsoleAdministrator));
                }
                else if (adminLevel == "SiteAdmin")
                {
                    DataProvider.AdministratorsInRolesDao.AddUserToRole(adminInfo.UserName, EPredefinedRoleUtils.GetValue(EPredefinedRole.SystemAdministrator));
                }
                else
                {
                    DataProvider.AdministratorsInRolesDao.AddUserToRole(adminInfo.UserName, EPredefinedRoleUtils.GetValue(EPredefinedRole.Administrator));
                    DataProvider.AdministratorsInRolesDao.AddUserToRoles(adminInfo.UserName, checkedRoles.ToArray());
                }

                DataProvider.AdministratorDao.UpdateSiteIdCollection(adminInfo,
                                                                     adminLevel == "SiteAdmin"
                        ? TranslateUtils.ObjectCollectionToString(checkedSites)
                        : string.Empty);

                PermissionsImpl.ClearAllCache();

                request.AddAdminLog("设置管理员权限", $"管理员:{adminInfo.UserName}");

                return(Ok(new
                {
                    Value = true,
                    Roles = AdminManager.GetRoles(adminInfo.UserName)
                }));
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex));
            }
        }
        public IHttpActionResult Submit()
        {
            try
            {
                var request = new AuthenticatedRequest();
                if (!request.IsAdminLoggin)
                {
                    return(Unauthorized());
                }

                var tableName         = request.GetPostString("tableName");
                var attributeName     = request.GetPostString("attributeName");
                var relatedIdentities = TranslateUtils.StringCollectionToIntList(request.GetPostString("relatedIdentities"));
                var value             = request.GetPostString("value");

                var styleInfo =
                    TableStyleManager.GetTableStyleInfo(tableName, attributeName, relatedIdentities);
                styleInfo.Additional.VeeValidate = value;

                //数据库中没有此项及父项的表样式 or 数据库中没有此项的表样式,但是有父项的表样式
                if (styleInfo.Id == 0 && styleInfo.RelatedIdentity == 0 || styleInfo.RelatedIdentity != relatedIdentities[0])
                {
                    DataProvider.TableStyleDao.Insert(styleInfo);
                    request.AddAdminLog("添加表单显示样式", $"字段名:{styleInfo.AttributeName}");
                }
                //数据库中有此项的表样式
                else
                {
                    DataProvider.TableStyleDao.Update(styleInfo, false);
                    request.AddAdminLog("修改表单显示样式", $"字段名:{styleInfo.AttributeName}");
                }

                return(Ok(new{}));
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex));
            }
        }
示例#12
0
        public IHttpActionResult Submit()
        {
            try
            {
                var request = new AuthenticatedRequest();
                if (!request.IsAdminLoggin ||
                    !request.AdminPermissionsImpl.HasSystemPermissions(ConfigManager.AppPermissions.SettingsAdminConfig))
                {
                    return(Unauthorized());
                }

                ConfigManager.SystemConfigInfo.AdminUserNameMinLength =
                    request.GetPostInt("adminUserNameMinLength");
                ConfigManager.SystemConfigInfo.AdminPasswordMinLength =
                    request.GetPostInt("adminPasswordMinLength");
                ConfigManager.SystemConfigInfo.AdminPasswordRestriction =
                    request.GetPostString("adminPasswordRestriction");

                ConfigManager.SystemConfigInfo.IsAdminLockLogin    = request.GetPostBool("isAdminLockLogin");
                ConfigManager.SystemConfigInfo.AdminLockLoginCount = request.GetPostInt("adminLockLoginCount");
                ConfigManager.SystemConfigInfo.AdminLockLoginType  = request.GetPostString("adminLockLoginType");
                ConfigManager.SystemConfigInfo.AdminLockLoginHours = request.GetPostInt("adminLockLoginHours");

                ConfigManager.SystemConfigInfo.IsViewContentOnlySelf = request.GetPostBool("isViewContentOnlySelf");

                ConfigManager.SystemConfigInfo.IsAdminEnforcePasswordChange   = request.GetPostBool("isAdminEnforcePasswordChange");
                ConfigManager.SystemConfigInfo.AdminEnforcePasswordChangeDays = request.GetPostInt("adminEnforcePasswordChangeDays");

                ConfigManager.SystemConfigInfo.IsAdminEnforceLogout      = request.GetPostBool("isAdminEnforceLogout");
                ConfigManager.SystemConfigInfo.AdminEnforceLogoutMinutes = request.GetPostInt("adminEnforceLogoutMinutes");

                DataProvider.ConfigDao.Update(ConfigManager.Instance);

                request.AddAdminLog("修改管理员设置");

                return(Ok(new
                {
                    Value = ConfigManager.SystemConfigInfo
                }));
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex));
            }
        }
示例#13
0
        public IHttpActionResult Submit()
        {
            try
            {
                var request = new AuthenticatedRequest();
                var userId  = request.GetQueryInt("userId");
                if (userId == 0)
                {
                    userId = request.AdminId;
                }
                if (!request.IsAdminLoggin)
                {
                    return(Unauthorized());
                }
                var adminInfo = AdminManager.GetAdminInfoByUserId(userId);
                if (adminInfo == null)
                {
                    return(NotFound());
                }
                if (request.AdminId != userId &&
                    !request.AdminPermissionsImpl.HasSystemPermissions(ConfigManager.SettingsPermissions.Admin))
                {
                    return(Unauthorized());
                }

                var password = request.GetPostString("password");

                if (!DataProvider.AdministratorDao.ChangePassword(adminInfo, password, out var errorMessage))
                {
                    return(BadRequest($"更改密码失败:{errorMessage}"));
                }

                request.AddAdminLog("重设管理员密码", $"管理员:{adminInfo.UserName}");

                return(Ok(new
                {
                    Value = true
                }));
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex));
            }
        }
        public IHttpActionResult Submit()
        {
            try
            {
                var request = new AuthenticatedRequest();
                if (!request.IsAdminLoggin ||
                    !request.AdminPermissionsImpl.HasSystemPermissions(ConfigManager.SettingsPermissions.Config))
                {
                    return(Unauthorized());
                }

                ConfigManager.SystemConfigInfo.IsHomeClosed               = request.GetPostBool("isHomeClosed");
                ConfigManager.SystemConfigInfo.HomeTitle                  = request.GetPostString("homeTitle");
                ConfigManager.SystemConfigInfo.IsHomeLogo                 = request.GetPostBool("isHomeLogo");
                ConfigManager.SystemConfigInfo.HomeLogoUrl                = request.GetPostString("homeLogoUrl");
                ConfigManager.SystemConfigInfo.HomeDefaultAvatarUrl       = request.GetPostString("homeDefaultAvatarUrl");
                ConfigManager.SystemConfigInfo.UserRegistrationAttributes = request.GetPostString("userRegistrationAttributes");
                ConfigManager.SystemConfigInfo.IsUserRegistrationGroup    = request.GetPostBool("isUserRegistrationGroup");
                ConfigManager.SystemConfigInfo.IsHomeAgreement            = request.GetPostBool("isHomeAgreement");
                ConfigManager.SystemConfigInfo.HomeAgreementHtml          = request.GetPostString("homeAgreementHtml");

                DataProvider.ConfigDao.Update(ConfigManager.Instance);

//                var config = $@"var $apiConfig = {{
//    isSeparatedApi: {ApiManager.IsSeparatedApi.ToString().ToLower()},
//    apiUrl: '{ApiManager.ApiUrl}',
//    innerApiUrl: '{ApiManager.InnerApiUrl}'
//}};
//";

                request.AddAdminLog("修改用户中心设置");

                return(Ok(new
                {
                    Value = ConfigManager.SystemConfigInfo
                }));
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex));
            }
        }
        public IHttpActionResult Submit()
        {
            try
            {
                var request = new AuthenticatedRequest();
                if (!request.IsAdminLoggin ||
                    !request.AdminPermissionsImpl.HasSystemPermissions(ConfigManager.SettingsPermissions.User))
                {
                    return(Unauthorized());
                }

                ConfigManager.SystemConfigInfo.IsUserRegistrationAllowed   = request.GetPostBool("isUserRegistrationAllowed");
                ConfigManager.SystemConfigInfo.IsUserRegistrationChecked   = request.GetPostBool("isUserRegistrationChecked");
                ConfigManager.SystemConfigInfo.IsUserUnRegistrationAllowed = request.GetPostBool("isUserUnRegistrationAllowed");
                ConfigManager.SystemConfigInfo.UserPasswordMinLength       = request.GetPostInt("userPasswordMinLength");
                ConfigManager.SystemConfigInfo.UserPasswordRestriction     = request.GetPostString("userPasswordRestriction");
                ConfigManager.SystemConfigInfo.UserRegistrationMinMinutes  = request.GetPostInt("userRegistrationMinMinutes");
                ConfigManager.SystemConfigInfo.IsUserLockLogin             = request.GetPostBool("isUserLockLogin");
                ConfigManager.SystemConfigInfo.UserLockLoginCount          = request.GetPostInt("userLockLoginCount");
                ConfigManager.SystemConfigInfo.UserLockLoginType           = request.GetPostString("userLockLoginType");
                ConfigManager.SystemConfigInfo.UserLockLoginHours          = request.GetPostInt("userLockLoginHours");

                DataProvider.ConfigDao.Update(ConfigManager.Instance);

                request.AddAdminLog("修改用户设置");

                return(Ok(new
                {
                    Value = ConfigManager.SystemConfigInfo
                }));
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex));
            }
        }
示例#16
0
        public IHttpActionResult Delete(string pluginId)
        {
            try
            {
                var request = new AuthenticatedRequest();
                if (!request.IsAdminLoggin ||
                    !request.AdminPermissionsImpl.HasSystemPermissions(ConfigManager.PluginsPermissions.Add))
                {
                    return(Unauthorized());
                }

                PluginManager.Delete(pluginId);
                request.AddAdminLog("删除插件", $"插件:{pluginId}");

                CacheUtils.ClearAll();
                CacheDbUtils.Clear();

                return(Ok());
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex));
            }
        }
示例#17
0
        public IHttpActionResult UpdateRole(int roleId)
        {
            try
            {
                var request = new AuthenticatedRequest();
                if (!request.IsAdminLoggin ||
                    !request.AdminPermissionsImpl.HasSystemPermissions(ConfigManager.SettingsPermissions.Admin))
                {
                    return(Unauthorized());
                }

                var roleName                       = request.GetPostString("roleName");
                var description                    = request.GetPostString("description");
                var generalPermissionList          = request.GetPostObject <List <string> >("generalPermissions");
                var sitePermissionsInRolesInfoList =
                    request.GetPostObject <List <SitePermissionsInfo> >("sitePermissions");

                var roleInfo = DataProvider.RoleDao.GetRoleInfo(roleId);
                if (roleInfo.RoleName != roleName)
                {
                    if (EPredefinedRoleUtils.IsPredefinedRole(roleName))
                    {
                        return(BadRequest($"角色添加失败,{roleName}为系统角色!"));
                    }
                    if (DataProvider.RoleDao.IsRoleExists(roleName))
                    {
                        return(BadRequest("角色名称已存在,请更换角色名称!"));
                    }
                }

                DataProvider.PermissionsInRolesDao.Delete(roleInfo.RoleName);
                DataProvider.SitePermissionsDao.Delete(roleInfo.RoleName);

                if (generalPermissionList != null && generalPermissionList.Count > 0)
                {
                    var permissionsInRolesInfo = new PermissionsInRolesInfo(0, roleName,
                                                                            TranslateUtils.ObjectCollectionToString(generalPermissionList));
                    DataProvider.PermissionsInRolesDao.Insert(permissionsInRolesInfo);
                }

                if (sitePermissionsInRolesInfoList != null && sitePermissionsInRolesInfoList.Count > 0)
                {
                    foreach (var sitePermissionsInfo in sitePermissionsInRolesInfoList)
                    {
                        sitePermissionsInfo.RoleName = roleName;
                        DataProvider.SitePermissionsDao.Insert(sitePermissionsInfo);
                    }
                }

                roleInfo.RoleName    = roleName;
                roleInfo.Description = description;

                DataProvider.RoleDao.UpdateRole(roleInfo);

                PermissionsImpl.ClearAllCache();

                request.AddAdminLog("修改管理员角色", $"角色名称:{roleName}");

                return(Ok(new
                {
                    Value = true
                }));
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex));
            }
        }
示例#18
0
        public IHttpActionResult Submit()
        {
            try
            {
                var request = new AuthenticatedRequest();
                var userId  = request.GetQueryInt("userId");
                if (!request.IsAdminLoggin)
                {
                    return(Unauthorized());
                }
                if (request.AdminId != userId &&
                    !request.AdminPermissionsImpl.HasSystemPermissions(ConfigManager.SettingsPermissions.Admin))
                {
                    return(Unauthorized());
                }

                AdministratorInfo adminInfo;
                if (userId > 0)
                {
                    adminInfo = AdminManager.GetAdminInfoByUserId(userId);
                    if (adminInfo == null)
                    {
                        return(NotFound());
                    }
                }
                else
                {
                    adminInfo = new AdministratorInfo();
                }

                var userName     = request.GetPostString("userName");
                var password     = request.GetPostString("password");
                var displayName  = request.GetPostString("displayName");
                var avatarUrl    = request.GetPostString("avatarUrl");
                var mobile       = request.GetPostString("mobile");
                var email        = request.GetPostString("email");
                var departmentId = request.GetPostInt("departmentId");
                var areaId       = request.GetPostInt("areaId");

                if (adminInfo.Id == 0)
                {
                    adminInfo.UserName        = userName;
                    adminInfo.Password        = password;
                    adminInfo.CreatorUserName = request.AdminName;
                    adminInfo.CreationDate    = DateTime.Now;
                }
                else
                {
                    if (adminInfo.Mobile != mobile && !string.IsNullOrEmpty(mobile) && DataProvider.AdministratorDao.IsMobileExists(mobile))
                    {
                        return(BadRequest("资料修改失败,手机号码已存在"));
                    }

                    if (adminInfo.Email != email && !string.IsNullOrEmpty(email) && DataProvider.AdministratorDao.IsEmailExists(email))
                    {
                        return(BadRequest("资料修改失败,邮箱地址已存在"));
                    }
                }

                adminInfo.DisplayName  = displayName;
                adminInfo.AvatarUrl    = avatarUrl;
                adminInfo.Mobile       = mobile;
                adminInfo.Email        = email;
                adminInfo.DepartmentId = departmentId;
                adminInfo.AreaId       = areaId;

                if (adminInfo.Id == 0)
                {
                    if (!DataProvider.AdministratorDao.Insert(adminInfo, out var errorMessage))
                    {
                        return(BadRequest($"管理员添加失败:{errorMessage}"));
                    }
                    request.AddAdminLog("添加管理员", $"管理员:{adminInfo.UserName}");
                }
                else
                {
                    DataProvider.AdministratorDao.Update(adminInfo);
                    request.AddAdminLog("修改管理员属性", $"管理员:{adminInfo.UserName}");
                }

                return(Ok(new
                {
                    Value = true
                }));
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex));
            }
        }
示例#19
0
        public IHttpActionResult Submit([FromBody] UserGroupInfo itemObj)
        {
            try
            {
                var request = new AuthenticatedRequest();
                if (!request.IsAdminLoggin ||
                    !request.AdminPermissionsImpl.HasSystemPermissions(ConfigManager.SettingsPermissions.User))
                {
                    return(Unauthorized());
                }

                if (itemObj.Id == -1)
                {
                    if (UserGroupManager.IsExists(itemObj.GroupName))
                    {
                        return(BadRequest("保存失败,已存在相同名称的用户组!"));
                    }

                    var groupInfo = new UserGroupInfo
                    {
                        GroupName = itemObj.GroupName,
                        AdminName = itemObj.AdminName
                    };

                    DataProvider.UserGroupDao.Insert(groupInfo);

                    request.AddAdminLog("新增用户组", $"用户组:{groupInfo.GroupName}");
                }
                else if (itemObj.Id == 0)
                {
                    ConfigManager.SystemConfigInfo.UserDefaultGroupAdminName = itemObj.AdminName;

                    DataProvider.ConfigDao.Update(ConfigManager.Instance);

                    UserGroupManager.ClearCache();

                    request.AddAdminLog("修改用户组", "用户组:默认用户组");
                }
                else if (itemObj.Id > 0)
                {
                    var groupInfo = UserGroupManager.GetUserGroupInfo(itemObj.Id);

                    if (groupInfo.GroupName != itemObj.GroupName && UserGroupManager.IsExists(itemObj.GroupName))
                    {
                        return(BadRequest("保存失败,已存在相同名称的用户组!"));
                    }

                    groupInfo.GroupName = itemObj.GroupName;
                    groupInfo.AdminName = itemObj.AdminName;

                    DataProvider.UserGroupDao.Update(groupInfo);

                    request.AddAdminLog("修改用户组", $"用户组:{groupInfo.GroupName}");
                }

                return(Ok(new
                {
                    Value = UserGroupManager.GetUserGroupInfoList()
                }));
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex));
            }
        }