public static string SaveTmpLogo(string tmpLogoPath) { if (String.IsNullOrEmpty(tmpLogoPath)) { return(null); } try { byte[] data; if (tmpLogoPath.StartsWith(Base64Start)) { data = Convert.FromBase64String(tmpLogoPath.Substring(Base64Start.Length)); return(SaveLogo(Guid.NewGuid() + ".png", data)); } var fileName = Path.GetFileName(tmpLogoPath); data = UserPhotoManager.GetTempPhotoData(fileName); UserPhotoManager.RemoveTempPhoto(fileName); return(SaveLogo(fileName, data)); } catch (Exception ex) { LogManager.GetLogger("ASC").Error(ex); return(null); } }
public object SaveGreetingLogoSettings(string logoVP) { try { SecurityContext.DemandPermissions(SecutiryConstants.EditPortalSettings); _tenantInfoSettings = TenantInfoSettings.Load(); if (!String.IsNullOrEmpty(logoVP)) { var fileName = Path.GetFileName(logoVP); var data = UserPhotoManager.GetTempPhotoData(fileName); _tenantInfoSettings.SetCompanyLogo(fileName, data); try { UserPhotoManager.RemoveTempPhoto(fileName); } catch { } } _tenantInfoSettings.Save(); MessageService.Send(HttpContext.Current.Request, MessageAction.GreetingSettingsUpdated); return(new { Status = 1, Message = Resource.SuccessfullySaveGreetingSettingsMessage }); } catch (Exception e) { return(new { Status = 0, Message = e.Message.HtmlEncode() }); } }
public object SaveCoBrandingSettings(bool isRetina, List <int> logoTypeList, List <string> logoPathList) { try { if (logoTypeList == null || logoPathList == null || logoTypeList.Count != logoPathList.Count) { throw new Exception("Incorrect data"); } SecurityContext.DemandPermissions(SecutiryConstants.EditPortalSettings); var _tenantCoBrandingSettings = SettingsManager.Instance.LoadSettings <TenantCoBrandingSettings>(TenantProvider.CurrentTenantID); for (var i = 0; i < logoTypeList.Count; i++) { var currentLogoType = (CoBrandingLogoTypeEnum)logoTypeList[i]; if (!String.IsNullOrEmpty(logoPathList[i])) { var fileName = Path.GetFileName(logoPathList[i]); var data = UserPhotoManager.GetTempPhotoData(fileName); var fileExt = fileName.Split('.').Last(); _tenantCoBrandingSettings.SetLogo(currentLogoType, fileExt, data); try { UserPhotoManager.RemoveTempPhoto(fileName); } catch (Exception ex) { log4net.LogManager.GetLogger("ASC").Error(ex); } } } SettingsManager.Instance.SaveSettings(_tenantCoBrandingSettings, TenantProvider.CurrentTenantID); return(new { Status = 1, Message = CoBrandingResource.SuccessfullySaveCoBrandingSettingsMessage, LogoPath = JsonConvert.SerializeObject( new Dictionary <int, string>() { { (int)CoBrandingLogoTypeEnum.Light, _tenantCoBrandingSettings.GetAbsoluteLogoPath(CoBrandingLogoTypeEnum.Light, !isRetina) }, { (int)CoBrandingLogoTypeEnum.LightSmall, _tenantCoBrandingSettings.GetAbsoluteLogoPath(CoBrandingLogoTypeEnum.LightSmall, !isRetina) }, { (int)CoBrandingLogoTypeEnum.Dark, _tenantCoBrandingSettings.GetAbsoluteLogoPath(CoBrandingLogoTypeEnum.Dark, !isRetina) }, { (int)CoBrandingLogoTypeEnum.Favicon, _tenantCoBrandingSettings.GetAbsoluteLogoPath(CoBrandingLogoTypeEnum.Favicon, !isRetina) }, { (int)CoBrandingLogoTypeEnum.DocsEditor, _tenantCoBrandingSettings.GetAbsoluteLogoPath(CoBrandingLogoTypeEnum.DocsEditor, !isRetina) } }) }); } catch (Exception e) { return(new { Status = 0, Message = e.Message.HtmlEncode() }); } }
public void RemoveTempPhoto(string photoPath) { if (!String.IsNullOrEmpty(photoPath)) { var fileName = Path.GetFileName(photoPath); try { UserPhotoManager.RemoveTempPhoto(fileName); } catch { } ; } }
public void SetLogo(Dictionary <int, string> logo) { var xStart = @"data:image/png;base64,"; foreach (var currentLogo in logo) { var currentLogoType = (WhiteLabelLogoTypeEnum)(currentLogo.Key); var currentLogoPath = currentLogo.Value; if (!String.IsNullOrEmpty(currentLogoPath)) { var fileExt = "png"; byte[] data = null; if (!currentLogoPath.StartsWith(xStart)) { var fileName = Path.GetFileName(currentLogoPath); fileExt = fileName.Split('.').Last(); data = UserPhotoManager.GetTempPhotoData(fileName); try { UserPhotoManager.RemoveTempPhoto(fileName); } catch (Exception ex) { log4net.LogManager.GetLogger("ASC").Error(ex); } } else { var xB64 = currentLogoPath.Substring(xStart.Length); // Get the Base64 string data = System.Convert.FromBase64String(xB64); // Convert the Base64 string to binary data } if (data != null) { SetLogo(currentLogoType, fileExt, data); } } } }
public object SaveGreetingSettings(string logoVP, string header) { try { SecurityContext.DemandPermissions(SecutiryConstants.EditPortalSettings); _tenantInfoSettings = SettingsManager.Instance.LoadSettings <TenantInfoSettings>(TenantProvider.CurrentTenantID); if (!String.IsNullOrEmpty(logoVP)) { var fileName = Path.GetFileName(logoVP); var data = UserPhotoManager.GetTempPhotoData(fileName); _tenantInfoSettings.SetCompanyLogo(fileName, data); try { UserPhotoManager.RemoveTempPhoto(fileName); } catch { } } var currentTenant = CoreContext.TenantManager.GetCurrentTenant(); currentTenant.Name = header; CoreContext.TenantManager.SaveTenant(currentTenant); SettingsManager.Instance.SaveSettings(_tenantInfoSettings, TenantProvider.CurrentTenantID); AdminLog.PostAction("Settings: saved greeting settings with parameters logo={0},header={1}", logoVP, header); MessageService.Send(HttpContext.Current.Request, MessageAction.GreetingSettingsUpdated); return(new { Status = 1, Message = Resource.SuccessfullySaveGreetingSettingsMessage }); } catch (Exception e) { return(new { Status = 0, Message = e.Message.HtmlEncode() }); } }
public AjaxResponse SaveUser(UserInfoEx userInfoEx, string photoPath) { var resp = new AjaxResponse(); if (!SecurityContext.IsAuthenticated) { resp.rs1 = "0"; return(resp); } var isNew = userInfoEx.Info.ID.Equals(Guid.Empty); userInfoEx.Info.Email = (userInfoEx.Info.Email ?? "").Trim(); if (String.IsNullOrEmpty(userInfoEx.Info.FirstName.Trim())) { resp.rs1 = "0"; resp.rs2 = "<div>" + Resources.Resource.ErrorEmptyUserFirstName + "</div>"; return(resp); } else if (String.IsNullOrEmpty(userInfoEx.Info.LastName.Trim())) { resp.rs1 = "0"; resp.rs2 = "<div>" + Resources.Resource.ErrorEmptyUserLastName + "</div>"; return(resp); } else if (String.IsNullOrEmpty(userInfoEx.Info.Email.Trim()) || !userInfoEx.Info.Email.TestEmailRegex()) { resp.rs1 = "0"; resp.rs2 = "<div>" + Resources.Resource.ErrorNotCorrectEmail + "</div>"; return(resp); } if (isNew) { userInfoEx.Pwd = UserManagerWrapper.GeneratePassword(); } try { var self = SecurityContext.CurrentAccount.ID.Equals(userInfoEx.Info.ID); var newDepartment = CoreContext.GroupManager.GetGroupInfo(userInfoEx.DepartmentID); if (newDepartment != ASC.Core.Users.Constants.LostGroupInfo) { userInfoEx.Info.Department = newDepartment.Name; } UserInfo newUserInfo = null; if (isNew && SecurityContext.IsAuthenticated && SecurityContext.CheckPermissions(ASC.Core.Users.Constants.Action_AddRemoveUser)) { var disableEditGroups = false; if (!SecurityContext.CheckPermissions(ASC.Core.Users.Constants.Action_EditGroups)) { userInfoEx.Info.Title = ""; disableEditGroups = true; } newUserInfo = UserManagerWrapper.AddUser(userInfoEx.Info, userInfoEx.Pwd); if (disableEditGroups == false && userInfoEx.DepartmentID != Guid.Empty) { CoreContext.UserManager.AddUserIntoGroup(newUserInfo.ID, userInfoEx.DepartmentID); } resp.rs3 = "add_user"; resp.rs10 = CustomNamingPeople.Substitute <Resources.Resource>("UserMakerAddUser").HtmlEncode(); } else if (SecurityContext.CheckPermissions(ASC.Core.Users.Constants.Action_EditUser) || (self && SecurityContext.CheckPermissions(new UserSecurityProvider(SecurityContext.CurrentAccount.ID), ASC.Core.Users.Constants.Action_EditUser))) { newUserInfo = (UserInfo)CoreContext.UserManager.GetUsers(userInfoEx.Info.ID).Clone(); newUserInfo.FirstName = userInfoEx.Info.FirstName.Trim(); newUserInfo.LastName = userInfoEx.Info.LastName.Trim(); newUserInfo.Sex = userInfoEx.Info.Sex; newUserInfo.Title = userInfoEx.Info.Title.Trim(); newUserInfo.BirthDate = userInfoEx.Info.BirthDate; newUserInfo.WorkFromDate = userInfoEx.Info.WorkFromDate; newUserInfo.Notes = userInfoEx.Info.Notes.Trim(); newUserInfo.Department = userInfoEx.Info.Department; newUserInfo.Location = userInfoEx.Info.Location.Trim(); newUserInfo.Contacts.Clear(); userInfoEx.Info.Contacts.ForEach(c => newUserInfo.Contacts.Add(c)); if (SecurityContext.CheckPermissions(ASC.Core.Users.Constants.Action_EditGroups)) { var oldDep = GetDepartmentForUser(userInfoEx.Info.ID); if (oldDep != null && !oldDep.ID.Equals(userInfoEx.DepartmentID)) { CoreContext.UserManager.RemoveUserFromGroup(newUserInfo.ID, oldDep.ID); newUserInfo.Department = ""; } if (((oldDep != null && !oldDep.ID.Equals(userInfoEx.DepartmentID)) || oldDep == null) && userInfoEx.DepartmentID != Guid.Empty) { CoreContext.UserManager.AddUserIntoGroup(newUserInfo.ID, userInfoEx.DepartmentID); var dep = CoreContext.GroupManager.GetGroupInfo(userInfoEx.DepartmentID); newUserInfo.Department = dep.Name; } } UserManagerWrapper.SaveUserInfo(newUserInfo); resp.rs3 = "edit_user"; resp.rs10 = Resources.Resource.UserMakerEditUser; resp.rs5 = SecurityContext.CurrentAccount.ID.Equals(newUserInfo.ID) ? "1" : ""; if (self && !CoreContext.UserManager.IsUserInGroup(SecurityContext.CurrentAccount.ID, ASC.Core.Users.Constants.GroupAdmin.ID)) { StudioNotifyService.Instance.SendMsgToAdminAboutProfileUpdated(); } } else { resp.rs1 = "0"; return(resp); } if (!String.IsNullOrEmpty(photoPath)) { var fileName = Path.GetFileName(photoPath); var data = UserPhotoManager.GetTempPhotoData(fileName); UserPhotoManager.SaveOrUpdatePhoto(newUserInfo.ID, data); try { UserPhotoManager.RemoveTempPhoto(fileName); } catch { } ; } resp.rs1 = "1"; } catch (Exception e) { resp.rs1 = "0"; resp.rs2 = "<div>" + e.Message.HtmlEncode() + "</div>"; } return(resp); }