Skip to content
This repository has been archived by the owner on Jan 24, 2021. It is now read-only.

Commit

Permalink
Introduced new route declaration syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
thecodejunkie committed May 16, 2016
1 parent 2c07700 commit b490c6b
Show file tree
Hide file tree
Showing 104 changed files with 2,281 additions and 2,348 deletions.
4 changes: 2 additions & 2 deletions samples/Nancy.Demo.Authentication.Basic/MainModule.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
namespace Nancy.Demo.Authentication.Basic
{
public class MainModule : LegacyNancyModule
public class MainModule : NancyModule
{
public MainModule()
{
Get["/"] = _ => "<a href='/secure'>Enter</a>";
Get("/", args => "<a href='/secure'>Enter</a>");
}
}
}
4 changes: 2 additions & 2 deletions samples/Nancy.Demo.Authentication.Basic/SecureModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
{
using Nancy.Security;

public class SecureModule : LegacyNancyModule
public class SecureModule : NancyModule
{
public SecureModule() : base("/secure")
{
this.RequiresAuthentication();

Get["/"] = x => "Hello " + this.Context.CurrentUser.Identity.Name;
Get("/", args => "Hello " + this.Context.CurrentUser.Identity.Name);
}
}
}
26 changes: 13 additions & 13 deletions samples/Nancy.Demo.Authentication.Forms/MainModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,23 @@ namespace Nancy.Demo.Authentication.Forms
using Nancy.Authentication.Forms;
using Nancy.Extensions;

public class MainModule : LegacyNancyModule
public class MainModule : NancyModule
{
public MainModule()
{
Get["/"] = x => {
Get("/", args => {
return View["index"];
};
});

Get["/login"] = x =>
{
dynamic model = new ExpandoObject();
model.Errored = this.Request.Query.error.HasValue;
Get("/login", args =>
{
dynamic model = new ExpandoObject();
model.Errored = this.Request.Query.error.HasValue;
return View["login", model];
};
return View["login", model];
});

Post["/login"] = x => {
Post("/login", args => {
var userGuid = UserDatabase.ValidateUser((string)this.Request.Form.Username, (string)this.Request.Form.Password);
if (userGuid == null)
Expand All @@ -37,11 +37,11 @@ public MainModule()
}
return this.LoginAndRedirect(userGuid.Value, expiry);
};
});

Get["/logout"] = x => {
Get("/logout", args => {
return this.LogoutAndRedirect("~/");
};
});
}
}
}
8 changes: 4 additions & 4 deletions samples/Nancy.Demo.Authentication.Forms/PartlySecureModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@ namespace Nancy.Demo.Authentication.Forms
using Nancy.Demo.Authentication.Forms.Models;
using Nancy.Security;

public class PartlySecureModule : LegacyNancyModule
public class PartlySecureModule : NancyModule
{
public PartlySecureModule()
: base("/partlysecure")
{
Get["/"] = _ => "No auth needed! <a href='partlysecure/secured'>Enter the secure bit!</a>";
Get("/", args => "No auth needed! <a href='partlysecure/secured'>Enter the secure bit!</a>");

Get["/secured"] = x => {
Get("/secured", args => {
this.RequiresAuthentication();
var model = new UserModel(this.Context.CurrentUser.Identity.Name);
return View["secure.cshtml", model];
};
});
}
}
}
6 changes: 3 additions & 3 deletions samples/Nancy.Demo.Authentication.Forms/SecureModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ namespace Nancy.Demo.Authentication.Forms
using Nancy.Demo.Authentication.Forms.Models;
using Nancy.Security;

public class SecureModule : LegacyNancyModule
public class SecureModule : NancyModule
{
public SecureModule() : base("/secure")
{
this.RequiresAuthentication();

Get["/"] = x => {
Get("/", args => {
var model = new UserModel(this.Context.CurrentUser.Identity.Name);
return View["secure.cshtml", model];
};
});
}
}
}
31 changes: 16 additions & 15 deletions samples/Nancy.Demo.Authentication.Stateless/AuthModule.cs
Original file line number Diff line number Diff line change
@@ -1,27 +1,28 @@
namespace Nancy.Demo.Authentication.Stateless
{
public class AuthModule : LegacyNancyModule
public class AuthModule : NancyModule
{
public AuthModule() : base("/auth/")
{
//the Post["/login"] method is used mainly to fetch the api key for subsequent calls
Post["/"] = x =>
{
string apiKey = UserDatabase.ValidateUser((string) this.Request.Form.Username,
(string) this.Request.Form.Password);
Post("/", args =>
{
var apiKey = UserDatabase.ValidateUser(
(string) this.Request.Form.Username,
(string) this.Request.Form.Password);
return string.IsNullOrEmpty(apiKey)
? new Response {StatusCode = HttpStatusCode.Unauthorized}
: this.Response.AsJson(new {ApiKey = apiKey});
};
return string.IsNullOrEmpty(apiKey)
? new Response {StatusCode = HttpStatusCode.Unauthorized}
: this.Response.AsJson(new {ApiKey = apiKey});
});

//do something to destroy the api key, maybe?
Delete["/"] = x =>
{
var apiKey = (string) this.Request.Form.ApiKey;
UserDatabase.RemoveApiKey(apiKey);
return new Response {StatusCode = HttpStatusCode.OK};
};
Delete("/", args =>
{
var apiKey = (string) this.Request.Form.ApiKey;
UserDatabase.RemoveApiKey(apiKey);
return new Response {StatusCode = HttpStatusCode.OK};
});
}
}
}
6 changes: 3 additions & 3 deletions samples/Nancy.Demo.Authentication.Stateless/RootModule.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
namespace Nancy.Demo.Authentication.Stateless
{
public class RootModule : LegacyNancyModule
public class RootModule : NancyModule
{
public RootModule()
{
Get["/"] = _ => this.Response.AsText("This is a REST API. It is in another VS project to " +
Get("/", args => this.Response.AsText("This is a REST API. It is in another VS project to " +
"demonstrate how a common REST API might behave when " +
"accessing it from another website or application. To " +
"see how a website can access this API, run the " +
"Nancy.Demo.Authentication.Stateless.Website project " +
"(in the same Nancy solution).");
"(in the same Nancy solution)."));
}
}
}
36 changes: 18 additions & 18 deletions samples/Nancy.Demo.Authentication.Stateless/SecureModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,33 @@ namespace Nancy.Demo.Authentication.Stateless
using Nancy.Demo.Authentication.Stateless.Models;
using Nancy.Security;

public class SecureModule : LegacyNancyModule
public class SecureModule : NancyModule
{
//by this time, the api key should have already been pulled out of our querystring
//and, using the api key, an identity assigned to our NancyContext
public SecureModule()
{
this.RequiresAuthentication();

Get["secure"] = x =>
{
//Context.CurrentUser was set by StatelessAuthentication earlier in the pipeline
var identity = this.Context.CurrentUser;
Get("secure", args =>
{
//Context.CurrentUser was set by StatelessAuthentication earlier in the pipeline
var identity = this.Context.CurrentUser;
//return the secure information in a json response
var userModel = new UserModel(identity.Identity.Name);
return this.Response.AsJson(new
{
SecureContent = "here's some secure content that you can only see if you provide a correct apiKey",
User = userModel
});
};
//return the secure information in a json response
var userModel = new UserModel(identity.Identity.Name);
return this.Response.AsJson(new
{
SecureContent = "here's some secure content that you can only see if you provide a correct apiKey",
User = userModel
});
});

Post["secure/create_user"] = x =>
{
Tuple<string, string> user = UserDatabase.CreateUser(this.Context.Request.Form["username"], this.Context.Request.Form["password"]);
return this.Response.AsJson(new { username = user.Item1 });
};
Post("secure/create_user", args =>
{
Tuple<string, string> user = UserDatabase.CreateUser(this.Context.Request.Form["username"], this.Context.Request.Form["password"]);
return this.Response.AsJson(new { username = user.Item1 });
});
}
}
}
7 changes: 3 additions & 4 deletions samples/Nancy.Demo.Authentication/AnotherVerySecureModule.cs
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
namespace Nancy.Demo.Authentication
{
using System.Security.Claims;

using Nancy.Demo.Authentication.Models;
using Nancy.Security;

/// <summary>
/// A module that only people with SuperSecure clearance are allowed to access
/// </summary>
public class AnotherVerySecureModule : LegacyNancyModule
public class AnotherVerySecureModule : NancyModule
{
public AnotherVerySecureModule() : base("/superSecure")
{
this.RequiresClaims(c => c.Type == ClaimTypes.Role && c.Value == "SuperSecure");

Get["/"] = x =>
Get("/", args =>
{
var model = new UserModel(this.Context.CurrentUser.Identity.Name);
return View["superSecure.cshtml", model];
};
});
}
}
}
10 changes: 5 additions & 5 deletions samples/Nancy.Demo.Authentication/MainModule.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
namespace Nancy.Demo.Authentication
{
public class MainModule : LegacyNancyModule
public class MainModule : NancyModule
{
public MainModule()
{
Get["/"] = x => {
Get("/", args => {
return View["Index.cshtml"];
};
});

Get["/login"] = x => {
Get("/login", args => {
return View["Login.cshtml", this.Request.Query.returnUrl];
};
});
}
}
}
6 changes: 3 additions & 3 deletions samples/Nancy.Demo.Authentication/SecureModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ namespace Nancy.Demo.Authentication
using Nancy.Demo.Authentication.Models;
using Nancy.Security;

public class SecureModule : LegacyNancyModule
public class SecureModule : NancyModule
{
public SecureModule() : base("/secure")
{
this.RequiresAuthentication();

Get["/"] = x => {
Get("/", args => {
var model = new UserModel(this.Context.CurrentUser.Identity.Name);
return View["secure.cshtml", model];
};
});
}
}
}
6 changes: 3 additions & 3 deletions samples/Nancy.Demo.Bootstrapper.Aspnet/DependencyModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{
using Nancy.Demo.Bootstrapping.Aspnet.Models;

public class DependencyModule : LegacyNancyModule
public class DependencyModule : NancyModule
{
private readonly IApplicationDependency applicationDependency;
private readonly IRequestDependency requestDependency;
Expand All @@ -12,7 +12,7 @@ public DependencyModule(IApplicationDependency applicationDependency, IRequestDe
this.applicationDependency = applicationDependency;
this.requestDependency = requestDependency;

Get["/"] = x => {
Get("/", args => {
var model =
new RatPackWithDependencyText
{
Expand All @@ -22,7 +22,7 @@ public DependencyModule(IApplicationDependency applicationDependency, IRequestDe
};
return View["razor-dependency", model];
};
});
}
}
}
15 changes: 7 additions & 8 deletions samples/Nancy.Demo.Caching/MainModule.cs
Original file line number Diff line number Diff line change
@@ -1,26 +1,25 @@
namespace Nancy.Demo.Caching
{
using System;

using Nancy.Demo.Caching.CachingExtensions;

public class MainModule : LegacyNancyModule
public class MainModule : NancyModule
{
public MainModule()
{
Get["/"] = x => {
Get("/", args => {
return View["Index.cshtml", DateTime.Now.ToString()];
};
});

Get["/cached"] = x => {
Get("/cached", args => {
this.Context.EnableOutputCache(30);
return View["Payload.cshtml", DateTime.Now.ToString()];
};
});

Get["/uncached"] = x => {
Get("/uncached", args => {
this.Context.DisableOutputCache();
return View["Payload.cshtml", DateTime.Now.ToString()];
};
});
}
}
}
Loading

0 comments on commit b490c6b

Please sign in to comment.