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("~/"); } }
public RecipesController(IMasterChefData data, IUserIdProvider userIdProvider, IImageUploadProvider imageUploadProvider, INotificationProvider notificationProvider) : base(data, userIdProvider) { this.imageUploadProvider = imageUploadProvider; this.notificationProvider = notificationProvider; }
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(object sender, EventArgs e) { var dbContext = new MasterChefDbContext(); this.data = new MasterChefData(dbContext); string userId = this.User.Identity.GetUserId(); AppUser user = data.Users.All().Single(x => x.Id == userId); this.details.DataSource = new List<AppUser>() { user }; this.details.DataBind(); }
protected void Page_Load(object sender, EventArgs e) { var dbContext = new MasterChefDbContext(); data = new MasterChefData(dbContext); if (!IsPostBack) { LoadData(); } }
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 InMemoryHttpServer(string baseUrl, IMasterChefData data) { this.baseUrl = baseUrl; var config = new HttpConfiguration(); this.AddHttpRoutes(config.Routes); config.IncludeErrorDetailPolicy = IncludeErrorDetailPolicy.Always; var resolver = new TestBugsDependencyResolver(); resolver.Data = data; config.DependencyResolver = resolver; var server = new HttpServer(config); this.client = new HttpClient(server); }
protected void Page_Load(object sender, EventArgs e) { var dbContext = new MasterChefDbContext(); this.data = new MasterChefData(dbContext); string userId = this.User.Identity.GetUserId(); AppUser user = data.Users.All().Single(x => x.Id == userId); this.details.DataSource = new List <AppUser>() { user }; this.details.DataBind(); }
protected void Page_Load(object sender, EventArgs e) { var currentUserId = Request.QueryString["Id"]; var dbContext = new MasterChefDbContext(); this.data = new MasterChefData(dbContext); if (Context.User.Identity.IsAuthenticated) { AdminPanelMenu.Visible = false; CreateArticlePrivateAdminItemMenu.Visible = false; var user = this.data.Users .All() .Where(u => u.UserName == this.Context.User.Identity.Name) .FirstOrDefault(); var adminRole = this.data.Roles .All() .Where(r => r.Name == "admin") .FirstOrDefault(); if (user.Roles.Any(r => r.RoleId == adminRole.Id)) { AdminPanelMenu.Visible = true; CreateArticlePrivateAdminItemMenu.Visible = true; } (LoginView.FindControl("ProfileImage") as Image).ImageUrl = user.Image.Path; // TODO: cache data using this.Cache -> sitemaster } else { AddRecipePrivateItemMenu.Visible = false; FavouriteArticlesPrivateItemMenu.Visible = false; MyRecipesPrivateItemMenu.Visible = false; AdminPanelMenu.Visible = false; CreateArticlePrivateAdminItemMenu.Visible = false; } }
protected BaseApiController(IMasterChefData data, IUserIdProvider userIdProvider) { this.data = data; this.userIdProvider = userIdProvider; }
public UserActionsController(IMasterChefData data, IUserIdProvider userIdProvider) : base(data, userIdProvider) { }
public CategoriesController(IMasterChefData data, IUserIdProvider userIdProvider) : base(data, userIdProvider) { }
public RecipesController(IMasterChefData data, IUserIdProvider userIdProvider, IDropboxImageUploader imageUploadProvider) : base(data, userIdProvider) { this.imageUploadProvider = imageUploadProvider; }