public void ShowComponents(IUserCtx user) { var roles = user.GetAllRoles(); foreach (var role in roles) { switch (role) { case "admin": listBox1.Enabled = true; checkedListBox1.Enabled = true; checkedListBox2.Enabled = true; dodajGrupęToolStripMenuItem.Enabled = true; dodajNoweUprawnienieToolStripMenuItem.Enabled = true; dodajUżytkownikaToolStripMenuItem.Enabled = true; zobaczListęToolStripMenuItem1.Enabled = true; button1.Enabled = true; button2.Enabled = true; button3.Enabled = true; button4.Enabled = true; button5.Enabled = true; break; } } }
public static bool Login( String uname , String pass , out IUserCtx uc) { String[] roles; uc = null; // autentykacja (tu następuje sprawdzenie z tablicą user/pass z Bazy Danych) if (uname == "Rafal") { // autoryzacja (tu następuje pobranie z Bazy Danych wszystkich ról do których user należy) roles = new String[] { BizzLogic.Operation1Role, BizzLogic.Operation2Role }; } else if (uname == "Atylla") { roles = new String[] { BizzLogic.Operation2Role }; } else { return false; } UserCtx ucl = new UserCtx(uname); foreach (String s in roles) ucl.AddOperRole(s); uc = ucl; GenericIdentity gi = new GenericIdentity(uname); GenericPrincipal gp = new GenericPrincipal(gi, roles); // przypisanie kontekstu (żeby działał mechanizm) Thread.CurrentPrincipal = gp; return true; }
public void ShowComponenets(IUserCtx user) { var roles = user.GetAllRoles(); foreach (var role in roles) { switch (role) { case "AddProduct": button3.Enabled = true; break; case "UpdateProduct": button4.Enabled = true; break; case "DeleteProduct": button5.Enabled = true; break; case "GetAllProducts": listBox1.Enabled = true; break; case "UpdatePallet": button2.Enabled = true; break; } } }
public void ShowComponents(IUserCtx user) { var roles = user.GetAllRoles(); foreach (var role in roles) { switch (role) { case "AddOrder": dodajZamówienieToolStripMenuItem.Enabled = true; break; case "AddCategory": dodajKategorięProduktówToolStripMenuItem.Enabled = true; break; case "UpdateOrder": button1.Enabled = true; break; case "DeleteOrder": button3.Enabled = true; break; case "GetAllOrders": // wyświelListęToolStripMenuItem.Enabled = true; listBox1.Enabled = true; listBox2.Enabled = true; break; } } }
public static void Logout(ref IUserCtx uc) { // IPrincipal gp ; //gp = Thread.CurrentPrincipal; uc = null; Thread.CurrentPrincipal = null; //IIdentity id = gp.Identity; //id = null; //gp = null; }
/// <summary> /// /// </summary> /// <param name="uc"></param> public static void Logout(ref IUserCtx uc) { // IPrincipal gp ; //gp = Thread.CurrentPrincipal; uc = null; Thread.CurrentPrincipal = null; //IIdentity id = gp.Identity; //id = null; //gp = null; }
/// <summary> /// /// </summary> /// <param name="uname">login</param> /// <param name="pass">password</param> /// <param name="uc">User Context</param> /// <exception cref="SqlException">When error with database occurs</exception> /// <returns>If user exists returns true</returns> public static bool Login(String login, String pass, out IUserCtx uc) { uc = null; try { string lol = ConfigurationManager.ConnectionStrings["AdminDatabase"].ConnectionString; var db = new SQLtoLinqDataContext(ConfigurationManager.ConnectionStrings["AdminDatabase"].ConnectionString); pass = UserCtx.Encrypt(pass); var result = (from p in db.Users where p.login == login && p.password == pass select new UserResult { user_ID = p.user_ID, name = p.name, surname = p.surname, login = p.login }).SingleOrDefault(); if (result == null) { return(false); } var roles = (from o in db.operations from u2o in db.users2operations from u in db.Users where o.operation_ID == u2o.operation_ID && u.user_ID == u2o.user_ID && u.user_ID == result.user_ID select o.name) .Union (from o in db.operations from g2o in db.groups2operations from u2g in db.users2groups from u in db.Users from g in db.groups where u.user_ID == u2g.user_ID && g.group_ID == u2g.group_ID && g.group_ID == g2o.group_ID && o.operation_ID == g2o.operation_ID && u.user_ID == result.user_ID select o.name).ToList <string>(); uc = new UserCtx(login, roles); GenericIdentity gi = new GenericIdentity(login); GenericPrincipal gp = new GenericPrincipal(gi, roles.ToArray()); Thread.CurrentPrincipal = gp; } catch (Exception ex) { throw ex; } return(true); }
public Order(IUserCtx user, string switchiIn, string orderIDIn, string senderIn, string recieverIn, DateTime dateSentIn, DateTime dateRecievedIn, string state) { switchi = switchiIn; try { switch (switchi) { case "new": orderID = orderIDIn; sender = senderIn; reciever = recieverIn; dateSent = dateSentIn; dateRecieved = dateRecievedIn; InitializeComponent(); InitialHideComponents(); ShowComponents(user); this.comboBox1.SelectedIndex = comboBox1.Items.IndexOf(state); break; case "exists": InitializeComponent(); InitialHideComponents(); ShowComponents(user); orderID = orderIDIn; this.textBox1.Text = senderIn; sender = senderIn; this.textBox2.Text = recieverIn; reciever = recieverIn; this.dateTimePicker1.Value = dateSentIn; dateSent = dateSentIn; this.dateTimePicker2.Value = dateRecievedIn; dateRecieved = dateRecievedIn; this.comboBox1.SelectedIndex = comboBox1.Items.IndexOf(state); var palletslist = Warehouse.Logic.Warehouse.GetAllPallets(orderID); foreach (PalletResult pallet in palletslist) { listBox1.Items.Add(pallet.kod_palety); } ; if (listBox1.Items.Count != 0) { listBox1.SelectedIndex = 0; this.listBox2.Items.Clear(); var palletProducts = Warehouse.Logic.Warehouse.GetAllProducts(this.listBox1.SelectedItem.ToString()); foreach (ProductResult product in palletProducts) { this.listBox2.Items.Add(product.nazwa); } } break; } } catch (System.Security.SecurityException se) { MessageBox.Show("Permission denied " + se.Message); } catch (Exception se) { MessageBox.Show(se.Message); } }