From fa00180e8658a44aff3e36698be9a882379d9f0d Mon Sep 17 00:00:00 2001 From: Max Wofford Date: Mon, 9 Jun 2025 11:20:43 -0400 Subject: [PATCH] Add github unlink + relink options --- app/controllers/sessions_controller.rb | 11 +++++++++++ app/views/users/edit.html.erb | 11 +++++++++++ config/routes.rb | 1 + 3 files changed, 23 insertions(+) diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb index b5db579..b056b34 100644 --- a/app/controllers/sessions_controller.rb +++ b/app/controllers/sessions_controller.rb @@ -82,6 +82,17 @@ class SessionsController < ApplicationController end end + def github_unlink + unless current_user + redirect_to root_path, alert: "Please sign in first" + return + end + + current_user.update!(github_access_token: nil) + Rails.logger.info "GitHub account unlinked for User ##{current_user.id}" + redirect_to my_settings_path, notice: "GitHub account unlinked successfully" + end + def email email = params[:email].downcase continue_param = params[:continue] diff --git a/app/views/users/edit.html.erb b/app/views/users/edit.html.erb index 5828a53..e153559 100644 --- a/app/views/users/edit.html.erb +++ b/app/views/users/edit.html.erb @@ -92,6 +92,17 @@

This is used to show your active projects on the leaderboard & current hacking activity on the dashboard.

<% if @user.github_uid.present? %>

✅ Your GitHub account is linked: <%= link_to "@#{@user.github_username}", "https://github.com/#{@user.github_username}", target: "_blank" %>

+ <% if @user.github_access_token.present? %> + <%= link_to "Relink GitHub Account", github_auth_path, data: { turbo: "false" }, role: "button" %> + <%= link_to "Unlink GitHub Account", github_unlink_path, + method: :delete, + data: { confirm: "Are you sure? This will remove access to your GitHub data." }, + role: "button", + class: "outline" %> + <% else %> +

⚠️ Your GitHub token has expired. Please relink your account.

+ <%= link_to "Relink GitHub Account", github_auth_path, data: { turbo: "false" }, role: "button" %> + <% end %> <% else %> <%= link_to "Link GitHub Account", github_auth_path, data: { turbo: "false" }, role: "button" %> <% end %> diff --git a/config/routes.rb b/config/routes.rb index e9ef94c..f93b8f0 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -65,6 +65,7 @@ Rails.application.routes.draw do get "/auth/slack/callback", to: "sessions#create" get "/auth/github", to: "sessions#github_new", as: :github_auth get "/auth/github/callback", to: "sessions#github_create" + delete "/auth/github/unlink", to: "sessions#github_unlink", as: :github_unlink post "/auth/email", to: "sessions#email", as: :email_auth post "/auth/email/add", to: "sessions#add_email", as: :add_email_auth get "/auth/token/:token", to: "sessions#token", as: :auth_token