Created
November 6, 2012 19:56
-
-
Save jrsconfitto/4027087 to your computer and use it in GitHub Desktop.
Nancy Authentication issues i'm having
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
Imports Nancy | |
Imports Nancy.Authentication.Forms.ModuleExtensions | |
Imports Nancy.Extensions | |
Imports Nancy.Security | |
Imports System.Dynamic | |
''' <summary> | |
''' Handles all security related requests | |
''' </summary> | |
Public Class Login | |
Inherits NancyModule | |
''' <summary> | |
''' Handles all requests to the log in and log out routes | |
''' </summary> | |
''' <param name="settings">The application settings</param> | |
Public Sub New(settings As TVAppSettings) | |
[Get]("/login", Function() | |
Return settings.SecurityActive | |
End Function) = Function() | |
Dim model As Object = New ExpandoObject() | |
model.Error = Me.Request.Query.error.HasValue | |
#If DEBUG Then | |
model.Debug = True | |
#End If | |
Return View("login", model) | |
End Function | |
[Post]("/login", Function() | |
Return settings.SecurityActive | |
End Function) = Function() | |
Dim username As String = Me.Request.Form.Username | |
Dim password As String = Me.Request.Form.password | |
Dim theRequest = Me.Request | |
'Validate the user's credentials against the user database | |
Dim userGuid = TVUserDatabase.ValidateUser(username, password) | |
'If we haven't found a matching user | |
If userGuid = Nothing Then | |
Return Context.GetRedirect("~/login?error=true&username=" + username) | |
End If | |
If Me.Request.Form.RememberMe.HasValue Then | |
Return Me.LoginAndRedirect(userGuid, Date.Now.AddMonths(1)) | |
End If | |
Return Me.LoginAndRedirect(userGuid) | |
End Function | |
[Get]("/logout", Function() | |
Return settings.SecurityActive | |
End Function) = Function(params) | |
Return Me.LogoutAndRedirect("~/") | |
End Function | |
End Sub | |
End Class |
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
<!doctype html> | |
<!-- paulirish.com/2008/conditional-stylesheets-vs-css-hacks-answer-neither/ --> | |
<!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7" lang="en"> <![endif]--> | |
<!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8" lang="en"> <![endif]--> | |
<!--[if IE 8]> <html class="no-js lt-ie9" lang="en"> <![endif]--> | |
<!-- Consider adding a manifest.appcache: h5bp.com/d/Offline --> | |
<!--[if gt IE 8]><!--> <html class="no-js" lang="en"> <!--<![endif]--> | |
<head> | |
<title>Log in</title> | |
<link rel="stylesheet" href=@Path['~/Content/css/jquery.mobile.theme.css']> | |
<link rel="stylesheet" href=@Path['~/Content/css/jquery.mobile.structure.css']> | |
<link rel="stylesheet" href=@Path['~/Content/css/mobile.css']> | |
<!-- enabled/disabled js styles --> | |
<style> | |
.js #jsnotice { display: none; } | |
.no-js #jsnotice { display: block; } | |
.no-js #content { display: none; } | |
</style> | |
<!-- modernizer script for testing js presence --> | |
<script src=@Path['~/Content/js/lib/modernizr.min.js']></script> | |
<script src=@Path['~/Content/js/lib/jquery.min.js']></script> | |
<script src=@Path['~/Content/js/lib/jquery.mobile.js']></script> | |
<!-- Lastest builds of jQueryMobile can be found here--> | |
<!--<script src="http://code.jquery.com/mobile/latest/jquery.mobile.min.js"></script>--> | |
<!-- Apple and Chrome application shortcuts icons --> | |
<link rel="icon" href=@Path['~/Content/images/shortcut_icon.png'] sizes="32x32"> | |
<link rel="shortcut icon" href=@Path['~/Content/images/favicon.ico']> | |
<link rel="apple-touch-icon" href=@Path['~/Content/images/apple-touch-icon.png']> | |
<link rel="apple-touch-icon-precomposed" href=@Path['~/Content/images/apple-touch-icon-precomposed.png']> | |
<link rel="apple-touch-icon-precomposed" sizes="72x72" href=@Path['~/Content/images/apple-touch-icon-72x72-precomposed.png']> | |
<link rel="apple-touch-icon-precomposed" sizes="114x114" href=@Path['~/Content/images/apple-touch-icon-114x114-precomposed.png']> | |
<link rel="apple-touch-icon-precomposed" sizes="144x144" href=@Path['~/Content/images/apple-touch-icon-144x144-precomposed.png']> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0"> | |
</head> | |
<body> | |
<div id="log-in-page" data-role="page"> | |
<div data-role="header"> | |
<h1><img class="logo" src="/Content/images/bell-icon-center-glow.png" alt="TopView bell logo" width="12px"/>TopView</h1> | |
</div> | |
<!-- /header --> | |
<div data-role="content"> | |
<h2 align="center">Log in to TopView</h2> | |
@If.Error | |
<div class="ui-body ui-body-e"> | |
<p id="errorMessage">Invalid Username or Password</p> | |
</div> | |
@EndIf | |
<form action="login" method="POST" data-ajax="false"> | |
<label for="Username">Username:</label> | |
<input type="text" name="Username" autofocus> | |
<script> | |
if (!("autofocus" in document.createElement("input"))) { | |
document.getElementById("q").focus(); | |
} | |
</script> | |
<label for="Password">Password:</label> | |
<input name="Password" type="password"> | |
<input type="checkbox" name="RememberMe" id="RememberMe" class="custom"> | |
<label for="RememberMe">Remember Me</label> | |
<button type="submit" data-theme="a">Log in</button> | |
</form> | |
</div><!-- /content --> | |
</div><!-- /page --> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment