Created
October 12, 2014 14:48
-
-
Save ThomasLocke/6e62e38876b31815f69d to your computer and use it in GitHub Desktop.
shelfmiddleware.checktoken.dart
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
library shelfmiddleware.checktoken; | |
import 'headers.dart'; | |
import 'token.dart'; | |
import 'package:shelf/shelf.dart' as shelf; | |
final shelf.Middleware checkToken = shelf.createMiddleware(requestHandler: _passOrForbid); | |
shelf.Response _passOrForbid(shelf.Request request) { | |
final String token = Uri.splitQueryString(request.url.query)['token']; | |
if(isValid(token)) { | |
return null; | |
} | |
final String newToken = getToken(); | |
final String html = ''' | |
<h1>Grab a Token!</h1> | |
<p>Click <a href="/app?token=${newToken}">here</a> to venture forth to app/</p> | |
<p>Token: ${newToken} | |
'''; | |
return new shelf.Response.forbidden(html, headers: textHtmlHeader); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment