public IEnumerable <AllowedAction> GetAllowedActions() { List <AllowedAction> allowedActions = new List <AllowedAction>(); allowedActions.Add(new AllowedAction("Templates", "Templates", "Home")); if (this._identity.IsAuthenticated) { allowedActions.Add(new AllowedAction("Create your pizza", "PizzaConstructor", "Home")); allowedActions.Add(new AllowedAction("Your pizzas", "OrdersHistory", "Home")); string userId = this._identity.GetUserId(); AdminSection adminSection = (AdminSection)WebConfigurationManager.GetSection("adminSection"); AdminsCollection adminsCollection = adminSection.AdminEmails; for (int i = 0; i < adminsCollection.Count; i++) { if (adminsCollection[i].Email == userId) { allowedActions.Add(new AllowedAction("Admin panel", "Index", "AdminPage")); break; } } } return(allowedActions); }
public void Configuration(IAppBuilder app) { // Register UserManager for OWIN app.CreatePerOwinContext <IdentityUserManager>(IdentityUserManager.Create); // Use cookies for authentication and authorization // LoginPath - path to redirect unauthenticated user app.UseCookieAuthentication(new Microsoft.Owin.Security.Cookies.CookieAuthenticationOptions { AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie, LoginPath = new PathString("/Account/Login") }); // Receive settings about google application GoogleSection section = (GoogleSection)WebConfigurationManager.GetSection("googleSection"); GoogleElement elem = section.GoogleElement; AdminSection adminSection = (AdminSection)WebConfigurationManager.GetSection("adminSection"); AdminsCollection adminsCollection = adminSection.AdminEmails; for (int i = 0; i < adminsCollection.Count; i++) { var uuu = adminsCollection[i]; } // Use external cookies app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie); // Google authentication app.UseGoogleAuthentication(new GoogleOAuth2AuthenticationOptions() { ClientId = elem.ClientId, ClientSecret = elem.ClientSecret, CallbackPath = new PathString("/Account/LoginCallback/") }); }
private void New_user_button_Click(object sender, EventArgs e) { // this.Hide(); Add_Mod_user_window nw = new Add_Mod_user_window(0); nw.ShowDialog(); Users_DataGridviev.DataSource = (from p in AdminSection.Find_user(Uname_text_box.Text, Lname_text_box.Text, Fname_text_box.Text) select new { Last_Name = p.lname, First_Name = p.fname, User_Name = p.uname, Rola = p.role, Data_wygaśnięcia = p.dt_exp }); }
public ActionResult Delete(int id) { using (DBModel db = new DBModel()) { AdminSection admin = db.AdminSections.Where(x => x.AdminSectionId == id).FirstOrDefault <AdminSection>(); db.AdminSections.Remove(admin); db.SaveChanges(); return(Json(new { success = true, message = "Deleted Successfuly" }, JsonRequestBehavior.AllowGet)); } }
private void Mod_User_Button_Click(object sender, EventArgs e) { try { int numer = Convert.ToInt32(Users_DataGridviev.CurrentRow.Index); string zmienna = Users_DataGridviev.Rows[numer].Cells[2].Value.ToString(); Add_Mod_user_window nw = new Add_Mod_user_window(1, zmienna); nw.ShowDialog(); } catch { MessageBox.Show("Proszę wybrać użytkownika"); } Users_DataGridviev.DataSource = (from p in AdminSection.Find_user(Uname_text_box.Text, Lname_text_box.Text, Fname_text_box.Text) select new { Last_Name = p.lname, First_Name = p.fname, User_Name = p.uname, Rola = p.role, Data_wygaśnięcia = p.dt_exp }); }
public ActionResult AddOrEditAdminSection(AdminSection admin) { using (DBModel db = new DBModel()) { if (admin.AdminSectionId == 0) { db.AdminSections.Add(admin); db.SaveChanges(); //return Json(new { success = true, message = "Saved Successfully" }, JsonRequestBehavior.AllowGet); return(View("IndexAdminSection")); } else { db.Entry(admin).State = EntityState.Modified; db.SaveChanges(); //return Json(new { success = true, message = "Updated Successfully" }, JsonRequestBehavior.AllowGet); return(View("IndexAdminSection")); } } }
protected override bool AuthorizeCore(HttpContextBase httpContext) { bool allow = false; AdminSection adminSection = (AdminSection)WebConfigurationManager.GetSection("adminSection"); AdminsCollection adminsCollection = adminSection.AdminEmails; for (int i = 0; i < adminsCollection.Count; i++) { if (httpContext.User.Identity.GetUserId() == adminsCollection[i].Email) { return(allow = true); } else { allow = false; } } return(allow); //return httpContext.Request.IsLocal || base.AuthorizeCore(httpContext); }
private void Add_Mod_user_window_Load(object sender, EventArgs e) { Pass1_text_box.PasswordChar = Pass_text_box.PasswordChar = '*'; if (choice == 0) { Add_Mod_user_button.Text = "Dodaj"; Open_label.Text = "Dodaj nowego użytkownika:"; Help_Box.Text = "Wartość domyślna daty wygaśnięcia konta jest równoważna z jej brakiem"; } else if (choice == 1) { Add_Mod_user_button.Text = "Zapisz"; var sz_zap = AdminSection.Find_user(UnameGG); Lname_text_box.Text = (sz_zap.Where(p => p.uname == UnameGG).Select(p => p.lname)).Single(); Fname_text_box.Text = (sz_zap.Where(p => p.uname == UnameGG).Select(p => p.fname)).Single(); Role_Combo_Box.Text = (sz_zap.Where(p => p.uname == UnameGG).Select(p => p.role)).Single(); Pass_text_box.Text = Pass1_text_box.Text = "nowe haslo"; string wzor = "dd.MM.yyyy"; string data_z_bazy = "01.01.2000";//ustawia jesli w bazie jest null Open_label.Text = "Modyfikuj użytkownika: " + (sz_zap.Where(p => p.uname == UnameGG).Select(p => p.uname)).Single();; Help_Box.Text = "Należy wprowadzić tylko wartości wymagające modyfikacji"; DateTime pomo_date; if ((sz_zap.Where(p => p.uname == UnameGG).Select(p => p.dt_exp)).Single() != null) { data_z_bazy = (sz_zap.Where(p => p.uname == UnameGG).Select(p => p.dt_exp)).Single().Value.ToString(wzor); pomo_date = (sz_zap.Where(p => p.uname == UnameGG).Select(p => p.dt_exp)).Single().Value; } else { pomo_date = DateTime.ParseExact(data_z_bazy, wzor, null); } Dt_exp_picker.Value = pomo_date; } }
private void Add_Mod_user_button_Click(object sender, EventArgs e) { DialogResult result1 = MessageBox.Show("Na pewno chcesz zapisać tego użytkownika?", "Potwierdzenie", MessageBoxButtons.YesNo); if (result1 == DialogResult.Yes) { Lname_label.ForeColor = Fname_label.ForeColor = Pass_label.ForeColor = Role_label.ForeColor = Pass1_label.ForeColor = Color.Black; if (Lname_text_box.Text == "" || Fname_text_box.Text == "" || Pass_text_box.Text == "" || Pass1_text_box.Text == "" || Role_Combo_Box.Text == "") { MessageBox.Show("Pozostawiono puste pola"); if (Lname_text_box.Text == "") { Lname_label.ForeColor = Color.Red; } if (Fname_text_box.Text == "") { Fname_label.ForeColor = Color.Red; } if (Pass_text_box.Text == "") { Pass_label.ForeColor = Color.Red; } if (Pass1_text_box.Text == "") { Pass1_label.ForeColor = Color.Red; } if (Role_Combo_Box.Text == "") { Role_label.ForeColor = Color.Red; } } else if (Pass1_text_box.Text != Pass_text_box.Text) { MessageBox.Show("Podane hasła różnią się."); Pass_label.ForeColor = Color.Red; Pass1_label.ForeColor = Color.Red; } else { if (Add_Mod_user_button.Text == "Dodaj") { DateTime data = Dt_exp_picker.Value; string zwrot = AdminSection.Create_Personel(Lname_text_box.Text, Fname_text_box.Text, Role_Combo_Box.Text, Pass_text_box.Text, data); if (zwrot == "Pomyslnie dodano do BD. ") { DialogResult result = MessageBox.Show(zwrot + "Chcesz dodać następnego uzytkownika?", "Potwierdzenie", MessageBoxButtons.YesNo); if (result == DialogResult.Yes) { Lname_text_box.Clear(); Fname_text_box.Clear(); Pass_text_box.Clear(); Pass1_text_box.Clear(); Haslo_checkbox.Checked = false; } else if (result == DialogResult.No) { this.Close(); } } else { MessageBox.Show(zwrot); } } else if (Add_Mod_user_button.Text == "Zapisz") { DateTime data = Dt_exp_picker.Value; AdminSection.Modify_Personel(UnameGG, Lname_text_box.Text, Fname_text_box.Text, Role_Combo_Box.Text, Pass_text_box.Text, data); this.Close(); } } } }
private void Find_user_button_Click(object sender, EventArgs e) { Users_DataGridviev.DataSource = (from p in AdminSection.Find_user(Uname_text_box.Text, Lname_text_box.Text, Fname_text_box.Text) select new { Last_Name = p.lname, First_Name = p.fname, User_Name = p.uname, Rola = p.role, Data_wygaśnięcia = p.dt_exp }); }