using System; using System.Data; using System.Data.SqlClient; // ******* using System.Configuration; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; /// /// Summary description for Rollihaldur /// public class Rollihaldur : RoleProvider { public override void AddUsersToRoles(string[] usernames, string[] roleNames) { throw new Exception("The method or operation is not implemented."); } public override string ApplicationName { get { throw new Exception("The method or operation is not implemented."); } set { throw new Exception("The method or operation is not implemented."); } } public override void CreateRole(string roleName) { throw new Exception("The method or operation is not implemented."); } public override bool DeleteRole(string roleName, bool throwOnPopulatedRole) { throw new Exception("The method or operation is not implemented."); } public override string[] FindUsersInRole(string roleName, string usernameToMatch) { throw new Exception("The method or operation is not implemented."); } public override string[] GetAllRoles() { return new string[] { "ADMIN", "MYYJA" }; } public override string[] GetRolesForUser(string username) { SqlConnection conn = new SqlConnection( ConfigurationManager.ConnectionStrings["yhendusTekst"].ConnectionString); SqlCommand cmd = new SqlCommand( "SELECT OnMyya, OnAdmin FROM Kasutaja_tbl " + "WHERE KasutajaNimi = @nimi", conn); cmd.Parameters.AddWithValue("@nimi", username); string rollid = ""; conn.Open(); SqlDataReader lugeja = cmd.ExecuteReader(CommandBehavior.CloseConnection); if (lugeja.HasRows) { lugeja.Read(); bool onMyyja = lugeja.GetBoolean(0); bool onAdmin = lugeja.GetBoolean(1); if (onAdmin) rollid += "ADMIN,"; if (onMyyja) rollid += "MYYJA"; } return rollid.Split(new char[] {','}, StringSplitOptions.RemoveEmptyEntries); } public override string[] GetUsersInRole(string roleName) { throw new Exception("The method or operation is not implemented."); } public override bool IsUserInRole(string username, string roleName) { string[] rollid = GetRolesForUser(username); roleName = roleName.ToUpper(); for (int i = 0; i < rollid.Length; i++) { if (rollid[i] == roleName) return true; } return false; } public override void RemoveUsersFromRoles(string[] usernames, string[] roleNames) { throw new Exception("The method or operation is not implemented."); } public override bool RoleExists(string roleName) { roleName = roleName.ToUpper(); return roleName == "ADMIN" || roleName == "MYYJA"; } }