//------------------------------------------------------------------------------------------- public MembershipUser CreateUser(string username, string password, string email, string passwordQuestion, string passwordAnswer, bool isApproved, object providerUserKey, string userhostaddress, string referredby, out MembershipCreateStatus status) { username = username.ToLower(); email = email.ToLower(); using (WeavverEntityContainer data = new WeavverEntityContainer()) { System_Users user = new System_Users(); user.EmailAddress = email; user.Username = username; user.Password = password; user.ReferredBy = referredby; Random rHash = new Random(); string seed = rHash.Next().ToString() + rHash.Next().ToString() + rHash.Next().ToString() + rHash.Next().ToString(); user.ActivationKey = MD5Hash(seed); user.LastLoggedIn = DateTime.UtcNow; user.UpdatedAt = DateTime.UtcNow; user.UpdatedBy = Guid.Empty; user.CreatedAt = DateTime.UtcNow; user.CreatedBy = Guid.Empty; // todo: add account note, signed up from "ip address" - user.CreatedBy = userhostaddress; data.System_Users.Add(user); if (data.SaveChanges() > 0) { status = MembershipCreateStatus.Success; return GetUser(username, false); } else { status = MembershipCreateStatus.ProviderError; return null; } } }
//------------------------------------------------------------------------------------------- public override MembershipUser GetUser(string username, bool userIsOnline) { System_Users u = new System_Users(); u.Id = Guid.NewGuid(); u.Username = username; u.Activated = true; u.OrganizationId = new Guid("0baae579-dbd8-488d-9e51-dd4dd6079e95"); return new WeavverMembershipUser("LdapMembershipProvider", username, u.Id, u.EmailAddress, u.PasswordQuestion, null, u.Activated, u.Locked, u.CreatedAt, u.LastLoggedIn.Value, u.LastLoggedIn.Value, DateTime.UtcNow, DateTime.UtcNow); //var user = GetUser(username); //if (user != null) //{ // WeavverMembershipUser wvvrMembershipUser = new WeavverMembershipUser("WeavverMembershipProvider", user.Username, user.Id, user.EmailAddress, "none", "", user.Activated, false, DateTime.UtcNow, DateTime.UtcNow, DateTime.UtcNow, DateTime.UtcNow, user.CreatedAt.Value); // wvvrMembershipUser.WeavverSysUser = user; // return wvvrMembershipUser; //} //else //{ // return null; //} }
//------------------------------------------------------------------------------------------- private void ConfigureDatabase() { using (WeavverEntityContainer data = new WeavverEntityContainer()) { // Run SQL Deploy script string connectionString = ConfigurationManager.ConnectionStrings["WeavverEntityContainer"].ConnectionString; var entityBuilder = new System.Data.EntityClient.EntityConnectionStringBuilder(connectionString); SqlConnection connection = new SqlConnection(entityBuilder.ProviderConnectionString); connection.Open(); string script = System.IO.File.ReadAllText(Server.MapPath(@"\bin\Database.sql")); //data.CreateDatabaseScript(); script = script.Replace("%dalpath%", Server.MapPath(@"\bin\Weavver.DAL.dll")); script = script.Replace("%databasename%", connection.Database); string[] blocks = System.Text.RegularExpressions.Regex.Split(script, "\nGO"); foreach (string block in blocks) { if (block.Trim() != String.Empty) { SqlCommand createDb = new SqlCommand(block, connection); try { createDb.ExecuteNonQuery(); } catch (Exception ex) { throw new Exception("Block: " + block, ex); } } } // CREATE INITIAL DATA Guid orgId = Guid.NewGuid(); Session["SelectedOrganizationId"] = orgId; // deploy first org Weavver.Data.Logistics_Organizations org = new Weavver.Data.Logistics_Organizations(); org.Id = orgId; org.OrganizationId = org.Id; // THIS IS OVERRIDDEN ANYWAY BY AUDITUTILITY AS A SECURITY PRECAUTION org.OrganizationType = "Personal"; org.Name = Organization.Text; org.VanityURL = "default"; org.EIN = ""; org.Founded = DateTime.UtcNow; org.Bio = "This is a sample organization."; org.CreatedAt = DateTime.UtcNow; org.CreatedBy = Guid.Empty; org.UpdatedAt = DateTime.UtcNow; org.UpdatedBy = Guid.Empty; data.Logistics_Organizations.AddObject(org); data.SaveChanges(); Weavver.Data.System_Users user = new Weavver.Data.System_Users(); user.Id = orgId; user.OrganizationId = org.Id; // THIS IS OVERRIDDEN ANYWAY BY AUDITUTILITY AS A SECURITY PRECAUTION user.FirstName = "Enlightened"; user.LastName = "User"; user.Activated = true; user.Locked = false; user.Username = Username.Text; user.Password = Password.Text; user.CreatedAt = DateTime.UtcNow; user.CreatedBy = Guid.Empty; user.UpdatedAt = DateTime.UtcNow; user.UpdatedBy = Guid.Empty; data.System_Users.AddObject(user); data.SaveChanges(); Roles.ApplicationName = orgId.ToString(); string adminuser = user.Username; Roles.CreateRole("Administrators"); Roles.AddUsersToRoles(new string[] { adminuser }, new string[] { "Administrators" }); Roles.CreateRole("Accountants"); Roles.AddUsersToRoles(new string[] { adminuser }, new string[] { "Accountants" }); if (data.SaveChanges() > 0) Response.Redirect("~/install/step2"); } }
//------------------------------------------------------------------------------------------- private void ConfigureDatabase() { using (WeavverEntityContainer data = new WeavverEntityContainer()) { // Run SQL Deploy script string connectionString = ConfigurationManager.ConnectionStrings["WeavverEntityContainer"].ConnectionString; var entityBuilder = new System.Data.EntityClient.EntityConnectionStringBuilder(connectionString); SqlConnection connection = new SqlConnection(entityBuilder.ProviderConnectionString); connection.Open(); string script = System.IO.File.ReadAllText(Server.MapPath(@"\bin\Database.sql")); //data.CreateDatabaseScript(); script = script.Replace("%dalpath%", Server.MapPath(@"\bin\Weavver.DAL.dll")); script = script.Replace("%databasename%", connection.Database); string[] blocks = System.Text.RegularExpressions.Regex.Split(script, "\nGO"); foreach (string block in blocks) { if (block.Trim() != String.Empty) { SqlCommand createDb = new SqlCommand(block, connection); try { createDb.ExecuteNonQuery(); } catch (Exception ex) { throw new Exception("Block: " + block, ex); } } } // CREATE INITIAL DATA Guid orgId = Guid.NewGuid(); Session["SelectedOrganizationId"] = orgId; // deploy first org Weavver.Data.Logistics_Organizations org = new Weavver.Data.Logistics_Organizations(); org.Id = orgId; org.OrganizationId = org.Id; // THIS IS OVERRIDDEN ANYWAY BY AUDITUTILITY AS A SECURITY PRECAUTION org.OrganizationType = "Personal"; org.Name = Organization.Text; org.VanityURL = "default"; org.EIN = ""; org.Founded = DateTime.UtcNow; org.Bio = "This is a sample organization."; org.CreatedAt = DateTime.UtcNow; org.CreatedBy = Guid.Empty; org.UpdatedAt = DateTime.UtcNow; org.UpdatedBy = Guid.Empty; data.Logistics_Organizations.AddObject(org); data.SaveChanges(); Weavver.Data.System_Users user = new Weavver.Data.System_Users(); user.Id = orgId; user.OrganizationId = org.Id; // THIS IS OVERRIDDEN ANYWAY BY AUDITUTILITY AS A SECURITY PRECAUTION user.FirstName = "Enlightened"; user.LastName = "User"; user.Activated = true; user.Locked = false; user.Username = Username.Text; user.Password = Password.Text; user.CreatedAt = DateTime.UtcNow; user.CreatedBy = Guid.Empty; user.UpdatedAt = DateTime.UtcNow; user.UpdatedBy = Guid.Empty; data.System_Users.AddObject(user); data.SaveChanges(); Roles.ApplicationName = orgId.ToString(); string adminuser = user.Username; Roles.CreateRole("Administrators"); Roles.AddUsersToRoles(new string[] { adminuser }, new string[] { "Administrators" }); Roles.CreateRole("Accountants"); Roles.AddUsersToRoles(new string[] { adminuser }, new string[] { "Accountants" }); if (data.SaveChanges() > 0) { Response.Redirect("~/install/step2"); } } }