static RoleHelper() { RoleHelper.defaultRoles = null; RoleHelper.rolesConfig = null; RoleHelper.rolesConfig = HiConfiguration.GetConfig().RolesConfiguration; RoleHelper.defaultRoles = RoleHelper.rolesConfig.RoleList(); }
private bool AddBuiltInRoles(out string errorMsg) { DbConnection connection = null; DbTransaction transaction = null; try { using (connection = new SqlConnection(this.GetConnectionString())) { connection.Open(); DbCommand command = connection.CreateCommand(); transaction = connection.BeginTransaction(); command.Connection = connection; command.Transaction = transaction; command.CommandType = CommandType.Text; command.CommandText = "INSERT INTO aspnet_Roles(RoleName, LoweredRoleName) VALUES(@RoleName, LOWER(@RoleName))"; DbParameter parameter = new SqlParameter("@RoleName", SqlDbType.NVarChar, 0x100); command.Parameters.Add(parameter); RolesConfiguration rolesConfiguration = HiConfiguration.GetConfig().RolesConfiguration; command.Parameters["@RoleName"].Value = rolesConfiguration.Distributor; command.ExecuteNonQuery(); command.Parameters["@RoleName"].Value = rolesConfiguration.Manager; command.ExecuteNonQuery(); command.Parameters["@RoleName"].Value = rolesConfiguration.Member; command.ExecuteNonQuery(); command.Parameters["@RoleName"].Value = rolesConfiguration.SystemAdministrator; command.ExecuteNonQuery(); command.Parameters["@RoleName"].Value = rolesConfiguration.Underling; command.ExecuteNonQuery(); transaction.Commit(); connection.Close(); } errorMsg = null; return(true); } catch (SqlException exception) { errorMsg = exception.Message; if (transaction != null) { try { transaction.Rollback(); } catch (Exception exception2) { errorMsg = exception2.Message; } } if ((connection != null) && (connection.State != ConnectionState.Closed)) { connection.Close(); connection.Dispose(); } return(false); } }
public AuthController( SignInManager <ApplicationUser> signInManager, RoleManager <IdentityRole <long> > roleManager, TwitterAppConfiguration twitterConfiguration, RolesConfiguration roles) { _signInManager = signInManager; _roleManager = roleManager; _userManager = signInManager.UserManager; _twitterConfiguration = twitterConfiguration; _adminUsers = roles.AdminUsers; }
private void TreeView1_AfterSelect(object sender, TreeViewEventArgs e) { if (e.Node.Name == "System") { return; } if (m_Current != null) { if (m_Current.Tag.ToString() == e.Node.Name) { return; } } m_Current?.Dispose(); UserControl control; if (e.Node.Name == "General") { control = new GeneralConfiguration(); } else if (e.Node.Name == "Factory") { control = new ArrayConfiguration( CommonLibrary.CommonHeadCode.SimplifyHeadCode.请求分厂, CommonLibrary.CommonHeadCode.SimplifyHeadCode.分厂, e.Node.Text); } else if (e.Node.Name == "Client") { control = new ClientConfiguration(); } else if (e.Node.Name == "Roles") { control = new RolesConfiguration(); } else { control = new UserControl(); } control.Width = panel1.Width; control.Height = panel1.Height; control.Location = new Point(0, 0); control.Parent = panel1; control.Tag = e.Node.Name; m_Current = control; }
private void RefreshUserAccess( ) { var data = RolesConfiguration.GetRefreshedAccess( ); if (data != null && data.Any( )) { var dir = string.Format(@"{0}{1}", Page.Request.PhysicalApplicationPath, "AccessMenu"); if (!Directory.Exists(dir)) { Directory.CreateDirectory(dir); } var fullPath = Path.Combine(dir, "Menu.exe"); Sars.Systems.Serialization.XmlObjectSerializer.Persist <List <CacheUserAccessDetails> >(data, fullPath); } }
static RoleHelper() { rolesConfig = HiConfiguration.GetConfig().RolesConfiguration; defaultRoles = rolesConfig.RoleList(); }
/// <summary> /// 创建管理员 /// </summary> /// <param name="newUserId"></param> /// <param name="errorMsg"></param> /// <returns></returns> bool CreateAdministrator(out int newUserId, out string errorMsg) { DbConnection connection = null; DbTransaction transaction = null; bool flag = false; try { using (connection = new SqlConnection(GetConnectionString())) { connection.Open(); RolesConfiguration rolesConfiguration = HiConfiguration.GetConfig().RolesConfiguration; DbCommand command = connection.CreateCommand(); transaction = connection.BeginTransaction(); command.Connection = connection; command.Transaction = transaction; command.CommandType = CommandType.Text; command.CommandText = "SELECT RoleId FROM aspnet_Roles WHERE [LoweredRoleName] = LOWER(@RoleName)"; command.Parameters.Add(new SqlParameter("@RoleName", rolesConfiguration.SystemAdministrator)); Guid guid = (Guid)command.ExecuteScalar(); command.Parameters["@RoleName"].Value = rolesConfiguration.Manager; Guid guid2 = (Guid)command.ExecuteScalar(); command.Parameters.Clear(); command.CommandText = "INSERT INTO aspnet_Users (UserName, LoweredUserName, IsAnonymous, UserRole, LastActivityDate, Password, PasswordFormat, PasswordSalt, IsApproved, IsLockedOut, CreateDate, LastLoginDate, LastPasswordChangedDate, LastLockoutDate, FailedPasswordAttemptCount, FailedPasswordAttemptWindowStart, FailedPasswordAnswerAttemptCount, FailedPasswordAnswerAttemptWindowStart, Email, LoweredEmail) VALUES (@Username, LOWER(@Username), 0, @UserRole, @CreateDate, @Password, @PasswordFormat, @PasswordSalt, 1, 0, @CreateDate, @CreateDate, @CreateDate, CONVERT( datetime, '17540101', 112 ), 0, CONVERT( datetime, '17540101', 112 ), 0, CONVERT( datetime, '17540101', 112 ), @Email, LOWER(@Email));SELECT @@IDENTITY"; command.Parameters.Add(new SqlParameter("@Username", username)); command.Parameters.Add(new SqlParameter("@UserRole", UserRole.SiteManager)); command.Parameters.Add(new SqlParameter("@CreateDate", DateTime.Now)); command.Parameters.Add(new SqlParameter("@Password", password)); command.Parameters.Add(new SqlParameter("@PasswordFormat", MembershipPasswordFormat.Clear)); command.Parameters.Add(new SqlParameter("@PasswordSalt", "")); command.Parameters.Add(new SqlParameter("@Email", email)); newUserId = Convert.ToInt32(command.ExecuteScalar()); command.Parameters.Clear(); command.CommandText = "INSERT INTO aspnet_Managers(UserId) VALUES(@UserId)"; command.Parameters.Add(new SqlParameter("@UserId", (int)newUserId)); command.ExecuteNonQuery(); command.CommandText = "INSERT INTO aspnet_UsersInRoles(UserId, RoleId) VALUES(@UserId, @RoleId)"; command.Parameters.Add(new SqlParameter("@RoleId", guid2)); command.ExecuteNonQuery(); command.Parameters["@RoleId"].Value = guid; command.ExecuteNonQuery(); transaction.Commit(); connection.Close(); } errorMsg = ""; flag = true; } catch (SqlException exception) { errorMsg = exception.Message; newUserId = 0; if (transaction != null) { try { transaction.Rollback(); } catch (Exception exception2) { errorMsg = exception2.Message; } } if ((connection != null) && (connection.State != ConnectionState.Closed)) { connection.Close(); connection.Dispose(); } } return(flag); }
private bool CreateAdministrator(out int newUserId, out string errorMsg) { System.Data.Common.DbConnection dbConnection = null; System.Data.Common.DbTransaction dbTransaction = null; bool result; try { System.Data.Common.DbConnection dbConnection2; dbConnection = (dbConnection2 = new System.Data.SqlClient.SqlConnection(this.GetConnectionString())); try { dbConnection.Open(); RolesConfiguration rolesConfiguration = HiConfiguration.GetConfig().RolesConfiguration; System.Data.Common.DbCommand dbCommand = dbConnection.CreateCommand(); dbTransaction = dbConnection.BeginTransaction(); dbCommand.Connection = dbConnection; dbCommand.Transaction = dbTransaction; dbCommand.CommandType = System.Data.CommandType.Text; dbCommand.CommandText = "SELECT RoleId FROM aspnet_Roles WHERE [LoweredRoleName] = LOWER(@RoleName)"; dbCommand.Parameters.Add(new System.Data.SqlClient.SqlParameter("@RoleName", rolesConfiguration.SystemAdministrator)); System.Guid guid = (System.Guid)dbCommand.ExecuteScalar(); dbCommand.Parameters["@RoleName"].Value = rolesConfiguration.Manager; System.Guid guid2 = (System.Guid)dbCommand.ExecuteScalar(); dbCommand.Parameters.Clear(); dbCommand.CommandText = "INSERT INTO aspnet_Users (UserName, LoweredUserName, IsAnonymous, UserRole, LastActivityDate, Password, PasswordFormat, PasswordSalt, IsApproved, IsLockedOut, CreateDate, LastLoginDate, LastPasswordChangedDate, LastLockoutDate, FailedPasswordAttemptCount, FailedPasswordAttemptWindowStart, FailedPasswordAnswerAttemptCount, FailedPasswordAnswerAttemptWindowStart, Email, LoweredEmail) VALUES (@Username, LOWER(@Username), 0, @UserRole, @CreateDate, @Password, @PasswordFormat, @PasswordSalt, 1, 0, @CreateDate, @CreateDate, @CreateDate, CONVERT( datetime, '17540101', 112 ), 0, CONVERT( datetime, '17540101', 112 ), 0, CONVERT( datetime, '17540101', 112 ), @Email, LOWER(@Email));SELECT @@IDENTITY"; dbCommand.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Username", this.username)); dbCommand.Parameters.Add(new System.Data.SqlClient.SqlParameter("@UserRole", UserRole.SiteManager)); dbCommand.Parameters.Add(new System.Data.SqlClient.SqlParameter("@CreateDate", System.DateTime.Now)); dbCommand.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Password", this.password)); dbCommand.Parameters.Add(new System.Data.SqlClient.SqlParameter("@PasswordFormat", System.Web.Security.MembershipPasswordFormat.Clear)); dbCommand.Parameters.Add(new System.Data.SqlClient.SqlParameter("@PasswordSalt", "")); dbCommand.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Email", this.email)); newUserId = System.Convert.ToInt32(dbCommand.ExecuteScalar()); dbCommand.Parameters.Clear(); dbCommand.CommandText = "INSERT INTO aspnet_Managers(UserId) VALUES(@UserId)"; dbCommand.Parameters.Add(new System.Data.SqlClient.SqlParameter("@UserId", newUserId)); dbCommand.ExecuteNonQuery(); dbCommand.CommandText = "INSERT INTO aspnet_UsersInRoles(UserId, RoleId) VALUES(@UserId, @RoleId)"; dbCommand.Parameters.Add(new System.Data.SqlClient.SqlParameter("@RoleId", guid2)); dbCommand.ExecuteNonQuery(); dbCommand.Parameters["@RoleId"].Value = guid; dbCommand.ExecuteNonQuery(); dbTransaction.Commit(); dbConnection.Close(); } finally { if (dbConnection2 != null) { ((System.IDisposable)dbConnection2).Dispose(); } } errorMsg = null; result = true; } catch (System.Data.SqlClient.SqlException ex) { errorMsg = ex.Message; newUserId = 0; if (dbTransaction != null) { try { dbTransaction.Rollback(); } catch (System.Exception ex2) { errorMsg = ex2.Message; } } if (dbConnection != null && dbConnection.State != System.Data.ConnectionState.Closed) { dbConnection.Close(); dbConnection.Dispose(); } result = false; } return(result); }
private bool AddBuiltInRoles(out string errorMsg) { System.Data.Common.DbConnection dbConnection = null; System.Data.Common.DbTransaction dbTransaction = null; bool result; try { System.Data.Common.DbConnection dbConnection2; dbConnection = (dbConnection2 = new System.Data.SqlClient.SqlConnection(this.GetConnectionString())); try { dbConnection.Open(); System.Data.Common.DbCommand dbCommand = dbConnection.CreateCommand(); dbTransaction = dbConnection.BeginTransaction(); dbCommand.Connection = dbConnection; dbCommand.Transaction = dbTransaction; dbCommand.CommandType = System.Data.CommandType.Text; dbCommand.CommandText = "INSERT INTO aspnet_Roles(RoleName, LoweredRoleName) VALUES(@RoleName, LOWER(@RoleName))"; System.Data.Common.DbParameter value = new System.Data.SqlClient.SqlParameter("@RoleName", System.Data.SqlDbType.NVarChar, 256); dbCommand.Parameters.Add(value); RolesConfiguration rolesConfiguration = HiConfiguration.GetConfig().RolesConfiguration; dbCommand.Parameters["@RoleName"].Value = rolesConfiguration.Manager; dbCommand.ExecuteNonQuery(); dbCommand.Parameters["@RoleName"].Value = rolesConfiguration.Member; dbCommand.ExecuteNonQuery(); dbCommand.Parameters["@RoleName"].Value = rolesConfiguration.SystemAdministrator; dbCommand.ExecuteNonQuery(); dbTransaction.Commit(); dbConnection.Close(); } finally { if (dbConnection2 != null) { ((System.IDisposable)dbConnection2).Dispose(); } } errorMsg = null; result = true; } catch (System.Data.SqlClient.SqlException ex) { errorMsg = ex.Message; if (dbTransaction != null) { try { dbTransaction.Rollback(); } catch (System.Exception ex2) { errorMsg = ex2.Message; } } if (dbConnection != null && dbConnection.State != System.Data.ConnectionState.Closed) { dbConnection.Close(); dbConnection.Dispose(); } result = false; } return(result); }
protected override void Seed(ApplicationDbContext context) { // Configure application user roles with custom class RolesConfiguration.ConfigureUserRoles(context); // Seed default provinces context.Provinces.Add(new Province { ProvinceName = "AB" }); context.Provinces.Add(new Province { ProvinceName = "BC" }); context.Provinces.Add(new Province { ProvinceName = "MB" }); context.Provinces.Add(new Province { ProvinceName = "NB" }); context.Provinces.Add(new Province { ProvinceName = "NL" }); context.Provinces.Add(new Province { ProvinceName = "NT" }); context.Provinces.Add(new Province { ProvinceName = "NS" }); context.Provinces.Add(new Province { ProvinceName = "NU" }); context.Provinces.Add(new Province { ProvinceName = "ON" }); context.Provinces.Add(new Province { ProvinceName = "PE" }); context.Provinces.Add(new Province { ProvinceName = "QC" }); context.Provinces.Add(new Province { ProvinceName = "SK" }); context.Provinces.Add(new Province { ProvinceName = "YT" }); // Seed default positions context.Positions.Add(new Position { Title = "Developer" }); context.Positions.Add(new Position { Title = "Salesman" }); context.Positions.Add(new Position { Title = "Designer" }); context.Positions.Add(new Position { Title = "Manager" }); // This is needed. Employees and customers are distinguished by position Id and // if the position gets deleted, we would need to assign temporary position Id context.Positions.Add(new Position { Title = "UnAssigned" }); base.Seed(context); }