http://amberframework.org - Questions? Post on StackOverflow and contribute to community knowledge! https://stackoverflow.com/questions/tagged/amber-framework - IRC? Share your chat messages across http://webchat.freenode.net/?channels=#amber
robacarp on master
Fix the correct documentation u… (compare)
robacarp on master
Updated the version number in A… (compare)
robacarp on master
Fixing a timestamp issue to sup… (compare)
HTTP::Server
DI isn't a super common thing in Ruby and by extension Crystal. However, there are some libs that support it. Probably not going to be easy to make Amber aware of/use it tho.
Can checkout https://github.com/veelenga/awesome-crystal#dependency-injection and https://forum.crystal-lang.org/t/dependency-injection-in-crystal/3477
.gets_to_end
IO::Memory
that you could attach to the log record
#pipes/authenticate_jwt.cr
class HTTP::Server::Context
property current_user : User?
end
class AuthenticateJWT < Amber::Pipe::Base
PUBLIC_PATHS = ["/", "/signin", "/session",
"/signup", "/registration", "/register"]
# add the regular expressions of paths that have public access
REGEX_PATHS = [
%r(/categories(/\d+)?$/),
%r(/products(/\d+)?$/),
%r(/comments(/\d+)?$/),
%r(/support/.*$/),
]
def call(context)
token = context.params["token"]? || context.request.headers["x-jwt-token"]?
if token
payload, header = JWT.decode(token, Amber.settings.secret_key_base, JWT::Algorithm::HS256)
user = User.find_by(email: payload["email"].to_s) unless payload["email"]?.nil?
elsif user_id = context.session["user_id"]?
user = User.find user_id
end
if user
context.current_user = user
if context.request.path.starts_with?("/admin") && ! user.is_admin?
context.flash[:warning] = "Access forbidden"
context.response.headers.add "Location", "/"
context.response.status_code = 302
else
call_next(context)
end
else
return call_next(context) if public_path?(context.request.path, context.session["user_id"]?)
context.flash[:warning] = "Please Sign In"
context.response.headers.add "Location", "/signin"
context.response.status_code = 302
end
end
private def public_path?(path, user_id)
return true if PUBLIC_PATHS.includes?(path)
# Different strategies can be used to determine if a path is public
# Example, if /admin/* paths are the only private paths
# return false if path.starts_with?("/admin")
#
# Example, if only a few private paths exist
# return false if ["/secret", "/super/secret", "/private"].includes?(path)
REGEX_PATHS.count { |r| r.match(path) } > 0
end
end
Hi everyone, I'm new to crystal and I want to use amber for my project, only, I'm having some troubles running the getting started guide (https://docs.amberframework.org/amber/guides/installation)
Building migrate
Step 1/7 : FROM amberframework/amber:1.0.0rc2
Service 'migrate' failed to build: manifest for amberframework/amber:1.0.0rc2 not found: manifest unknown: manifest unknown
I am using Crystal 1.3.2.