# frozen_string_literal: true require "roda" require "sequel/core" require "securerandom" require "net/http" require "bcrypt" require "digest/sha1" if (url = ENV.delete("DATABASE_URL")) DB = Sequel.connect(url) else DB = Sequel.sqlite DB.create_table(:accounts) do primary_key :id, type: :Bignum String :email, null: false index :email, unique: true String :ph, null: false end end if ENV.delete("RODAUTH_DEBUG") require "logger" DB.loggers << Logger.new($stdout) end DB.extension :date_arithmetic DB.freeze hash = ::BCrypt::Password.create("password", cost: BCrypt::Engine::MIN_COST) DB[:accounts].insert_conflict(target: :email).insert(email: "foo@bar.com", ph: hash) DB[:accounts].insert_conflict(target: :email).insert(email: "foo2@bar.com", ph: hash) DB[:accounts].insert_conflict(target: :email).insert(email: "foo3@bar.com", ph: hash) class Goggles < Roda plugin :render, views: File.expand_path("assets/html", __dir__) plugin :flash plugin :common_logger plugin :assets, css: "layout.scss", path: File.expand_path("assets", __dir__) secret = ENV.delete("RODAUTH_SESSION_SECRET") || SecureRandom.random_bytes(64) plugin :sessions, secret: secret, key: "goggles.session" plugin :rodauth, json: true do db DB enable :login, :logout, :create_account, :select_account login_return_to_requested_location? true account_password_hash_column :ph title_instance_variable :@page_title login_return_to_requested_location? true end plugin :not_found do @page_title = "Not Found" "Not Found" end route do |r| r.assets r.rodauth r.root do view inline: <<~HTML <% if rodauth.logged_in? %>
You are now logged in to Goggles. Now I can monitor you.
<% else %>You are not logged in Goggles. Please, log in, so I can track you.
<% end %>