Skip to content
This repository has been archived by the owner on Sep 9, 2019. It is now read-only.

this address issue #170 #209

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 2 additions & 0 deletions .sample.env
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@ EXECJS_RUNTIME=Node
GITHUB_CLIENT_ID=consumer_public_key
GITHUB_CLIENT_SECRET=consumer_secret_key
GITHUB_TEAM_ID=yourteamid
SKIP_TEAM_CHECK=false
[email protected]
30 changes: 25 additions & 5 deletions app/controllers/auth_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,36 @@ class AuthController < ApplicationController
skip_before_action :authenticate_user!, only: [:oauth_callback]

def oauth_callback
if team_member?
user = User.find_or_create_by(email: auth_email)
sign_in(user)
flash[:success] = "You successfully signed in"
redirect_to root_path
if ok_to_bypass_authentication?
create_user(developer_email)
else
if team_member?
create_user(auth_email)
end
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a blocker for this pull request, but there should probably be an else here.

end
end

private

def create_user(email)
user = User.find_or_create_by(email: email)
sign_in(user)
flash[:success] = "You successfully signed in"
redirect_to root_path
end

def ok_to_bypass_authentication?
Rails.env == "development" && skip_team_check?
end

def skip_team_check?
ENV["SKIP_TEAM_CHECK"].downcase == "true"
end

def developer_email
ENV["DEVELOPER_EMAIL"]
end

def team_member?
auth_hash.credentials.team_member?
end
Expand Down