public BaseAdminPage() { dbContext = new MasterChefDbContext(); data = new MasterChefData(dbContext); bool isAuthenticated = this.User.Identity.IsAuthenticated; if (isAuthenticated) { var user = data.Users.All() .Single(x => x.UserName == this.Context.User.Identity.Name); var adminRole = data.Roles.All() .Single(x => x.Name == "admin"); bool isAdmin = user.Roles.Any(role => role.RoleId == adminRole.Id); if (!isAdmin) { HttpContext.Current.Response.Redirect("~/Error/403"); } } else { Response.Redirect("~/"); } }
protected void Page_Load() { dbContext = new MasterChefDbContext(); data = new MasterChefData(dbContext); string userId = this.User.Identity.GetUserId(); AppUser currentUser = data.Users.All().Single(x => x.Id == userId); this.userDetails.DataSource = new List <AppUser>() { currentUser }; this.userDetails.DataBind(); var manager = Context.GetOwinContext().GetUserManager <ApplicationUserManager>(); HasPhoneNumber = String.IsNullOrEmpty(manager.GetPhoneNumber(User.Identity.GetUserId())); // Enable this after setting up two-factor authentientication //PhoneNumber.Text = manager.GetPhoneNumber(User.Identity.GetUserId()) ?? String.Empty; TwoFactorEnabled = manager.GetTwoFactorEnabled(User.Identity.GetUserId()); LoginsCount = manager.GetLogins(User.Identity.GetUserId()).Count; var authenticationManager = HttpContext.Current.GetOwinContext().Authentication; if (!IsPostBack) { // Determine the sections to render if (HasPassword(manager)) { ChangePassword.Visible = true; } else { CreatePassword.Visible = true; ChangePassword.Visible = false; } // Render success message var message = Request.QueryString["m"]; if (message != null) { // Strip the query string from action Form.Action = ResolveUrl("~/Account/Manage"); SuccessMessage = message == "ChangePwdSuccess" ? "Your password has been changed." : message == "SetPwdSuccess" ? "Your password has been set." : message == "RemoveLoginSuccess" ? "The account was removed." : message == "AddPhoneNumberSuccess" ? "Phone number has been added" : message == "RemovePhoneNumberSuccess" ? "Phone number was removed" : String.Empty; successMessage.Visible = !String.IsNullOrEmpty(SuccessMessage); } } }
public BaseAuthorizationPage() { this.dbContext = new MasterChefDbContext(); this.data = new MasterChefData(dbContext); if (!HttpContext.Current.User.Identity.IsAuthenticated) { HttpContext.Current.Response.Redirect("~/Account/Login"); } }
protected void Page_Load() { dbContext = new MasterChefDbContext(); data = new MasterChefData(dbContext); string userId = this.User.Identity.GetUserId(); AppUser currentUser = data.Users.All().Single(x => x.Id == userId); this.userDetails.DataSource = new List<AppUser>() { currentUser }; this.userDetails.DataBind(); var manager = Context.GetOwinContext().GetUserManager<ApplicationUserManager>(); HasPhoneNumber = String.IsNullOrEmpty(manager.GetPhoneNumber(User.Identity.GetUserId())); // Enable this after setting up two-factor authentientication //PhoneNumber.Text = manager.GetPhoneNumber(User.Identity.GetUserId()) ?? String.Empty; TwoFactorEnabled = manager.GetTwoFactorEnabled(User.Identity.GetUserId()); LoginsCount = manager.GetLogins(User.Identity.GetUserId()).Count; var authenticationManager = HttpContext.Current.GetOwinContext().Authentication; if (!IsPostBack) { // Determine the sections to render if (HasPassword(manager)) { ChangePassword.Visible = true; } else { CreatePassword.Visible = true; ChangePassword.Visible = false; } // Render success message var message = Request.QueryString["m"]; if (message != null) { // Strip the query string from action Form.Action = ResolveUrl("~/Account/Manage"); SuccessMessage = message == "ChangePwdSuccess" ? "Your password has been changed." : message == "SetPwdSuccess" ? "Your password has been set." : message == "RemoveLoginSuccess" ? "The account was removed." : message == "AddPhoneNumberSuccess" ? "Phone number has been added" : message == "RemovePhoneNumberSuccess" ? "Phone number was removed" : String.Empty; successMessage.Visible = !String.IsNullOrEmpty(SuccessMessage); } } }
public MasterChefData(IMasterChefDbContext context) { this.context = context; this.repositories = new Dictionary <Type, object>(); }