-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
345bda1
commit d57fc51
Showing
20 changed files
with
265 additions
and
3 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,19 @@ | ||
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 | ||
|
||
protect_from_forgery with: :exception | ||
helper_method :current_user | ||
helper_method :user_signed_in? | ||
|
||
def authenticate_user! | ||
redirect_to root_path, alert: "Requires authentication" unless user_signed_in? | ||
end | ||
|
||
def current_user | ||
@current_user ||= User.find_by(id: session[:user_id]) if session[:user_id] | ||
end | ||
|
||
def user_signed_in? | ||
!!current_user | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
class DashboardController < ApplicationController | ||
before_action :authenticate_user! | ||
|
||
def show | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
class SessionsController < ApplicationController | ||
def create | ||
@user = User.create_from_omniauth(request.env["omniauth.auth"]) | ||
|
||
if @user.persisted? | ||
session[:user_id] = @user.id | ||
redirect_path = request.env["omniauth.origin"] || dashboard_path | ||
redirect_to redirect_path, notice: "Logged in as #{@user.name}" | ||
else | ||
redirect_to root_url, alert: "Failure" | ||
end | ||
end | ||
|
||
def destroy | ||
session[:user_id] = nil | ||
redirect_to root_path, notice: "Logged out" | ||
end | ||
|
||
def failure | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
module DashboardHelper | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
class User < ApplicationRecord | ||
validates :provider, presence: true | ||
validates :uid, presence: true, uniqueness: true | ||
validates :email, format: { with: URI::MailTo::EMAIL_REGEXP }, presence: true, uniqueness: true | ||
|
||
def self.create_from_omniauth(omniauth_params) | ||
provider = omniauth_params.provider | ||
uid = omniauth_params.uid | ||
|
||
user = User.find_or_initialize_by(provider:, uid:) | ||
user.email = omniauth_params.info.email | ||
user.name = omniauth_params.info.name | ||
user.image = omniauth_params.info.image | ||
user.save | ||
user | ||
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<h1>Dashboard#index</h1> | ||
<p>Find me in app/views/dashboard/index.html.erb</p> |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<h1>Session#failure</h1> | ||
<p>Find me in app/views/session/failure.html.erb</p> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
Sg7Q2dwnWxjK2Mq2MmPPUYWUX2PKM+l4e4DuEcAqkY/y+2kQNbkx+1bzA+tnJLCEOCsGB4UnJZJZh/bKSx7KdddYrb86o91Nr3voqyiiAiaSvYTlzh8q6+Wijc/zyd9pT8gSWRi6RKPGQ1tnBID258eA7EQLRz3seHq6V8hk/lbVbfcq2IWpIRuGhzFlvz9PPQQpzxHL/jMmSPg=--swKpIerep+qrJ0Rh--1nh/oIprZkKKXuCFQrkPNQ== | ||
cqgblP/WZVUj7XLxx2aTg3eRDgL12lKyx4MD1KGp+0HiDOpcv9v4vYLQAMYntjDybrPbmyxnw2JUlB0Jzrih5djoiw0vNsCtPhkdtxTm6HjnuH/L2lu+M0JSFtg4CliACwXt+hSawlaZgWlQhDbXRI3cNnDIOFJ5Qgv5t5wtqto1LYWDdaaLSui1SP62bA6BplhyQM3OjJfJs2njKb3U3JOkJ4bokWbgA31IQSnFkgxUNVSO/WNA7nm7cjvIOEhjhCoVSpIPZTQTWF2b9aemgCXFapNwN5iIeNVlctROm7FO1VLWkPGu2r8xnGftbdCwOcCBihOX8HmZqHkKCwTw1a5hjM2TFdE=--escjTzyiTJRzv0Y3--cA8eAACAaxaVdCfmxm6aZQ== |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
Rails.application.config.middleware.use OmniAuth::Builder do | ||
github_oauth_credentials = Rails.application.credentials.github_oauth | ||
|
||
provider :github, | ||
github_oauth_credentials.client_id, | ||
github_oauth_credentials.client_secret, | ||
scope: "public_repo" | ||
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
class CreateUsers < ActiveRecord::Migration[8.0] | ||
def change | ||
create_table :users do |t| | ||
t.string :provider | ||
t.string :uid | ||
t.string :name | ||
t.string :email | ||
t.string :image | ||
|
||
t.timestamps | ||
end | ||
end | ||
end |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
require "test_helper" | ||
|
||
class DashboardControllerTest < ActionDispatch::IntegrationTest | ||
test "should get index" do | ||
get dashboard_index_url | ||
assert_response :success | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
require "test_helper" | ||
|
||
class SessionControllerTest < ActionDispatch::IntegrationTest | ||
test "should get create" do | ||
get session_create_url | ||
assert_response :success | ||
end | ||
|
||
test "should get destroy" do | ||
get session_destroy_url | ||
assert_response :success | ||
end | ||
|
||
test "should get failure" do | ||
get session_failure_url | ||
assert_response :success | ||
end | ||
end |
Oops, something went wrong.