public override bool IsUserInRole(string username, string roleName) { if (!Initialized) { return(_prevProvider.IsUserInRole(username, roleName)); } string connString = ConnectionString; if (string.IsNullOrEmpty(username)) { MySqlSimpleMembershipProvider.NullArgumentException("username"); } if (string.IsNullOrEmpty(roleName)) { MySqlSimpleMembershipProvider.NullArgumentException("roleName"); } int userid = MySqlSimpleMembershipProvider.GetUserId(username, connString, UserTableName, UserIdColumn, UserNameColumn); int roleid = GetRoleId(roleName); if (userid <= 0 || roleid <= 0) { return(false); } using (MySqlDatabaseWrapper dbConn = new MySqlDatabaseWrapper(connString)) { return((dbConn.ExecuteQuery(string.Format("select count(userid) from {0} where userid=? and roleid=?;", _userInRolesTable), userid, roleid)).Count() > 0); } }
public override string[] GetUsersInRole(string roleName) { if (!Initialized) { return(_prevProvider.GetUsersInRole(roleName)); } if (string.IsNullOrEmpty(roleName)) { MySqlSimpleMembershipProvider.NullArgumentException("roleName"); } int roleid = GetRoleId(roleName); if (roleid > 0) { using (MySqlDatabaseWrapper dbConn = new MySqlDatabaseWrapper(ConnectionString)) { var users = dbConn.ExecuteQuery(string.Format("select ut.{0} from {1} as urt join {2} as ut on urt.userid = ut.{3} where urt.roleid=?;", UserNameColumn, _userInRolesTable, UserTableName, UserIdColumn), roleid); if (users.Count() > 0) { return(users.Select(role => role[0].ToString()).ToArray()); } } } return(null); }
public override string[] GetRolesForUser(string username) { if (!Initialized) { return(_prevProvider.GetRolesForUser(username)); } if (string.IsNullOrEmpty(username)) { MySqlSimpleMembershipProvider.NullArgumentException("username"); } string connString = ConnectionString; int userid = MySqlSimpleMembershipProvider.GetUserId(username, connString, UserTableName, UserIdColumn, UserNameColumn); if (userid > 0) { using (MySqlDatabaseWrapper dbConn = new MySqlDatabaseWrapper(connString)) { var roles = dbConn.ExecuteQuery(string.Format("select rt.rolename from {0} as urt join {1} as rt on urt.roleid = rt.roleid where urt.userid=?;", _userInRolesTable, _rolesTable), userid); if (roles.Count() > 0) { return(roles.Select(role => role[0].ToString()).ToArray()); } } } return(null); }
public override string[] FindUsersInRole(string roleName, string usernameToMatch) { if (!Initialized) { return(_prevProvider.FindUsersInRole(roleName, usernameToMatch)); } if (string.IsNullOrEmpty(roleName)) { MySqlSimpleMembershipProvider.NullArgumentException("roleName"); } if (string.IsNullOrEmpty(usernameToMatch)) { return(GetUsersInRole(roleName)); } using (MySqlDatabaseWrapper dbConn = new MySqlDatabaseWrapper(ConnectionString)) { var usersName = dbConn.ExecuteQuery(string.Format("select ut.{0} from {1} as rt join {2} as urt on rt.roleid=urt.roleid join {3} as ut on rt.userid=ut.{4} where rt.rolename=? and ut.name like '%?%'", UserNameColumn, _rolesTable, _userInRolesTable, UserTableName, UserIdColumn), roleName, usernameToMatch); if (usersName.Count() > 0) { return(usersName.Select(username => username[0].ToString()).ToArray()); } } return(null); }
public override bool DeleteRole(string roleName, bool throwOnPopulatedRole) { if (!Initialized) { return(_prevProvider.DeleteRole(roleName, throwOnPopulatedRole)); } if (string.IsNullOrEmpty(roleName)) { MySqlSimpleMembershipProvider.NullArgumentException("roleName"); } int roleid = GetRoleId(roleName); if (roleid <= 0) { return(false); } using (MySqlDatabaseWrapper dbConn = new MySqlDatabaseWrapper(ConnectionString)) { if (throwOnPopulatedRole) { if (IsRoleInUse(roleid)) { throw new InvalidOperationException(string.Format(Resources.RoleInUse, roleName)); } } else { dbConn.ExecuteNonQuery(string.Format("delete from {0} where roleid=?;", _userInRolesTable), roleid); } return(dbConn.ExecuteNonQuery(string.Format("delete from {0} where roleid=?;", _rolesTable), roleid) > 0); } }
public override void CreateRole(string roleName) { if (!Initialized) { _prevProvider.CreateRole(roleName); } else { if (string.IsNullOrEmpty(roleName)) { MySqlSimpleMembershipProvider.NullArgumentException("roleName"); } using (MySqlDatabaseWrapper dbConn = new MySqlDatabaseWrapper(ConnectionString)) { int roleid = GetRoleId(roleName); if (roleid != 0) { throw new InvalidOperationException(string.Format(Resources.RoleAlreadyExists, roleName)); } if (dbConn.ExecuteNonQuery(string.Format("insert into {0} (rolename) values(?);", _rolesTable), roleName) <= 0) { throw new ProviderException(string.Format(Resources.CreateRoleFailed, roleName)); } } } }