public NancyDemoModule(IResourceLinker linker) { Get["HelloWorldRoute", "/nancy/demo/{MyQueryParameter:string}"] = parameters => new[] {"Hello", "World", (string) parameters.MyQueryParameter}; Get["FindHelloWorld", "/nancy/findhelloworld"] = parameters => new[] { linker.BuildAbsoluteUri(Context, "HelloWorldRoute", new {MyQueryParameter = "CodeOpinion"}) }; Get["GzipTest", "/nancy/gziptest"] = parameters => { return new Response { ContentType = "application/json", StatusCode = HttpStatusCode.OK, Contents = stream => { var resourceStream = Assembly.GetExecutingAssembly().GetManifestResourceStream("AspNet5Nancy.fakedata.json"); using (var reader = new StreamReader(resourceStream, Encoding.UTF8)) { var content = Encoding.UTF8.GetBytes(reader.ReadToEnd()); stream.Write(content, 0, content.Length); } } }; }; }
public SecurityExtensions(IUserRepository userRepository, IResourceLinker linker, IPlexUserRepository plexUsers, ISettingsService <UserManagementSettings> umSettings) { UserRepository = userRepository; Linker = linker; PlexUsers = plexUsers; UserManagementSettings = umSettings; }
public UserLoginModule(ISettingsService <AuthenticationSettings> auth, IPlexApi api, ISettingsService <PlexSettings> plexSettings, ISettingsService <PlexRequestSettings> pr, ISettingsService <LandingPageSettings> lp, IAnalytics a, IResourceLinker linker) : base("userlogin", pr) { AuthService = auth; LandingPageSettings = lp; Analytics = a; Api = api; PlexSettings = plexSettings; Linker = linker; Get["UserLoginIndex", "/", true] = async(x, ct) => { if (!string.IsNullOrEmpty(Username) || IsAdmin) { var uri = Linker.BuildRelativeUri(Context, "SearchIndex"); return(Response.AsRedirect(uri.ToString())); } var settings = await AuthService.GetSettingsAsync(); return(View["Index", settings]); }; Post["/", true] = async(x, ct) => await LoginUser(); Get["/logout"] = x => Logout(); }
public LandingPageModule(ISettingsService <PlexRequestSettings> settingsService, ISettingsService <LandingPageSettings> landing, ISettingsService <PlexSettings> ps, IPlexApi pApi, IResourceLinker linker, ISecurityExtensions security) : base("landing", settingsService, security) { LandingSettings = landing; PlexSettings = ps; PlexApi = pApi; Linker = linker; Get["LandingPageIndex", "/", true] = async(x, ct) => { var s = await LandingSettings.GetSettingsAsync(); if (!s.BeforeLogin && string.IsNullOrEmpty(Username)) //We are signed in { var url = Linker.BuildRelativeUri(Context, "SearchIndex").ToString(); return(Response.AsRedirect(url)); } var model = new LandingPageViewModel { Enabled = s.Enabled, Id = s.Id, EnabledNoticeTime = s.EnabledNoticeTime, NoticeEnable = s.NoticeEnable, NoticeEnd = s.NoticeEnd, NoticeMessage = s.NoticeMessage, NoticeStart = s.NoticeStart, ContinueUrl = s.BeforeLogin ? $"userlogin" : $"search" }; return(View["Landing/Index", model]); }; Get["/status", true] = async(x, ct) => await CheckStatus(); }
public NancyDemoModule(IResourceLinker linker) { Get["HelloWorldRoute", "/nancy/demo/{MyQueryParameter:string}"] = parameters => new[] { "Hello", "World", (string)parameters.MyQueryParameter }; Get["FindHelloWorld", "/nancy/findhelloworld"] = parameters => new[] { linker.BuildAbsoluteUri(Context, "HelloWorldRoute", new { MyQueryParameter = "CodeOpinion" }) }; Get["GzipTest", "/nancy/gziptest"] = parameters => { return(new Response { ContentType = "application/json", StatusCode = HttpStatusCode.OK, Contents = stream => { var resourceStream = Assembly.GetExecutingAssembly().GetManifestResourceStream("AspNet5Nancy.fakedata.json"); using (var reader = new StreamReader(resourceStream, Encoding.UTF8)) { var content = Encoding.UTF8.GetBytes(reader.ReadToEnd()); stream.Write(content, 0, content.Length); } } }); }; }
public AuthModule(IAppDbContext dbCtx, IResourceLinker linker) : base(dbCtx, linker) { var encoder = new SaltRawSaltPasswordEncoder(); Get[RouteNames.GetLogin, "/auth/login"] = arg => { AppModel.PageTitle = "Login"; return(View["login", new { linker }]); }; Get[RouteNames.GetLogout, "/auth/logout"] = arg => { var rootPath = linker.BuildRelativeUri(Context, RouteNames.GetRoot).ToString(); return(this.LogoutAndRedirect(rootPath)); }; Post[RouteNames.PostLogin, "/auth/login"] = parameters => { var loginParams = this.Bind <AuthModel>(); var member = dbCtx.Users.FirstOrDefault(x => x.UserName == loginParams.Username); if (member == null || !encoder.IsPasswordValid(member.PassHash, loginParams.Password, member.PassSalt)) { return("username and/or password was incorrect"); } var expiry = loginParams.RememberMe ? DateTime.MaxValue : DateTime.Now.AddDays(14); var rootPath = linker.BuildRelativeUri(Context, RouteNames.GetRoot).ToString(); return(this.LoginAndRedirect(member.Uuid, expiry, rootPath)); }; }
public IndexModule(ISettingsService <PlexRequestSettings> pr, ISettingsService <LandingPageSettings> l, IResourceLinker rl, ISecurityExtensions security) : base(pr, security) { LandingPage = l; Linker = rl; Get["Index", "/", true] = async(x, ct) => await Index(); Get["/Index", true] = async(x, ct) => await Index(); }
public SecurityExtensions(IUserRepository userRepository, IResourceLinker linker, IExternalUserRepository <PlexUsers> plexUsers, ISettingsService <UserManagementSettings> umSettings, IExternalUserRepository <EmbyUsers> embyUsers) { UserRepository = userRepository; Linker = linker; PlexUsers = plexUsers; UserManagementSettings = umSettings; EmbyUsers = embyUsers; }
public IndexModule(IResourceLinker linker) { Get["home", "/"] = parameters => Response.AsJson(new { serverTime = DateTime.UtcNow.ToString(@"yyyy-MM-ddTHH\:mm\:ss"), apiName = "xxxx", version = "v0.2", hone = linker.BuildAbsoluteUri(Context, "home") }); }
public TestModule(IResourceLinker linker) { TestModule.linker = linker; this.Get["foo", "/foo"] = _ => 200; this.Get["bar", "/bar/{id}"] = _ => 200; this.Get["no segments", "/"] = _ => 200; this.Get["constraint", "/intConstraint/{id: int}"] = _ => 200; this.Get["regex", @"/regex/(?<id>[\d]{ 1,7})"] = _ => 200; this.Get["optional", "optional/{id?}"] = _ => 200; this.Get["default", "default/{id?123}"] = _ => 200; }
public HomeModule(IAppDbContext dbCtx, IResourceLinker linker) : base(dbCtx, linker) { Get[RouteNames.GetHome, "/home"] = parameters => { AppModel.PageTitle = "Home Page"; var user = (User)Context.CurrentUser; var model = new HomeModel { UserId = user.Id, UserName = user.UserName }; return(View["index", model]); }; }
public TvStationsModule(ITvStations tvStations, IResourceLinker resourceLinker) : base("tvstations") { this.resourceLinker = resourceLinker; this.Get["/", true] = async(o, token) => { TvStation[] stations = await tvStations.GetAllAsync(); List <ApiTvStation> apiTvStations = stations.Select(station => this.MapStation(station)).ToList(); TvStation selectedStation = TvControlViewModel.Current.SelectedStation; return(new { Stations = apiTvStations, Selected = selectedStation == null ? null : this.MapStation(selectedStation), TvControlViewModel.Current.SelectedIndex }); }; this.Post["/{id}"] = o => { TvControlViewModel tvControlViewModel = TvControlViewModel.Current; if (!tvControlViewModel.SetCurrentStation(o.id)) { return(InvalidStationIdResponse(o.id)); } return(HttpStatusCode.Accepted); }; this.Post["/toggleInfo"] = o => { TvControlViewModel.Current.ToggleInfoCommand.Execute(); return(HttpStatusCode.Accepted); }; this.Get["StationImageRoute", "/image/{id}"] = o => { dynamic id = o.id; TvStation station = TvControlViewModel.Current.TvStations.FirstOrDefault(s => s.Id == id); var encoder = new PngBitmapEncoder(); if (station == null) { return(InvalidStationIdResponse(o.id)); } var stationImage = (BitmapSource)station.Image; encoder.Frames.Add(BitmapFrame.Create(stationImage)); var stream = new MemoryStream(); encoder.Save(stream); byte[] bitmapdata = stream.ToArray(); return(new ByteArrayResponse(bitmapdata, "image/png")); }; }
public LoginModule(IResourceLinker linker, LoginSL loginSl) { Post["/CreateAccount"] = param => { WebUserData data = this.Bind <WebUserData>(); LoginViewModel loginViewModel = new LoginViewModel(); if (loginSl.IsAccountNameRegistered(data.UserName)) { loginViewModel.HasError = true; loginViewModel.ErrorMessage = "Account name is already in use."; return(View["Views/Login.sshtml", loginViewModel]); } loginSl.CreateNewAccount(data); return(View["Views/Login.sshtml", loginViewModel]); }; Post["/Login"] = param => { LoginViewModel loginViewModel = new LoginViewModel(); WebUserData data = this.Bind <WebUserData>(); if (!loginSl.IsAccountNameRegistered(data.UserName)) { loginViewModel.HasError = true; loginViewModel.ErrorMessage = "You have specified an incorrect or inactive username, or an invalid password."; return(View["Views/Login.sshtml", loginViewModel]); } if (!loginSl.IsUserAdmin(data.UserName)) { loginViewModel.HasError = true; loginViewModel.ErrorMessage = "You need to be an admin to access this page."; return(View["Views/Login.sshtml", loginViewModel]); } data.Claims = new List <string> { "Admin" }; Guid guid = Guid.NewGuid(); if (!loginSl.LoginWithCredentials(data, guid)) { loginViewModel.HasError = true; loginViewModel.ErrorMessage = "You have specified an incorrect or inactive username, or an invalid password."; return(View["Views/Login.sshtml", loginViewModel]); } DateTime expiry = DateTime.Now; expiry = data.Remember ? expiry.AddDays(7) : expiry.AddHours(1); return(this.LoginAndRedirect(guid, expiry, "/Admin")); }; }
protected override void Initialize(System.Web.Http.Controllers.HttpControllerContext controllerContext) { base.Initialize(controllerContext); var url = controllerContext.Request.RequestUri; var baseUri = new UriBuilder( url.Scheme, url.Host, url.Port).Uri; _resourceLinker = new RouteLinker(baseUri, this); }
//Constructor public ApplicationModule(IAppDbContext dbCtx, IResourceLinker linker) { //All pages on the site should be viewed through HTTPS //IIS Express puts HTTPS on 44300 this.RequiresHttps(true, AppModel.IsTest ? 44300 : 443); //Populate injected interfaces. _db = dbCtx; _linker = linker; //Setup filters Before += AddSiteConfiguration; After += AssignAppModelToViewBag; }
public RootModule(IAppDbContext context, IResourceLinker linker) : base(context, linker) { //Redirect the root to the home page route Get[RouteNames.GetRoot, "/"] = parameters => { if (Context.CurrentUser != null) { return(new RedirectResponse( linker.BuildRelativeUri(Context, RouteNames.GetHome) .ToString())); } //Otherwise, show the logged out version return(View["index", new { linker }]); }; }
/// <summary> /// Initializes a new instance of the <see cref="T:System.Web.Mvc.Controller"/> class. /// </summary> public OrderController(IRepository<Order> a_orderRepository, IDtoMapper a_dtoMapper, IResourceLinker a_resourceLinker) { if (a_orderRepository == null) { throw new ArgumentNullException("a_orderRepository"); } if (a_dtoMapper == null) { throw new ArgumentNullException("a_dtoMapper"); } m_orderRepository = a_orderRepository; m_dtoMapper = a_dtoMapper; m_resourceLinker = a_resourceLinker; }
/// <summary> /// Initializes a new instance of the <see cref="T:System.Web.Mvc.Controller"/> class. /// </summary> public OrderController(IRepository <Order> a_orderRepository, IDtoMapper a_dtoMapper, IResourceLinker a_resourceLinker) { if (a_orderRepository == null) { throw new ArgumentNullException("a_orderRepository"); } if (a_dtoMapper == null) { throw new ArgumentNullException("a_dtoMapper"); } m_orderRepository = a_orderRepository; m_dtoMapper = a_dtoMapper; m_resourceLinker = a_resourceLinker; }
public AboutModule(ISettingsService <PlexRequestSettings> settingsService, ISettingsService <SystemSettings> systemService, ISecurityExtensions security, IStatusChecker statusChecker, IResourceLinker linker, ISqliteConfiguration config) : base("admin", settingsService, security) { Before += (ctx) => Security.AdminLoginRedirect(Permissions.Administrator, ctx); SettingsService = systemService; StatusChecker = statusChecker; Linker = linker; SqlConfig = config; Get["AboutPage", "/about", true] = async(x, ct) => await Index(); Post["/about", true] = async(x, ct) => await ReportIssue(); Get["/OAuth", true] = async(x, ct) => await OAuth(); Get["/authorize", true] = async(x, ct) => await Authorize(); }
public StatisticsModule(IProjectionStats stats, IResourceLinker resourceLinker) { Get("/", args => { var results = stats.OrderBy(p => p.ProjectorId).Select(p => new ProjectorSummary { ProjectorId = p.ProjectorId, LastCheckpoint = p.LastCheckpoint.Checkpoint, LastCheckpointUpdatedUtc = p.LastCheckpoint.TimestampUtc, Url = Context.Request.Url + $"/{p.ProjectorId}" }); return(results); }, null, "GetAll"); Get("/{id}", args => { string id = args.Id; return(new { ProjectorId = id, LastCheckpoint = stats.Get(id).LastCheckpoint.Checkpoint, LastCheckpointUpdatedUtc = stats.Get(id).LastCheckpoint.TimestampUtc, Properties = stats.Get(id).GetProperties().Select(p => new ProjectorProperty { Key = p.Key, Value = p.Value.Value, LastUpdatedUtc = p.Value.TimestampUtc }), EventsUrl = resourceLinker.BuildAbsoluteUri(Context, "GetEvents", new { args.id }).ToString() }); }, null, "GetSpecific"); Get("/{id}/events", args => { string id = args.Id; return(new ProjectorEventCollection { ProjectorId = id, Events = stats.Get(id).GetEvents().Select(@event => new ProjectorEvent { Body = @event.Body, TimestampUtc = @event.TimestampUtc }) }); }, null, "GetEvents"); Get("/{id}/eta/{targetCheckpoint}", args => { string id = args.Id; TimeSpan?eta = stats.GetTimeToReach(id, args.targetCheckpoint); return(new { Eta = eta }); }, null, "GetEta"); }
public TestModule(IResourceLinker linker) { TestModule.linker = linker; this.Get[""] = _ => 200; }
public GetFinesQueryHandler(IInMemoryFineRepository fineRepository, IResourceLinker resourceLinker) { _fineRepository = fineRepository; _resourceLinker = resourceLinker; }
public MainModule(IResourceLinker linker, GameSL gameSl, PlayerStatSL playerStatsSl, GhostCommSL ghostCommSl, StatisticsSL statisticsSl, GameDetailSL gameDetailSl, BanListSL banListSl) { Get["/"] = _ => { Context.EnableOutputCache(15); MainPageViewModel mpVm = new MainPageViewModel { CurrentBotTime = DateTime.Now, RecentGameDataList = gameSl.GetRecentGames(10) }; return(View["Views/MainPage.sshtml", mpVm]); }; Post["/Search"] = param => Response.AsRedirect($"/PlayerStats/USEast/{Request.Form.searchPlayerName}"); Get["/GameList"] = param => { Context.EnableOutputCache(10); return(View["Views/GameList.sshtml", ghostCommSl.GetGameList()]); }; Get["/About"] = Param => View["Views/About.sshtml"]; Get["/ServantStatistics"] = Param => { Context.EnableOutputCache(30); return(View["Views/ServantStatistics.sshtml", statisticsSl.GetServantStatistics()]); }; Get["/LeaderBoards"] = Param => { Context.EnableOutputCache(30); return(View["Views/LeaderBoards.sshtml"]); }; Get["/Downloads"] = Param => View["Views/Downloads.sshtml", ConfigHandler.MapName]; Get["/PlayerGameBuildDetail/{GameID}/{PlayerName}"] = param => { PlayerGameBuildViewModel vm = gameDetailSl.GetPlayerGameBuild(param.GameID, param.PlayerName); return(View["Views/PlayerGameBuildDetail.sshtml", vm]); }; Get["/Log"] = x => { string gameLog = gameSl.GetGameLog(Request.Query.gameId); return(View["Views/Log.sshtml", gameLog]); }; Get["/PlayerStats/{server}/{playerName}"] = param => { PlayerStatsPageViewModel summaryData = playerStatsSl.GetPlayerStatSummary(param.playerName, param.server, int.MaxValue); return(View["Views/PlayerStatsPage.sshtml", summaryData]); }; Get["/Maintenance"] = param => View["Views/Maintenance.sshtml"]; Get["/Login"] = param => View["Views/Login.sshtml", new LoginViewModel()]; Get["/BanList"] = param => { Context.EnableOutputCache(60); return(View["Views/BanList.sshtml", banListSl.GetBannedPlayers()]); }; }
public IndexService(NancyContext context, IResourceLinker linker) { this.context = context; this.linker = linker; }
public UserLoginModule(ISettingsService <AuthenticationSettings> auth, IPlexApi api, ISettingsService <PlexSettings> plexSettings, ISettingsService <PlexRequestSettings> pr, ISettingsService <LandingPageSettings> lp, IAnalytics a, IResourceLinker linker, IRepository <UserLogins> userLogins, IExternalUserRepository <PlexUsers> plexUsers, ICustomUserMapper custom, ISecurityExtensions security, ISettingsService <UserManagementSettings> userManagementSettings, IEmbyApi embyApi, ISettingsService <EmbySettings> emby, IExternalUserRepository <EmbyUsers> embyU, IUserHelper userHelper) : base("userlogin", pr, security) { AuthService = auth; LandingPageSettings = lp; Analytics = a; PlexApi = api; PlexSettings = plexSettings; Linker = linker; UserLogins = userLogins; PlexUserRepository = plexUsers; CustomUserMapper = custom; UserManagementSettings = userManagementSettings; EmbySettings = emby; EmbyApi = embyApi; EmbyUserRepository = embyU; UserHelper = userHelper; Post["/", true] = async(x, ct) => await LoginUser(); Get["/logout"] = x => Logout(); Get["UserLoginIndex", "/", true] = async(x, ct) => { if (Request.Query["landing"] == null) { var s = await LandingPageSettings.GetSettingsAsync(); if (s.Enabled) { if (s.BeforeLogin) // Before login { if (string.IsNullOrEmpty(Username)) { // They are not logged in return (Context.GetRedirect(Linker.BuildRelativeUri(Context, "LandingPageIndex").ToString())); } return(Context.GetRedirect(Linker.BuildRelativeUri(Context, "SearchIndex").ToString())); } // After login if (string.IsNullOrEmpty(Username)) { // Not logged in yet return(Context.GetRedirect(Linker.BuildRelativeUri(Context, "UserLoginIndex").ToString() + "?landing")); } // Send them to landing var landingUrl = Linker.BuildRelativeUri(Context, "LandingPageIndex").ToString(); return(Context.GetRedirect(landingUrl)); } } if (!string.IsNullOrEmpty(Username) || IsAdmin) { var url = Linker.BuildRelativeUri(Context, "SearchIndex").ToString(); return(Response.AsRedirect(url)); } var settings = await AuthService.GetSettingsAsync(); return(View["Username", settings]); }; Post["/login", true] = async(x, ct) => await UsernameLogin(); Post["/password", true] = async(x, ct) => await PasswordLogin(); }
public PayFinesCommandHandler(IInMemoryFineRepository fineRepository, IResourceLinker resourceLinker) { _fineRepository = fineRepository; _resourceLinker = resourceLinker; }
public AllBooksQueryHandler(IInMemoryBookRepository bookRepository, BookResourceMapper bookResourceMapper, IResourceLinker resourceLinker) { _bookRepository = bookRepository; _bookResourceMapper = bookResourceMapper; _resourceLinker = resourceLinker; }
public SecurityExtensions(IUserRepository userRepository, IResourceLinker linker, IPlexUserRepository plexUsers) { UserRepository = userRepository; Linker = linker; PlexUsers = plexUsers; }
public ClassifiedResourceHandler(IClassifiedService classifiedService, IResourceLinker linker) { this.classifiedService = classifiedService; this.linker = linker; }
public BookResourceMapper(IResourceLinker resourceLinker) { _resourceLinker = resourceLinker; }
public GetFinesQueryHandler(IInMemoryFineRepository fineRepository,IResourceLinker resourceLinker) { _fineRepository = fineRepository; _resourceLinker = resourceLinker; }
public RouteLinker(IResourceLinker linker, NancyContext context) { _linker = linker; _context = context; }
public AuthenticatedModule(IAppDbContext dbCtx, IResourceLinker linker) : base(dbCtx, linker) { this.RequiresAuthentication(); }
public NamedRouteService(NancyContext context, IResourceLinker linker) { this.context = context; this.linker = linker; }
public NancyRouteUrlBuilder(IResourceLinker resourceLinker, IProvideNancyContext nancyContextProvider) { _resourceLinker = resourceLinker; _nancyContextProvider = nancyContextProvider; }
public LoginModule(ISettingsService <PlexRequestSettings> pr, ICustomUserMapper m, IResourceLinker linker, IRepository <UserLogins> userLoginRepo, ISecurityExtensions security) : base(pr, security) { UserMapper = m; Get["LocalLogin", "/login"] = _ => { if (LoggedIn) { var url = linker.BuildRelativeUri(Context, "SearchIndex"); return(Response.AsRedirect(url.ToString())); } dynamic model = new ExpandoObject(); model.Redirect = Request.Query.redirect.Value ?? string.Empty; model.Errored = Request.Query.error.HasValue; var adminCreated = UserMapper.DoUsersExist(); model.AdminExists = adminCreated; return(View["Index", model]); }; Get["/logout"] = x => { if (Session[SessionKeys.UsernameKey] != null) { Session.Delete(SessionKeys.UsernameKey); } return(CustomModuleExtensions.LogoutAndRedirect(this, !string.IsNullOrEmpty(BaseUrl) ? $"~/{BaseUrl}/" : "~/")); }; Post["/login"] = x => { var username = (string)Request.Form.Username; var password = (string)Request.Form.Password; var dtOffset = (int)Request.Form.DateTimeOffset; var redirect = (string)Request.Form.Redirect; var userId = UserMapper.ValidateUser(username, password); if (userId == null) { return (Context.GetRedirect(!string.IsNullOrEmpty(BaseUrl) ? $"~/{BaseUrl}/login?error=true&username="******"~/login?error=true&username="******"userlogin")) { redirect = !string.IsNullOrEmpty(BaseUrl) ? $"/{BaseUrl}/search" : "/search"; } userLoginRepo.Insert(new UserLogins { LastLoggedIn = DateTime.UtcNow, Type = UserType.LocalUser, UserId = userId.ToString() }); return(CustomModuleExtensions.LoginAndRedirect(this, userId.Value, expiry, redirect)); }; Get["/register"] = x => { { dynamic model = new ExpandoObject(); model.Errored = Request.Query.error.HasValue; return(View["Register", model]); } }; Post["/register"] = x => { var username = (string)Request.Form.Username; var exists = UserMapper.DoUsersExist(); if (exists) { return (Context.GetRedirect(!string.IsNullOrEmpty(BaseUrl) ? $"~/{BaseUrl}/register?error=true" : "~/register?error=true")); } var userId = UserMapper.CreateUser(username, Request.Form.Password, EnumHelper <Permissions> .All(), 0); Session[SessionKeys.UsernameKey] = username; return(CustomModuleExtensions.LoginAndRedirect(this, (Guid)userId)); }; Get["/changepassword"] = _ => ChangePassword(); Post["/changepassword"] = _ => ChangePasswordPost(); }
public AllCheckedInBooksQueryHandler(IInMemoryBookRepository bookRepository, BookResourceMapper bookResourceMapper, IResourceLinker resourceLinker) { _bookRepository = bookRepository; _bookResourceMapper = bookResourceMapper; _resourceLinker = resourceLinker; }
public GetLibraryRootHandler(IResourceLinker linker) { _linker = linker; }