mirror of
https://github.com/czhu12/canine.git
synced 2025-12-19 09:49:58 -06:00
34 lines
1.1 KiB
Ruby
34 lines
1.1 KiB
Ruby
class Local::PagesController < ApplicationController
|
|
EXPECTED_SCOPES = [ "repo", "write:packages" ]
|
|
if Rails.application.config.local_mode
|
|
skip_before_action :set_github_token_if_not_exists
|
|
end
|
|
|
|
def github_token
|
|
end
|
|
|
|
def update_github_token
|
|
client = Octokit::Client.new(access_token: params[:github_token])
|
|
provider = current_user.providers.find_or_initialize_by(provider: "github")
|
|
provider.update!(access_token: params[:github_token])
|
|
username = client.user[:login]
|
|
provider.auth = {
|
|
info: {
|
|
nickname: username
|
|
}
|
|
}.to_json
|
|
# Check per
|
|
provider.save!
|
|
if (client.scopes & EXPECTED_SCOPES).sort != EXPECTED_SCOPES.sort
|
|
flash[:error] = "Invalid scopes. Please check that your personal access token has the following scopes: #{EXPECTED_SCOPES.join(", ")}"
|
|
redirect_to github_token_path
|
|
else
|
|
flash[:notice] = "Your Github account (#{username}) has been connected"
|
|
redirect_to root_path
|
|
end
|
|
rescue Octokit::Unauthorized
|
|
flash[:error] = "Invalid personal access token"
|
|
redirect_to github_token_path
|
|
end
|
|
end
|