Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

74 auth via email link gem passwordless #75

Merged
merged 28 commits into from
Nov 9, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
bc15fcc
add passwordless
yshmarov Nov 8, 2022
d2e34ba
add gem letter-opener
yshmarov Nov 8, 2022
973942c
add passwordless views
yshmarov Nov 8, 2022
333b627
make sign in work
yshmarov Nov 8, 2022
0775293
users#show, basic views work
yshmarov Nov 8, 2022
bb9897a
Update new.html.erb
yshmarov Nov 8, 2022
6830e43
no more need to load insta user in session
yshmarov Nov 8, 2022
c9c0bac
insta user belongs to user
yshmarov Nov 8, 2022
a56e780
add passwordless initializer
yshmarov Nov 8, 2022
babb292
prepare for sending emails in production
yshmarov Nov 8, 2022
2ea5c44
require user for users controller, i18n
yshmarov Nov 8, 2022
37d2719
Update new.html.erb
yshmarov Nov 8, 2022
fcc20b6
associate insta user with user
yshmarov Nov 8, 2022
a6e15ff
display insta users of a user
yshmarov Nov 8, 2022
a88413a
no need for user partial in insta users index
yshmarov Nov 8, 2022
479b9d7
validation for import action
yshmarov Nov 8, 2022
074b6c0
move import action from ig_posts to ig_user
yshmarov Nov 8, 2022
0b4bcbb
Update show.html.erb
yshmarov Nov 8, 2022
edb31c7
Update show.html.erb
yshmarov Nov 8, 2022
0e9acd5
fix import
yshmarov Nov 9, 2022
52e1237
depreciate insta_user#show in favour of insta posts#index
yshmarov Nov 9, 2022
e9f56ef
Update new.html.erb
yshmarov Nov 9, 2022
3dafeba
after connect insta account redirect to user path
yshmarov Nov 9, 2022
32e2b91
Update users_controller.rb
yshmarov Nov 9, 2022
5e62487
annotate routes
yshmarov Nov 9, 2022
02573bb
update tests
yshmarov Nov 9, 2022
18c48da
update AWS SES creds for prod
yshmarov Nov 9, 2022
2fec4b0
Update user.rb
yshmarov Nov 9, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
add passwordless
  • Loading branch information
yshmarov committed Nov 8, 2022
commit bc15fcca2c5fe650e5b693ccfca2873e8ecba248
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,4 @@ gem 'data_migrate', '~> 8.1'

gem 'meta-tags', '~> 2.18'
gem 'honeybadger', '~> 4.0'
gem 'passwordless'
5 changes: 5 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ GEM
addressable (2.8.1)
public_suffix (>= 2.0.2, < 6.0)
ast (2.4.2)
bcrypt (3.1.18)
better_html (2.0.1)
actionview (>= 6.0)
activesupport (>= 6.0)
Expand Down Expand Up @@ -159,6 +160,9 @@ GEM
parallel (1.22.1)
parser (3.1.2.1)
ast (~> 2.4.1)
passwordless (0.11.0)
bcrypt (~> 3.1.11)
rails (>= 5.1.4)
pg (1.4.4)
public_suffix (5.0.0)
puma (5.6.5)
Expand Down Expand Up @@ -284,6 +288,7 @@ DEPENDENCIES
importmap-rails
jbuilder
meta-tags (~> 2.18)
passwordless
pg (~> 1.1)
puma (~> 5.0)
rails (~> 7.0.4)
Expand Down
17 changes: 13 additions & 4 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
class ApplicationController < ActionController::Base
include Passwordless::ControllerHelpers

helper_method :current_user

private

def current_user
@current_user ||= InstaUser.find(session[:insta_user_id]) if session[:insta_user_id]
rescue ActiveRecord::RecordNotFound
nil
@current_user ||= authenticate_by_session(User)
end

def require_user!
return if current_user

redirect_to root_path, flash: { alert: 'You are not logged in.' }
end
helper_method :current_user
end
6 changes: 0 additions & 6 deletions app/controllers/sessions_controller.rb

This file was deleted.

5 changes: 5 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class User < ApplicationRecord
validates :email, presence: true, uniqueness: { case_sensitive: false }

passwordless_with :email
end
8 changes: 4 additions & 4 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@
get 'terms', to: 'static_pages#terms'
get 'privacy', to: 'static_pages#privacy'

passwordless_for :users

get 'instagram/authorize', to: "instagram#authorize"
get 'instagram/callback', to: "instagram#callback"
get 'instagram/deauthorize', to: "instagram#deauthorize"
get 'instagram/delete', to: "instagram#delete"

delete "logout", to: "sessions#logout", as: :logout

get 'u/:id', to: 'insta_users#show', as: :insta_user
get 'u', to: 'insta_users#index', as: :insta_users
get 'u/:id', to: 'insta_users#show', as: :insta_user
get 'u/:id/p', to: 'insta_posts#index', as: :insta_user_posts
post 'u/:id/p/import', to: 'insta_posts#import', as: :import_insta_user_posts
get 'u/:id/p/:post_id', to: 'insta_posts#show', as: :insta_user_post
post 'u/:id/p/import', to: 'insta_posts#import', as: :import_insta_user_posts
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# frozen_string_literal: true

# This migration comes from passwordless (originally 20171104221735)
class CreatePasswordlessSessions < ActiveRecord::Migration[5.1]
def change
create_table(:passwordless_sessions) do |t|
t.belongs_to(
:authenticatable,
polymorphic: true,
index: {name: "authenticatable"}
)

t.datetime(:timeout_at, null: false)
t.datetime(:expires_at, null: false)
t.datetime(:claimed_at)
t.text(:user_agent, null: false)
t.string(:remote_addr, null: false)
t.string(:token, null: false)

t.timestamps
end
end
end
10 changes: 10 additions & 0 deletions db/migrate/20221108125104_create_users.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class CreateUsers < ActiveRecord::Migration[7.0]
def change
create_table :users do |t|
t.string :email

t.timestamps
end
add_index :users, :email, unique: true
end
end
26 changes: 22 additions & 4 deletions db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions test/fixtures/users.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html

one:
email: MyString

two:
email: MyString
7 changes: 7 additions & 0 deletions test/models/user_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require "test_helper"

class UserTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end