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
# Embed this as a <input type="hidden"> into *every form* | |
def csrf_token(session_id, key = ENV_CSRF_TOKEN_SECRET) | |
d = OpenSSL::Digest.new("SHA256") | |
d.update session_id.to_slice | |
payload = String.build do |s| | |
s << d.hexdigest | |
s << " " | |
s << Time.utc.to_unix | |
end | |
"#{OpenSSL::HMAC.hexdigest(CSRF_TOKEN_HMAC_ALGO, key, payload)} #{payload}" |
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
package; | |
import openfl.text.TextField; | |
import openfl.events.KeyboardEvent; | |
import openfl.display.Sprite; | |
class Scene extends Sprite { | |
public function new() | |
{ | |
super(); |
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
module Cove::Views | |
def self.welcome (store) | |
html = <<-HTML | |
<h1>Hello #{store["data"]["username"]}</h1> | |
<p> Your UserId is: #{store["data"]["userid"]}</p> | |
HTML | |
end | |
end |
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
module Cove | |
class Auth | |
def self.register(ctx) | |
params = Cove::Parse.form_params(ctx.request.body) | |
username = params.fetch("username") | |
password = params.fetch("password") | |
store = { | |
"status" => "success", | |
"message" => "User was success fully added", |
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
module Cove::Views | |
def self.register | |
html = <<-HTML | |
<article id="register_page"> | |
<form class="ui form" id="register_form" action="/register" method="post"> | |
<div class="field"> | |
<label>Username</label> | |
<input type="text" name="username" id="username" placeholder="Username" /> | |
</div> | |
<div class="field"> |
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
def self.run(method, url, ctx) | |
url = clean(url) | |
path = {url, method} | |
case path | |
when {"/hola/", "GET"} | |
ctx.response.print "Yo buddy!" | |
when {"/about/", "GET"} | |
ctx.response.content_type = "text/html; charset=utf-8" |
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
# A handler that logs the request method, resource, status code, and | |
# the time used to execute the next handler, to the given `IO`. | |
class Cove::Logger < HTTP::LogHandler | |
# Initializes this handler to log to the given `IO`. | |
def initialize(@io : IO = STDOUT) | |
end | |
def call(context) | |
elapsed = Time.measure { call_next(context) } |
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
module Cove::Views | |
def self.js | |
html = <<-HTML | |
<script> | |
console.log("Hallo from the Cove") | |
</script> | |
HTML | |
end | |
end |
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
module Cove::Views | |
def self.css | |
html = <<-HTML | |
<style type="text/css"> | |
.main.container { | |
margin-top: 6em; | |
} | |
</style> | |
HTML | |
end |
NewerOlder