public int create(templateCarrier carrier, string username, string password) { Authenticate(username, password); if (carrier.Id != 0) { throw new Exception("ID may not be specified when creating"); } if (carrier == null) { throw new Exception("No carrier specified"); } // Get the user umbraco.BusinessLogic.User user = GetUser(username, password); // Create template cms.businesslogic.template.Template template = cms.businesslogic.template.Template.MakeNew(carrier.Name, user); template.MasterTemplate = carrier.MastertemplateId; template.Alias = carrier.Alias; template.Text = carrier.Name; template.Design = carrier.Design; template.Save(); clearCachedTemplate(template); return(template.Id); }
private Permissions GetInternal(string userId = null) { umbraco.BusinessLogic.User umbracoUser = null; if (string.IsNullOrEmpty(userId)) { umbracoUser = umbraco.BusinessLogic.User.GetCurrent(); } else { int?umbracoUserId = userId.TryParse <int>(); if (umbracoUserId != null) { umbracoUser = umbraco.BusinessLogic.User.GetUser(umbracoUserId.Value); } } Permissions permissions = null; if (umbracoUser != null) { userId = umbracoUser.Id.ToString(CultureInfo.InvariantCulture); permissions = !umbracoUser.IsRoot() ? _repository.Get(userId) : new Permissions(userId, true); } return(permissions); }
private void handlePublishing(Document doc, documentCarrier carrier, umbraco.BusinessLogic.User user) { switch (carrier.PublishAction) { case documentCarrier.EPublishAction.Publish: doc.Publish(user); umbraco.library.PublishSingleNode(doc.Id); break; case documentCarrier.EPublishAction.Unpublish: doc.Publish(user); umbraco.library.UnPublishSingleNode(doc.Id); break; case documentCarrier.EPublishAction.Ignore: if (doc.Published) { doc.Publish(user); umbraco.library.PublishSingleNode(doc.Id); } else { doc.Publish(user); umbraco.library.UnPublishSingleNode(doc.Id); } break; } }
private static void GenerateTemplate(string name, Dictionary<string, int> properties) { var user = new umbraco.BusinessLogic.User("admin"); var parentTemplate = DocumentType.GetByAlias("GridModule"); DocumentType template = DocumentType.MakeNew(user, name); int tabId = template.AddVirtualTab("Content"); foreach (string key in properties.Keys) { var property = template.AddPropertyType(new DataTypeDefinition(properties[key]), (Char.ToLower(key[0]) + key.Substring(1)).Replace(" ", ""), key); template.SetTabOnPropertyType(property, tabId); } template.Save(); #region Set Master Document type SqlConnection connection = new SqlConnection(ConfigurationManager.AppSettings["umbracoDbDSN"]); connection.Open(); SqlCommand command = new SqlCommand(string.Format("UPDATE cmsContentType SET masterContentType = {0} WHERE nodeId= {1}", parentTemplate.Id, template.Id), connection); command.ExecuteNonQuery(); connection.Close(); #endregion }
private static DataTypeDefinition CreateDefinition(string name, StringBuilder log) { var user = new umbraco.BusinessLogic.User("admin"); var result = DataTypeDefinition.MakeNew(user, name); log.AppendLine("Created DataType Definition: " + name); return result; }
private static string GetLanguage(User u) { if (u != null) { return u.Language; } return GetLanguage(""); }
private static string GetLanguage(User u) { if (u != null) { return(u.Language); } return(GetLanguage("")); }
/// <summary> /// Returns translated UI text with a specific key based on the specified user's language settings /// </summary> /// <param name="Key">The key.</param> /// <param name="u">The user.</param> /// <returns></returns> public static string Text(string Key, User u) { if (ApplicationContext.Current == null) { return("[" + Key + "]"); } return(ApplicationContext.Current.Services.TextService.Localize(Key, GetCultureFromUserLanguage(GetLanguage(u)))); }
public void update(documentCarrier carrier, string username, string password) { Authenticate(username, password); if (carrier.Id == 0) { throw new Exception("ID must be specifed when updating"); } if (carrier == null) { throw new Exception("No carrier specified"); } umbraco.BusinessLogic.User user = GetUser(username, password); Document doc = null; try { doc = new Document(carrier.Id); } catch {} if (doc == null) { // We assign the new values: doc.ReleaseDate = carrier.ReleaseDate; } doc.ExpireDate = carrier.ExpireDate; if (carrier.ParentID != 0) { doc.Move(carrier.ParentID); } if (carrier.Name.Length != 0) { doc.Text = carrier.Name; } // We iterate the properties in the carrier if (carrier.DocumentProperties != null) { foreach (documentProperty updatedproperty in carrier.DocumentProperties) { umbraco.cms.businesslogic.property.Property property = doc.getProperty(updatedproperty.Key); if (property == null) { } else { property.Value = updatedproperty.PropertyValue; } } } handlePublishing(doc, carrier, user); }
public static string Culture(User u) { if (ApplicationContext.Current == null) { return(string.Empty); } var found = UserExtensions.GetUserCulture(u.Language, ApplicationContext.Current.Services.TextService); return(found == null ? string.Empty : found.Name); }
public int create(stylesheetCarrier carrier, string username, string password) { Authenticate(username, password); umbraco.BusinessLogic.User user = GetUser(username, password); StyleSheet stylesheet = StyleSheet.MakeNew(user, carrier.Name, (carrier.Name + ".css"), carrier.Content); stylesheet.saveCssToFile(); return(stylesheet.Id); }
/// <summary> /// Returns translated UI text with a specific key and area based on the specified users language settings and single variable passed to the method /// </summary> /// <param name="Area">The area.</param> /// <param name="Key">The key.</param> /// <param name="Variable">The variable.</param> /// <param name="u">The u.</param> /// <returns></returns> public static string Text(string Area, string Key, string Variable, User u) { if (ApplicationContext.Current == null) { return("[" + Key + "]"); } return(ApplicationContext.Current.Services.TextService.Localize( string.Format("{0}/{1}", Area, Key), GetCultureFromUserLanguage(GetLanguage(u)), ConvertToDictionaryVars(new[] { Variable }))); }
public void DeleteRelationType(int relationTypeId) { // Check user calling this service is of type administrator umbraco.BusinessLogic.User user = umbraco.BusinessLogic.User.GetCurrent(); if (user.UserType.Name == "Administrators") { // Delete all relations for this relation type! uQuery.SqlHelper.ExecuteNonQuery(string.Format("DELETE FROM umbracoRelation WHERE relType = {0}", relationTypeId.ToString())); // Delete relation type uQuery.SqlHelper.ExecuteNonQuery(string.Format("DELETE FROM umbracoRelationType WHERE id = {0}", relationTypeId.ToString())); } }
/// <summary> /// Validates the user node tree permissions. /// </summary> /// <param name="umbracoUser"></param> /// <param name="path">The path.</param> /// <param name="action">The action.</param> /// <returns></returns> internal bool ValidateUserNodeTreePermissions(User umbracoUser, string path, string action) { var permissions = umbracoUser.GetPermissions(path); if (permissions.IndexOf(action, StringComparison.Ordinal) > -1 && (path.Contains("-20") || ("," + path + ",").Contains("," + umbracoUser.StartNodeId + ","))) { return(true); } var user = umbracoUser; LogHelper.Info <WebSecurity>("User {0} has insufficient permissions in UmbracoEnsuredPage: '{1}', '{2}', '{3}'", () => user.Name, () => path, () => permissions, () => action); return(false); }
public ActionResult GetPartialViewResultAsHtmlForEditor() { umbraco.BusinessLogic.User u = umbraco.helper.GetCurrentUmbracoUser(); if (u != null) { var modelStr = Request["model"]; var view = Request["view"]; dynamic model = JsonConvert.DeserializeObject(modelStr); return(View("/views/Partials/" + view + ".cshtml", model)); } else { return(new HttpUnauthorizedResult()); } }
public int create(memberCarrier carrier, int memberTypeId, string username, string password) { Authenticate(username, password); // Some validation if (carrier == null) { throw new Exception("No carrier specified"); } if (carrier.Id != 0) { throw new Exception("ID cannot be specifed when creating. Must be 0"); } if (string.IsNullOrEmpty(carrier.DisplayedName)) { carrier.DisplayedName = "unnamed"; } // we fetch the membertype umbraco.cms.businesslogic.member.MemberType mtype = new umbraco.cms.businesslogic.member.MemberType(memberTypeId); // Check if the membertype exists if (mtype == null) { throw new Exception("Membertype " + memberTypeId + " not found"); } // Get the user that creates umbraco.BusinessLogic.User user = GetUser(username, password); // Create the new member umbraco.cms.businesslogic.member.Member newMember = umbraco.cms.businesslogic.member.Member.MakeNew(carrier.DisplayedName, mtype, user); // We iterate the properties in the carrier if (carrier.MemberProperties != null) { foreach (memberProperty updatedproperty in carrier.MemberProperties) { umbraco.cms.businesslogic.property.Property property = newMember.getProperty(updatedproperty.Key); if (property != null) { property.Value = updatedproperty.PropertyValue; } } } return(newMember.Id); }
public int create(mediaCarrier carrier, string username, string password) { Authenticate(username, password); if (carrier == null) { throw new Exception("No carrier specified"); } if (carrier.ParentId == 0) { throw new Exception("Media needs a parent"); } if (carrier.TypeId == 0) { throw new Exception("Type must be specified"); } if (carrier.Text == null || carrier.Text.Length == 0) { carrier.Text = "unnamed"; } umbraco.BusinessLogic.User user = GetUser(username, password); MediaType mt = new MediaType(carrier.TypeId); Media m = Media.MakeNew(carrier.Text, mt, user, carrier.ParentId); if (carrier.MediaProperties != null) { foreach (mediaProperty updatedproperty in carrier.MediaProperties) { if (!(updatedproperty.Key.ToLower().Equals("umbracofile"))) { Property property = m.getProperty(updatedproperty.Key); if (property == null) { throw new Exception("property " + updatedproperty.Key + " was not found"); } property.Value = updatedproperty.PropertyValue; } } } return(m.Id); }
protected override void OnInit(EventArgs e) { base.OnInit(e); umbraco.BusinessLogic.User currentUser = umbraco.helper.GetCurrentUmbracoUser(); #region Security check currentUserPermissions = PermissionService.Instance.GetCurrentLoggedInUserPermissions(); if (currentUserPermissions == null || !currentUserPermissions.HasPermission(GeneralPermissionType.AccessSecurity)) { throw new SecurityException(); } else { bool showUser = true; umbraco.BusinessLogic.User user = umbraco.BusinessLogic.User.GetUser(int.Parse(HttpContext.Current.Request.QueryString["id"])); showUser = !user.IsRoot(); //Don't ever show admin user if (showUser) { bool showAllUsers = currentUser.IsRoot() || currentUser.Applications.Any(a => a.alias == "users"); showUser = showAllUsers || currentUser.Id == user.Id || (permissions != null && currentUserPermissions.StoreSpecificPermissions.Any(p => p.Value.HasFlag(StoreSpecificPermissionType.AccessStore) && permissions.HasPermission(StoreSpecificPermissionType.AccessStore, p.Key))); } if (!showUser) { throw new SecurityException(); } } #endregion AddTab(CommonTerms.Common, PnlCommon, SaveButton_Clicked); PPnlAccessSecurity.Text = StoreTerms.Security; ImgAccessSecurity.ImageUrl = WebUtils.GetWebResourceUrl(Constants.TreeIcons.Lock); PPnlAccessLicenses.Text = DeveloperTerms.Licenses; ImgAccessLicenses.ImageUrl = WebUtils.GetWebResourceUrl(Constants.TreeIcons.LicenseKey); PPnlCreateAndDeleteStore.Text = CommonTerms.CreateAndDeleteStore; ImgCreateAndDeleteStore.ImageUrl = WebUtils.GetWebResourceUrl(Constants.TreeIcons.Store); PnStoreSpecificPermissions.Text = CommonTerms.Stores; PPnlStoreSpecificPermissions.Text = CommonTerms.StoreSpecificPermissions; }
public BuildingBackOfficeModel PostSave(BuildingBackOfficeModel model) { var building = model.Building; var addresses = model.Addresses; umbraco.BusinessLogic.User siteAdmin = umbraco.helper.GetCurrentUmbracoUser(); if (building.Id > 0) { building.ModifiedBy = siteAdmin.Id; building.ModifiedOn = DateTime.Now; _bldgRepo.Update(building.Id, building); } else { building.CreatedBy = siteAdmin.Id; building.CreatedOn = DateTime.Now; building.ModifiedBy = siteAdmin.Id; //should be nullable BM-21 fix building.ModifiedOn = DateTime.Now; //should be nullable BM-21 fix var buildingInserted = _bldgRepo.Insert(building); building.Id = buildingInserted.Id; } foreach (var address in addresses) { if (address.Id > 0) { //DatabaseContext.Database.Update(address); _addressRepo.Update(address.Id, address); } else { if (!IsCanceledAddress(address)) { address.BuildingId = building.Id; //DatabaseContext.Database.Save(address); _addressRepo.Insert(address); } } } return(model); }
public ActionResult SaveEditorConfig() { umbraco.BusinessLogic.User u = umbraco.helper.GetCurrentUmbracoUser(); if (u != null) { var config = Request["config"]; var configPath = Request["configPath"]; using (System.IO.StreamWriter file = new System.IO.StreamWriter(System.Web.HttpContext.Current.Server.MapPath(configPath))) { file.Write(new JSonPresentationFormatter().Format(config)); } return(Json(new { Message = "Saved" }));; } else { return(new HttpUnauthorizedResult()); } }
protected void Page_Load(object sender, EventArgs e) { //gives current user access to the analytics section umbraco.BusinessLogic.User currentUser = umbraco.BasePages.UmbracoEnsuredPage.CurrentUser; bool hasAccess = false; foreach (umbraco.BusinessLogic.Application a in currentUser.Applications) { if (a.alias == "analytics") { hasAccess = true; break; } } //add application if (!hasAccess) { currentUser.addApplication("analytics"); } }
public void update(memberCarrier carrier, string username, string password) { Authenticate(username, password); // Some validation if (carrier.Id == 0) { throw new Exception("ID must be specifed when updating"); } if (carrier == null) { throw new Exception("No carrier specified"); } // Get the user umbraco.BusinessLogic.User user = GetUser(username, password); // We load the member Member member = new Member(carrier.Id); // We assign the new values: member.LoginName = carrier.LoginName; member.Text = carrier.DisplayedName; member.Email = carrier.Email; member.Password = carrier.Password; // We iterate the properties in the carrier if (carrier.MemberProperties != null) { foreach (memberProperty updatedproperty in carrier.MemberProperties) { umbraco.cms.businesslogic.property.Property property = member.getProperty(updatedproperty.Key); if (property != null) { property.Value = updatedproperty.PropertyValue; } } } }
public static StyleSheet Import(XmlNode n, umbraco.BusinessLogic.User u) { string stylesheetName = xmlHelper.GetNodeValue(n.SelectSingleNode("Name")); StyleSheet s = GetByName(stylesheetName); if (s == null) { s = StyleSheet.MakeNew( u, stylesheetName, xmlHelper.GetNodeValue(n.SelectSingleNode("FileName")), xmlHelper.GetNodeValue(n.SelectSingleNode("Content"))); } foreach (XmlNode prop in n.SelectNodes("Properties/Property")) { string alias = xmlHelper.GetNodeValue(prop.SelectSingleNode("Alias")); var sp = s.Properties.SingleOrDefault(p => p != null && p.Alias == alias); string name = xmlHelper.GetNodeValue(prop.SelectSingleNode("Name")); if (sp == default(StylesheetProperty)) { sp = StylesheetProperty.MakeNew( name, s, u); } else { sp.Text = name; } sp.Alias = alias; sp.value = xmlHelper.GetNodeValue(prop.SelectSingleNode("Value")); } s.saveCssToFile(); return(s); }
private void handlePublishing(Document doc, documentCarrier carrier, umbraco.BusinessLogic.User user) { switch (carrier.PublishAction) { case documentCarrier.EPublishAction.Publish: if (doc.PublishWithResult(user)) { umbraco.library.UpdateDocumentCache(doc.Id); } break; case documentCarrier.EPublishAction.Unpublish: if (doc.PublishWithResult(user)) { umbraco.library.UnPublishSingleNode(doc.Id); } break; case documentCarrier.EPublishAction.Ignore: if (doc.Published) { if (doc.PublishWithResult(user)) { umbraco.library.UpdateDocumentCache(doc.Id); } } else { if (doc.PublishWithResult(user)) { umbraco.library.UpdateDocumentCache(doc.Id); } } break; } }
internal bool UserHasAppAccess(string app, User user) { return(user.Applications.Any(uApp => uApp.alias == app)); }
public int create(documentCarrier carrier, string username, string password) { Authenticate(username, password); // Some validation if (carrier == null) { throw new Exception("No carrier specified"); } if (carrier.ParentID == 0) { throw new Exception("Document needs a parent"); } if (carrier.DocumentTypeID == 0) { throw new Exception("Documenttype must be specified"); } if (carrier.Id != 0) { throw new Exception("ID cannot be specifed when creating. Must be 0"); } if (carrier.Name == null || carrier.Name.Length == 0) { carrier.Name = "unnamed"; } umbraco.BusinessLogic.User user = GetUser(username, password); // We get the documenttype umbraco.cms.businesslogic.web.DocumentType docType = new umbraco.cms.businesslogic.web.DocumentType(carrier.DocumentTypeID); if (docType == null) { throw new Exception("DocumenttypeID " + carrier.DocumentTypeID + " not found"); } // We create the document Document newDoc = Document.MakeNew(carrier.Name, docType, user, carrier.ParentID); newDoc.ReleaseDate = carrier.ReleaseDate; newDoc.ExpireDate = carrier.ExpireDate; // We iterate the properties in the carrier if (carrier.DocumentProperties != null) { foreach (documentProperty updatedproperty in carrier.DocumentProperties) { umbraco.cms.businesslogic.property.Property property = newDoc.getProperty(updatedproperty.Key); if (property == null) { throw new Exception("property " + updatedproperty.Key + " was not found"); } property.Value = updatedproperty.PropertyValue; } } // We check the publishaction and do the appropiate handlePublishing(newDoc, carrier, user); // We return the ID of the document..65 return(newDoc.Id); }
internal bool UserHasAppAccess(string app, User user) { return user.Applications.Any(uApp => uApp.alias == app); }
/// <summary> /// Validates the user node tree permissions. /// </summary> /// <param name="umbracoUser"></param> /// <param name="path">The path.</param> /// <param name="action">The action.</param> /// <returns></returns> internal bool ValidateUserNodeTreePermissions(User umbracoUser, string path, string action) { var permissions = umbracoUser.GetPermissions(path); if (permissions.IndexOf(action, StringComparison.Ordinal) > -1 && (path.Contains("-20") || ("," + path + ",").Contains("," + umbracoUser.StartNodeId + ","))) return true; var user = umbracoUser; LogHelper.Info<WebSecurity>("User {0} has insufficient permissions in UmbracoEnsuredPage: '{1}', '{2}', '{3}'", () => user.Name, () => path, () => permissions, () => action); return false; }
/// <summary> /// Returns translated UI text with a specific key based on the specified user's language settings /// </summary> /// <param name="Key">The key.</param> /// <param name="u">The user.</param> /// <returns></returns> public static string Text(string Key, User u) { return GetText(string.Empty, Key, null, GetLanguage(u)); }
/// <summary> /// Adds a new membership user to the data source. /// </summary> /// <param name="memberTypeAlias"></param> /// <param name="username">The user name for the new user.</param> /// <param name="password">The password for the new user.</param> /// <param name="email">The e-mail address for the new user.</param> /// <param name="passwordQuestion">The password question for the new user.</param> /// <param name="passwordAnswer">The password answer for the new user</param> /// <param name="isApproved">Whether or not the new user is approved to be validated.</param> /// <param name="providerUserKey">The unique identifier from the membership data source for the user.</param> /// <param name="status">A <see cref="T:System.Web.Security.MembershipCreateStatus"></see> enumeration value indicating whether the user was created successfully.</param> /// <returns> /// A <see cref="T:System.Web.Security.MembershipUser"></see> object populated with the information for the newly created user. /// </returns> protected override MembershipUser PerformCreateUser(string memberTypeAlias, string username, string password, string email, string passwordQuestion, string passwordAnswer, bool isApproved, object providerUserKey, out MembershipCreateStatus status) { if (Member.GetMemberFromLoginName(username) != null) { status = MembershipCreateStatus.DuplicateUserName; LogHelper.Warn <UmbracoMembershipProvider>("Cannot create member as username already exists: " + username); return(null); } if (Member.GetMemberFromEmail(email) != null && RequiresUniqueEmail) { status = MembershipCreateStatus.DuplicateEmail; LogHelper.Warn <UmbracoMembershipProvider>( "Cannot create member as a member with the same email address exists: " + email); return(null); } var memberType = MemberType.GetByAlias(memberTypeAlias); if (memberType == null) { throw new InvalidOperationException("Could not find a member type with alias " + memberTypeAlias + ". Ensure your membership provider configuration is up to date and that the default member type exists."); } var m = Member.MakeNew(username, email, memberType, User.GetUser(0)); string salt; var encodedPassword = EncryptOrHashNewPassword(password, out salt); //set the password on the member m.ChangePassword(FormatPasswordForStorage(encodedPassword, salt)); // custom fields if (string.IsNullOrEmpty(PasswordRetrievalQuestionPropertyTypeAlias) == false) { UpdateMemberProperty(m, PasswordRetrievalQuestionPropertyTypeAlias, passwordQuestion); } if (string.IsNullOrEmpty(PasswordRetrievalAnswerPropertyTypeAlias) == false) { UpdateMemberProperty(m, PasswordRetrievalAnswerPropertyTypeAlias, passwordAnswer); } if (string.IsNullOrEmpty(ApprovedPropertyTypeAlias) == false) { UpdateMemberProperty(m, ApprovedPropertyTypeAlias, isApproved ? 1 : 0); } if (string.IsNullOrEmpty(LastLoginPropertyTypeAlias) == false) { UpdateMemberProperty(m, LastLoginPropertyTypeAlias, DateTime.Now); } if (string.IsNullOrEmpty(LastPasswordChangedPropertyTypeAlias) == false) { UpdateMemberProperty(m, LastPasswordChangedPropertyTypeAlias, DateTime.Now); } var mUser = ConvertToMembershipUser(m); // save m.Save(); status = MembershipCreateStatus.Success; return(mUser); }
/// <summary> /// Returns translated UI text with a specific key and area, based on the specified users language settings /// </summary> /// <param name="Area">The area.</param> /// <param name="Key">The key.</param> /// <param name="u">The user.</param> /// <returns></returns> public static string Text(string Area, string Key, User u) { return GetText(Area, Key, null, GetLanguage(u)); }
/// <summary> /// Returns translated UI text with a specific area and key. based on the specified users language settings and variables array passed to the method /// </summary> /// <param name="Area">The area.</param> /// <param name="Key">The key.</param> /// <param name="Variables">The variables array.</param> /// <param name="u">The user.</param> /// <returns></returns> public static string Text(string Area, string Key, string[] Variables, User u) { return GetText(Area, Key, Variables, GetLanguage(u)); }
internal bool UserHasSectionAccess(string section, User user) { return(user.Applications.Any(uApp => uApp.alias == section)); }
/// <summary> /// Returns translated UI text with a specific key and area based on the specified users language settings and single variable passed to the method /// </summary> /// <param name="Area">The area.</param> /// <param name="Key">The key.</param> /// <param name="Variable">The variable.</param> /// <param name="u">The u.</param> /// <returns></returns> public static string Text(string Area, string Key, string Variable, User u) { return GetText(Area, Key, new[] { Variable }, GetLanguage(u)); }
/// <summary> /// Gets the current Culture for the logged-in users /// </summary> /// <param name="u">The user.</param> /// <returns></returns> public static string Culture(User u) { return Culture(u.Language); }