-
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
Showing
54 changed files
with
457 additions
and
337 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 |
---|---|---|
@@ -0,0 +1 @@ | ||
web: bundle exec rails server -p $PORT |
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,6 +1,8 @@ | ||
# frozen_string_literal: true | ||
|
||
# Add your own tasks in files placed in lib/tasks ending in .rake, | ||
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. | ||
|
||
require_relative "config/application" | ||
require_relative 'config/application' | ||
|
||
Rails.application.load_tasks |
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,24 +1,30 @@ | ||
# frozen_string_literal: true | ||
|
||
# ApplicationController serves as the base controller for all other controllers in the application. | ||
# It enforces user authentication for all actions unless overridden, and supports browser version | ||
# restrictions for modern features like webp images, web push, badges, etc. | ||
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 | ||
# Require users to be logged in | ||
before_action :require_login | ||
|
||
private | ||
def current_user | ||
# if @current _user is undefined or falsy, evaluate the RHS | ||
# Look up user by id if user id is in the session hash | ||
@current_user ||= User.find(session[:user_id]) if session[:user_id] | ||
end | ||
|
||
def logged_in? | ||
current_user | ||
end | ||
def current_user | ||
# if @current _user is undefined or falsy, evaluate the RHS | ||
# Look up user by id if user id is in the session hash | ||
@current_user ||= User.find(session[:user_id]) if session[:user_id] | ||
end | ||
|
||
def logged_in? | ||
current_user | ||
end | ||
|
||
def require_login | ||
# redirect to the welcome page unless user is logged in | ||
return if logged_in? | ||
|
||
def require_login | ||
# redirect to the welcome page unless user is logged in | ||
unless logged_in? | ||
redirect_to welcome_path, alert: 'You must be logged in to access this section.' | ||
end | ||
end | ||
redirect_to welcome_path, alert: 'You must be logged in to access this section.' | ||
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 |
---|---|---|
@@ -1,28 +1,37 @@ | ||
# frozen_string_literal: true | ||
|
||
# SessionsController handles user authentication with OmniAuth for Google OAuth2. | ||
class SessionsController < ApplicationController | ||
# Don't require login for login page | ||
skip_before_action :require_login, only: [:omniauth] | ||
|
||
# GET /logout | ||
def logout | ||
reset_session | ||
redirect_to welcome_path, notice: 'You are logged out' | ||
end | ||
|
||
# GET /auth/google_oauth2/callback | ||
def omniauth | ||
auth = request.env['omniauth.auth'] | ||
@user = User.find_or_create_by(uid: auth['uid'], provider: auth['provider']) do |u| | ||
u.email = auth['info']['email'] | ||
names = auth['info']['name'].split | ||
u.first_name = names[0] | ||
u.last_name = names[1..].join(' ') | ||
end | ||
|
||
@user = find_or_create_user_from_auth(auth_info) | ||
|
||
if @user.valid? | ||
session[:user_id] = @user.id | ||
redirect_to user_path(@user), notice: 'You are logged in' | ||
else | ||
redirect_to welcome_path, alert: 'Login failed' | ||
end | ||
end | ||
|
||
private | ||
|
||
def auth_info | ||
request.env['omniauth.auth'] | ||
end | ||
|
||
def find_or_create_user_from_auth(auth) | ||
User.find_or_create_by(uid: auth['uid'], provider: auth['provider']) do |user| | ||
user.email = auth['info']['email'] | ||
names = auth['info']['name'].split | ||
user.first_name = names[0] | ||
user.last_name = names[1..].join(' ') | ||
end | ||
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
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,2 +1,5 @@ | ||
# frozen_string_literal: true | ||
|
||
# ApplicationHelper is used to store helper methods that can be used across views. | ||
module ApplicationHelper | ||
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 |
---|---|---|
@@ -1,3 +1,6 @@ | ||
# frozen_string_literal: true | ||
|
||
# ApplicationRecord serves as the base class for all models in the application. | ||
class ApplicationRecord < ActiveRecord::Base | ||
primary_abstract_class | ||
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 |
---|---|---|
@@ -1,3 +1,6 @@ | ||
# frozen_string_literal: true | ||
|
||
# The User model represents users in the application. | ||
class User < ApplicationRecord | ||
validates :email, presence: true | ||
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 |
---|---|---|
@@ -1,7 +1,9 @@ | ||
#!/usr/bin/env ruby | ||
require "rubygems" | ||
require "bundler/setup" | ||
# frozen_string_literal: true | ||
|
||
ARGV.unshift("--ensure-latest") | ||
require 'rubygems' | ||
require 'bundler/setup' | ||
|
||
load Gem.bin_path("brakeman", "brakeman") | ||
ARGV.unshift('--ensure-latest') | ||
|
||
load Gem.bin_path('brakeman', 'brakeman') |
Oops, something went wrong.