forked from NancyFx/Nancy.Demo.Samples
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
617c9c6
commit 3433a94
Showing
2 changed files
with
30 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,17 @@ | ||
namespace Nancy.Demo.Samples.Modules | ||
{ | ||
using System; | ||
using Authentication.Forms; | ||
|
||
public class Home : NancyModule | ||
{ | ||
public Home(IUserDatabase userDatabase) | ||
public Home() | ||
{ | ||
Get["/"] = parameters => | ||
{ | ||
var user = Context.CurrentUser; | ||
{ | ||
return View["index"]; | ||
}; | ||
|
||
Get["/about"] = parameters => { | ||
return View["about"]; | ||
}; | ||
|
||
Get["/login"] = x => | ||
{ | ||
return View["login"]; | ||
}; | ||
|
||
Post["/login"] = parameters => { | ||
var userGuid = userDatabase.ValidateUser((string)this.Request.Form.Password); | ||
if (userGuid == null) | ||
{ | ||
//return this.Context.GetRedirect("~/login?error=true&username=" + (string)this.Request.Form.Username); | ||
return Response.AsRedirect("/"); | ||
} | ||
DateTime? expiry = null; | ||
//if (this.Request.Form.RememberMe.HasValue) | ||
//{ | ||
// expiry = DateTime.Now.AddDays(7); | ||
//} | ||
return this.LoginAndRedirect(userGuid.Value, expiry); | ||
}; | ||
|
||
Get["/logout"] = x => { | ||
return this.LogoutAndRedirect("~/"); | ||
}; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,36 @@ | ||
namespace Nancy.Demo.Samples.Modules | ||
{ | ||
using System; | ||
using Authentication.Forms; | ||
|
||
public class Login : NancyModule | ||
{ | ||
public Login() | ||
public Login(IUserDatabase userDatabase) | ||
{ | ||
|
||
Get["/login"] = x => | ||
{ | ||
return View["login"]; | ||
}; | ||
|
||
Post["/login"] = parameters => | ||
{ | ||
var userGuid = userDatabase.ValidateUser((string)this.Request.Form.Password); | ||
if (userGuid == null) | ||
{ | ||
return Response.AsRedirect("/"); | ||
} | ||
DateTime? expiry = null; | ||
return this.LoginAndRedirect(userGuid.Value, expiry); | ||
}; | ||
|
||
Get["/logout"] = x => | ||
{ | ||
return this.LogoutAndRedirect("~/"); | ||
}; | ||
} | ||
} | ||
} |