//private string GetConnectionString() //{ // if (!string.IsNullOrEmpty(ConnectionString)) // return ConnectionString; // else // { // ConnectionStringSettings connString = ConfigurationManager.ConnectionStrings[ConnectionStringName]; // if (connString != null) // return connString.ConnectionString; // } // if (!string.IsNullOrEmpty(_connString)) // return _connString; // throw new InvalidOperationException(Resources.NoConnString); //} private IEnumerable <int> GetUsersId(string[] usersName) { foreach (string userName in usersName) { yield return(MySqlSimpleMembershipProvider.GetUserId(userName, ConnectionString, UserTableName, UserIdColumn, UserNameColumn)); } }
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[] 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); }
private List <int> GetUserIdsFromNames(MySqlSecurityDbContext db, string[] usernames) { List <int> userIds = new List <int>(usernames.Length); foreach (string username in usernames) { int id = MySqlSimpleMembershipProvider.GetUserId(db, username); if (id == -1) { throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, Resources.Security_NoUserFound, username)); } userIds.Add(id); } return(userIds); }
/// <summary> /// Gets a list of the roles that a specified user is in for the configured applicationName. /// </summary> /// <remarks>Inherited from RoleProvider ==> Forwarded to previous provider if this provider hasn't been initialized</remarks> /// <param name="username">The user to return a list of roles for.</param> /// <returns>A string array containing the names of all the roles that the specified user is in for the configured applicationName.</returns> /// <exception cref="System.InvalidOperationException"></exception> public override string[] GetRolesForUser(string username) { if (!InitializeCalled) { return(PreviousProvider.GetRolesForUser(username)); } using (var db = NewMySqlSecurityDbContext) { int userId = MySqlSimpleMembershipProvider.GetUserId(db, username); if (userId == -1) { throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, Resources.Security_NoUserFound, username)); } var roleNames = db.UsersInRoles.Where(x => x.UserId == userId) .Select(x => x.Role.RoleName) .ToArray(); return(roleNames); } }