public void ProcessFile() { XmlDocument XmlDoc = new XmlDocument(); XmlDoc.Load(FilePath); foreach (var Node in XmlDoc.DocumentElement.GetElementsByTagName("AdminUser")) { XmlElement Element = (XmlElement) Node; AdminUser AdmUser = new AdminUser(); AdmUser.Username = Element.GetElementsByTagName("Username")[0].InnerText; AdmUser.Email = Element.GetElementsByTagName("Email")[0].InnerText; AdmUser.Hashed_Password = Element.GetElementsByTagName("Hashed_Password")[0].InnerText; AdmUser.Active = true; foreach (var ChildNode in Element.GetElementsByTagName("Role")) { XmlElement ChildElement = (XmlElement)ChildNode; AdmUser.RoleList.Add(ChildElement.InnerText); } AdminUserDAO.Save(AdmUser); } }
public void AdminUsers_CreateAll() { List<AdminUserRole> RoleList = AdminUserRoleDAO.LoadAll(); if (RoleList != null && RoleList.Count > 0) { foreach (var UserRole in RoleList) { var DeleteQuery = Query<AdminUser>.EQ(e => e.Username, UserRole.Name); Execute.Delete<AdminUser>("AdminUsers", DeleteQuery); AdminUser NewUser = new AdminUser(); NewUser.Active = true; NewUser.Username = UserRole.Name; NewUser.Hashed_Password = "******"; NewUser.RoleList.Add(UserRole.Name); AdminUserDAO.Save(NewUser); } } }
public void AdminUsers_CreateTheClient() { var DeleteQuery = Query<AdminUser>.EQ(e => e.Username, "theclient"); Execute.Delete<AdminUser>("AdminUsers", DeleteQuery); AdminUser NewUser = new AdminUser(); NewUser.Active = true; NewUser.Username = "******"; NewUser.Hashed_Password = "******"; NewUser.RoleList.Add("page-view"); NewUser.RoleList.Add("page-edit"); NewUser.RoleList.Add("product-view"); NewUser.RoleList.Add("product-edit"); NewUser.RoleList.Add("setting-view"); NewUser.RoleList.Add("setting-value-edit"); NewUser.RoleList.Add("nav-menu-edit"); NewUser.RoleList.Add("purchase-order-view"); NewUser.RoleList.Add("purchase-order-edit"); AdminUserDAO.Save(NewUser); }
/// <summary> /// Add or update an admin user. Username is unique, password is hashed based on mongo object id. /// Will return false if attempting to save with new username of a user that already exists. /// </summary> /// <param name="adminUser">The new or existing admin user</param> /// <returns>bool if successful.</returns> public static bool Save(AdminUser adminUser) { AdminUser AdminUser = LoadByUsername(adminUser.Username); //if no users in the database exist with that username, or the only user that exists in the one we are trying to save. if (AdminUser == null || string.IsNullOrWhiteSpace(AdminUser.Id) || (AdminUser.Id.Equals(adminUser.Id))) { //if true we are saving a brand new user if (string.IsNullOrWhiteSpace(adminUser.Id)) { //generate a brand new mongo id adminUser.Id = ObjectId.GenerateNewId().ToString(); //hash the password by using the user's mongo id adminUser.Hashed_Password = Hashing.GetSaltedHash(adminUser.Hashed_Password, adminUser.Id.ToString()); } //Timestamp of when the page was saved. adminUser.ModifiedDateUTC = DateTime.UtcNow; return Execute.Save<AdminUser>(COLLECTION_NAME, adminUser); } return false; }
public static void Logout() { User = null; }