diff options
author | Jeroen Walter <jeroen@enormkansloos.nl> | 2013-03-20 21:31:02 +0100 |
---|---|---|
committer | Jeroen Walter <jeroen@enormkansloos.nl> | 2013-03-20 21:31:02 +0100 |
commit | 8ee93847b1e82d39575bbc86b0f74f1dae8f5c94 (patch) | |
tree | 58fa6231dddcc9e6823c5a22dda7772f0632aabe /ComicRackWebViewer/Modules/BCRModule.cs | |
parent | 1b864d5dfd3806a193302539dba836db56bb86ad (diff) | |
download | ComicRackWeb-8ee93847b1e82d39575bbc86b0f74f1dae8f5c94.zip ComicRackWeb-8ee93847b1e82d39575bbc86b0f74f1dae8f5c94.tar.gz ComicRackWeb-8ee93847b1e82d39575bbc86b0f74f1dae8f5c94.tar.bz2 |
- support for multiple users
- removed original webviewer
- new settings interface
Diffstat (limited to 'ComicRackWebViewer/Modules/BCRModule.cs')
-rw-r--r-- | ComicRackWebViewer/Modules/BCRModule.cs | 99 |
1 files changed, 93 insertions, 6 deletions
diff --git a/ComicRackWebViewer/Modules/BCRModule.cs b/ComicRackWebViewer/Modules/BCRModule.cs index 28fd423..c125620 100644 --- a/ComicRackWebViewer/Modules/BCRModule.cs +++ b/ComicRackWebViewer/Modules/BCRModule.cs @@ -16,13 +16,13 @@ using cYo.Projects.ComicRack.Viewer; using Nancy; using Nancy.ModelBinding; using Nancy.Responses; +using Nancy.Security; using ComicRackWebViewer; using System.Text.RegularExpressions; using Linq2Rest.Parser; - namespace BCR { public class BCRModule : NancyModule @@ -30,11 +30,28 @@ namespace BCR public BCRModule() : base("/BCR") { - Get["/"] = x => { return Response.AsRedirect("/tablet/index.html", RedirectResponse.RedirectType.Permanent); }; + // The user must be authenticated in order to use the BCR API. + this.RequiresAuthentication(); + + Get["/"] = x => { return Response.AsRedirect("/", RedirectResponse.RedirectType.Permanent); }; + + /* + Get["/User"] = x => { + //Context.CurrentUser was set by StatelessAuthentication earlier in the pipeline + var user = (BCRUser)this.Context.CurrentUser; + + return Response.AsRedirect("/", RedirectResponse.RedirectType.Permanent); + }; + */ /////////////////////////////////////////////////////////////////////////////////////////////// // Retrieve a list of all (smart)lists. Get["/Lists"] = x => { + + // TODO: get home list for user. + //var user = (BCRUser)this.Context.CurrentUser; + + try { int depth = Request.Query.depth.HasValue ? int.Parse(Request.Query.depth) : -1; @@ -144,6 +161,7 @@ namespace BCR /////////////////////////////////////////////////////////////////////////////////////////////// // Retrieve the specified page as a jpg file with the specified dimensions. Get["/Comics/{id}/Pages/{page}"] = x => { + try { int width = Request.Query.width.HasValue ? int.Parse(Request.Query.width) : -1; @@ -258,13 +276,13 @@ namespace BCR } }; - + /* /////////////////////////////////////////////////////////////////////////////////////////////// // Get the BCR settings. Get["/Settings"] = x => { try { - return Response.AsJson(BCRSettingsStore.Instance, HttpStatusCode.OK); + return Response.AsJson(ImageCache.Instance, HttpStatusCode.OK); } catch(Exception e) { @@ -281,7 +299,7 @@ namespace BCR try { BCRSettings settings = this.Bind<BCRSettings>(); - BCRSettingsStore.Instance.UpdateFrom(settings); + ImageCache.Instance.UpdateFrom(settings); return HttpStatusCode.OK; } catch(Exception e) @@ -289,7 +307,37 @@ namespace BCR return Response.AsError(HttpStatusCode.InternalServerError, e.ToString(), Request); } }; - + */ + /////////////////////////////////////////////////////////////////////////////////////////////// + // Get the BCR settings. + Get["/Settings"] = x => { + try + { + var user = (BCRUser)this.Context.CurrentUser; + return Response.AsJson(user.GetSettings(), HttpStatusCode.OK); + } + catch(Exception e) + { + return Response.AsError(HttpStatusCode.InternalServerError, e.ToString(), Request); + } + }; + + + /////////////////////////////////////////////////////////////////////////////////////////////// + // Update the BCR settings. + Put["/Settings"] = x => { + try + { + var user = (BCRUser)this.Context.CurrentUser; + user.UpdateSettings(this.Bind<UserSettings>()); + + return HttpStatusCode.OK; + } + catch(Exception e) + { + return Response.AsError(HttpStatusCode.InternalServerError, e.ToString(), Request); + } + }; /////////////////////////////////////////////////////////////////////////////////////////////// // Get a list of series @@ -437,6 +485,45 @@ namespace BCR return Response.AsError(HttpStatusCode.InternalServerError, e.ToString(), Request); } }; + + /* + /////////////////////////////////////////////////////////////////////////////////////////////// + // User management + Get["/Login/{id}"] = x => { + try + { + + } + catch(Exception e) + { + return Response.AsError(HttpStatusCode.InternalServerError, e.ToString(), Request); + } + }; + + // Get list of all users + Get["/User"] = x => { + try + { + + } + catch(Exception e) + { + return Response.AsError(HttpStatusCode.InternalServerError, e.ToString(), Request); + } + }; + + // + Get["/User/{id}"] = x => { + try + { + + } + catch(Exception e) + { + return Response.AsError(HttpStatusCode.InternalServerError, e.ToString(), Request); + } + }; + */ } } |