init email otp system

This commit is contained in:
techpixel 2025-04-27 23:28:38 -05:00
parent 53d1f97869
commit 7fd63afed8
16 changed files with 131 additions and 5 deletions

View file

@ -67,3 +67,6 @@ gem "tailwindcss-ruby", "~> 4.1"
gem "tailwindcss-rails", "~> 4.2"
gem "kramdown"
gem "airrecord"
gem "dotenv"

View file

@ -74,6 +74,10 @@ GEM
uri (>= 0.13.1)
addressable (2.8.7)
public_suffix (>= 2.0.2, < 7.0)
airrecord (1.0.12)
faraday (>= 1.0, < 3.0)
faraday-net_http_persistent
net-http-persistent
ast (2.4.3)
base64 (0.2.0)
bcrypt_pbkdf (1.1.1)
@ -107,6 +111,15 @@ GEM
erubi (1.13.1)
et-orbi (1.2.11)
tzinfo
faraday (2.13.1)
faraday-net_http (>= 2.0, < 3.5)
json
logger
faraday-net_http (3.4.0)
net-http (>= 0.5.0)
faraday-net_http_persistent (2.3.0)
faraday (~> 2.5)
net-http-persistent (>= 4.0.4, < 5)
ffi (1.17.2-aarch64-linux-gnu)
ffi (1.17.2-aarch64-linux-musl)
ffi (1.17.2-arm-linux-gnu)
@ -169,6 +182,10 @@ GEM
mini_mime (1.1.5)
minitest (5.25.5)
msgpack (1.8.0)
net-http (0.6.0)
uri
net-http-persistent (4.0.5)
connection_pool (~> 2.2)
net-imap (0.5.7)
date
net-protocol
@ -390,10 +407,12 @@ PLATFORMS
x86_64-linux-musl
DEPENDENCIES
airrecord
bootsnap
brakeman
capybara
debug
dotenv
image_processing (~> 1.2)
importmap-rails
jbuilder

View file

@ -1,4 +1,9 @@
class ApplicationController < ActionController::Base
# Only allow modern browsers supporting webp images, web push, badges, import maps, CSS nesting, and CSS :has.
allow_browser versions: :modern
private
def current_user
@current_user ||= User.find_by(id: session[:user_id]) if session[:user_id]
end
end

View file

@ -1,4 +1,5 @@
class LandingController < ApplicationController
def index
@authenticated = current_user.present?
end
end

View file

@ -0,0 +1,20 @@
class SessionsController < ApplicationController
@@authTable = Airrecord.table(ENV['AIRTABLE_API_KEY'], ENV['AIRTABLE_BASE_ID'], 'auth')
def create
@user = User.find_by(email_address: params[:email])
if @user && @user.authenticate(params[:password])
session[:user_id] = @user.id
else
@@authTable.create(
"Email" => params[:email],
"PIN" => "0000"
)
end
end
def destroy
session[:user_id] = nil
redirect_to root_path, notice: 'Logged out successfully'
end
end

View file

@ -0,0 +1,2 @@
module SessionsHelper
end

View file

@ -0,0 +1,2 @@
class Session < ApplicationRecord
end

2
site/app/models/user.rb Normal file
View file

@ -0,0 +1,2 @@
class User < ApplicationRecord
end

View file

@ -5,7 +5,17 @@
<div class="landing-text-container">
<h1 class="landing-text title">HIGHWAY</h1>
<p class="landing-text subtitle">Subtitle? Is this a Join Slack button? Also what font do we use?</p>
<% if @authenticated %>
<p class="landing-text subtitle">yooo!</p>
<% else %>
<div class="landing-input-container">
<%= form_with url: "/sessions", method: :post, local: true do |form| %>
<%= form.text_field :email, placeholder: "Enter your email", class: "landing-input" %>
<%= form.submit "Enter", class: "landing-button" %>
<% end %>
</div>
<% end %>
</div>
</div>

View file

@ -12,7 +12,10 @@ Rails.application.routes.draw do
# Defines the root path route ("/")
root "landing#index"
resources :posts
get "/info", to: "info#show"
# otp auth + session
resources :sessions
end

22
site/db/schema.rb generated
View file

@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema[8.0].define(version: 2025_04_27_015515) do
ActiveRecord::Schema[8.0].define(version: 2025_04_28_000939) do
create_table "action_text_rich_texts", force: :cascade do |t|
t.string "name", null: false
t.text "body"
@ -53,11 +53,27 @@ ActiveRecord::Schema[8.0].define(version: 2025_04_27_015515) do
t.string "name"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.text "description"
t.string "featured_image"
t.integer "hours"
end
create_table "sessions", force: :cascade do |t|
t.integer "user_id", null: false
t.string "ip_address"
t.string "user_agent"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["user_id"], name: "index_sessions_on_user_id"
end
create_table "users", force: :cascade do |t|
t.string "email_address", null: false
t.string "password_digest", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["email_address"], name: "index_users_on_email_address", unique: true
end
add_foreign_key "active_storage_attachments", "active_storage_blobs", column: "blob_id"
add_foreign_key "active_storage_variant_records", "active_storage_blobs", column: "blob_id"
add_foreign_key "sessions", "users"
end

View file

@ -0,0 +1,7 @@
require "test_helper"
class SessionsControllerTest < ActionDispatch::IntegrationTest
# test "the truth" do
# assert true
# end
end

11
site/test/fixtures/sessions.yml vendored Normal file
View file

@ -0,0 +1,11 @@
# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
# This model initially had no columns defined. If you add columns to the
# model remove the "{}" from the fixture names and add the columns immediately
# below each fixture, per the syntax in the comments below
#
one: {}
# column: value
#
two: {}
# column: value

11
site/test/fixtures/users.yml vendored Normal file
View file

@ -0,0 +1,11 @@
# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
# This model initially had no columns defined. If you add columns to the
# model remove the "{}" from the fixture names and add the columns immediately
# below each fixture, per the syntax in the comments below
#
one: {}
# column: value
#
two: {}
# column: value

View file

@ -0,0 +1,7 @@
require "test_helper"
class SessionTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end

View file

@ -0,0 +1,7 @@
require "test_helper"
class UserTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end